Security rules

NGB026: Untrusted HTTP request destination

Traces attacker-controllable values (URL / route parameters, postMessage data, window.name, document.referrer) into the URL of outgoing requests — HttpClient methods, fetch(), XMLHttpRequest.open(), navigator.sendBeacon(), EventSource, WebSocket.

Property Value
Rule ID NGB026
Category Navigation & authentication
Default severity high
CWE CWE-918, CWE-22, CWE-352
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

Traces attacker-controllable values (URL / route parameters, postMessage data, window.name, document.referrer) into the URL of outgoing requests — HttpClient methods, fetch(), XMLHttpRequest.open(), navigator.sendBeacon(), EventSource, WebSocket. When the value can choose the destination origin, requests (and any credentials or sensitive body attached to them) go to the attacker. When the origin is fixed but the value forms a path segment, the attacker can redirect the victim's authenticated request to another endpoint of your API (client-side path traversal / request forgery).

Why it matters

Angular decodes route parameters, so /items/..%2F..%2Fadmin%2Fusers%2F42 turns this.http.delete(/api/items/${id}) into DELETE /api/admin/users/42 sent with the victim's cookies or token. When the whole URL comes from a query parameter, an Authorization header added to the request, a credentialed body or the response handling (rendering, redirects) is under attacker control.

Detection behavior and supported patterns

  • Requests: HttpClient.get/post/put/patch/delete/head/options/request/jsonp, fetch(url, init), xhr.open(method, url), navigator.sendBeacon(url), new EventSource(url), new WebSocket(url), RxJS webSocket(url)
  • URL decomposition: template literals, + concatenation and const URL variables; values after ? or # are not destinations and are ignored
  • Origin control (high severity with an auth header, credentials or a sensitive body; otherwise medium): the attacker value is first, or follows only a scheme / /
  • Path control: a fixed https://host/, /api/…, relative api/… or configured base (environment.apiUrl) precedes the value — medium severity for state-changing methods (POST/PUT/PATCH/DELETE), low for reads
  • Recognized validation: encodeURIComponent() and numeric conversion on the value, host allowlists / same-origin checks (as NGB011) for origin control, anchored regex tests (/^[\w-]+$/.test(id)) for path segments

Example

TypeScript
const id = this.route.snapshot.paramMap.get('id');this.http.delete(`/api/projects/${id}`).subscribe();

Safer alternative

TypeScript
const id = this.route.snapshot.paramMap.get('id') ?? '';if (!/^[0-9a-f-]{36}$/.test(id)) return;this.http.delete(`/api/projects/${encodeURIComponent(id)}`).subscribe();

Remediation

Validate identifiers before using them in a request path (/^[A-Za-z0-9_-]+$/, numeric conversion) and encode them with encodeURIComponent(). Never take a complete request URL or host from URL parameters or messages; map allowed values to fixed endpoints instead.

False-positive considerations

  • Read-only lookups by route ID (GET /api/items/${id}) are low severity and low confidence; they are hidden by the default minConfidence: medium.

Known limitations

  • encodeURIComponent('..') is still ..; a single path level can be traversed after encoding. This is accepted as mitigation (one segment can no longer inject /).
  • Values from HTTP responses, Web Storage and form inputs are not treated as attacker-controlled here (users control their own inputs; response-driven URLs are usually API links).
  • Whether the server would accept the forged request (method, CSRF token, authorization) is not visible.

References

Run it

Shell
ngbastion explain NGB026