Security rules

NGB039: JSONP request

Reports HttpClient.jsonp() requests.

Property Value
Rule ID NGB039
Category Angular security & XSS
Default severity medium
CWE CWE-829, CWE-95
Built-in presets recommended: error, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Reports HttpClient.jsonp() requests. JSONP loads the response as a <script>, so the remote server executes code in your application's origin. Severity: high when the URL is traced to an attacker-controllable source, medium for fixed third-party URLs, low (low confidence) for same-origin relative URLs.

Why it matters

With JSONP there is no data boundary: whatever the endpoint returns runs with full access to your page, tokens and DOM. A compromised or malicious JSONP provider, a callback-parameter injection on the provider, or an attacker-chosen URL is immediate script execution (XSS) that CSP connect-src does not restrict. CORS made JSONP unnecessary.

Detection behavior and supported patterns

  • http.jsonp(url, callbackParam) on HttpClient from @angular/common/http
  • URL traced to ActivatedRoute / location values, postMessage data, window.name, referrer → high
  • Constant https://other.host/… → medium; relative same-origin URL → low

Example

TypeScript
this.http.jsonp('https://api.weather.example/v1/today', 'callback').subscribe(...)

Safer alternative

TypeScript
this.http.get('/api/weather/today').subscribe(...) // backend proxies the provider

Remediation

Replace JSONP with HttpClient.get() against an endpoint that sends CORS headers, then remove withJsonpSupport() / HttpClientJsonpModule. If a provider only offers JSONP, proxy it through your backend.

False-positive considerations

  • Legacy first-party JSONP endpoints on the same origin are reported with low confidence.

Known limitations

  • Hand-written JSONP (creating <script src="…?callback=…">) is covered by NGB005, not this rule.
  • withJsonpSupport() / HttpClientJsonpModule registrations without visible jsonp() calls are not reported.

References

Run it

Shell
ngbastion explain NGB039