Insecure JSONP Endpoint

An endpoint returns data as JSONP, a script any website can load, so other sites may read data meant for the logged-in user or inject script through the callback name.

SeverityLow
CVSS 3.13.1 CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:N/A:N Open in the calculator
CVSS 4.02.3 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-346: Origin Validation Error
OWASP Top 10A07:2025 Authentication Failures
CategoryInformation Disclosure

Description

JSONP (JSON with padding) is a legacy technique for sharing data across origins that predates CORS. The endpoint wraps its JSON response in a call to a function named by a request parameter, commonly callback or jsonp, and returns it as JavaScript. Because browsers let a page load and run a script from any origin, any website can include the endpoint with a <script> element and receive the data in its own function, and the same-origin policy, which normally stops one site reading another's responses, does not apply.

Two problems follow. Where the endpoint returns data specific to the user and identifies them by cookie, a site the user visits may be able to read that data, a form of cross-site script inclusion: an attacker who lures a logged-in user to their website can read whatever the endpoint returns for that user, such as personal details, account data or anti-CSRF tokens, without the user noticing. Current browsers limit this, and with their defaults such theft of authenticated data is often blocked: Chromium-based browsers do not send cookies that lack a SameSite attribute, or are marked Lax or Strict, with such requests, and other browsers block or partition third-party cookies. The exposure therefore mainly arises where session cookies are marked SameSite=None or the endpoint trusts network location rather than a login, and its impact depends on the sensitivity of the returned data.

Separately, where the callback name is not restricted, an attacker controls the start of a script served from the application's origin. This can be used to bypass a Content Security Policy that trusts that origin, defeating a policy that would otherwise contain an injection flaw elsewhere, and can lead to cross-site scripting if the response is served as HTML.

The issue is identified by adding a callback parameter to JSON endpoints, observing whether the response is wrapped, and checking which characters the callback accepts.

Remediation

  • Retire JSONP. Serve data as JSON with the application/json content type and, where another origin genuinely needs it, allow that origin explicitly with CORS rather than allowing every site.
  • Until the endpoint can be removed, do not return user-specific or sensitive data through it, and disable the callback parameter on every endpoint that does not need it, including framework defaults.
  • Restrict the callback name to a short allowlist of known function names, or at minimum to letters, digits, underscores and dots, and reject anything else.
  • Serve JSONP responses with a JavaScript content type and X-Content-Type-Options: nosniff, never as HTML.
  • Reject cross-site requests for authenticated data by checking the Sec-Fetch-Site request header (a resource isolation policy), and set session cookies to SameSite=Lax or Strict unless cross-site use is required.

Confirm the fix by requesting the endpoint with a callback parameter and checking that a JSON response, not a script, is returned.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Web Applications Findings

Every Web Applications finding