Skip to main content
MediumClient-sideOWASP A01:2021CWE-352

How to fix: JSONP Callback Pattern Detected

A JSONP endpoint was detected that wraps JSON data in a function call controlled by a URL parameter (callback=myFunction). JSONP is an obsolete cross-origin technique that creates security vulnerabilities.

Why it matters

JSONP endpoints bypass the Same-Origin Policy entirely. Any website can load the endpoint as a script tag and exfiltrate the response data. If the endpoint returns user-specific data, it's a cross-site data theft vulnerability.

JSONP was invented before CORS existed as a cross-origin workaround. It works by wrapping JSON in a function call: callback({ 'data': 'value' }). Since there is no origin validation, any page can call your endpoint and access the data.

How to fix it

  1. 1Remove JSONP endpoints and replace with proper CORS configuration.
  2. 2If cross-origin access is needed, use CORS with explicit origin allowlist.
  3. 3Never expose user-specific data over JSONP.
  4. 4If JSONP must remain for legacy clients: only expose public, non-sensitive data.

Code examples

Replace JSONP with CORS

TypeScript
// Bad: JSONP endpoint (any site can read this)
export function GET(req: Request) {
  const callback = new URL(req.url).searchParams.get('callback');
  return new Response(`${callback}(${JSON.stringify(data)})`);
}

// Good: CORS with allowlist
export function GET(req: Request) {
  const origin = req.headers.get('origin');
  const allowed = ALLOWED_ORIGINS.has(origin ?? '') ? origin : '';
  return Response.json(data, {
    headers: { 'Access-Control-Allow-Origin': allowed ?? '' },
  });
}

References

Detected automatically by VulnRadar. The check id is jsonp-callback-endpoint, stable across every scan so you can filter or diff on it.

See every client-side check

Questions

How severe is JSONP Callback Pattern Detected?
VulnRadar rates this medium severity in the client-side category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id jsonp-callback-endpoint, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does JSONP Callback Pattern Detected map to?
It maps to CWE-352. In the OWASP Top 10 it falls under A01:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for jsonp callback pattern detected

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: JSONP Callback Pattern Detected | VulnRadar