Security rules
NGB060: Untrusted OAuth redirect URI
Traces untrusted data (URL query / fragment, postMessage data, window.name, referrer, Web Storage) into the OAuth / OIDC redirect URI of an authorization or logout request: redirect_uri / redirectUri / post_logout_redirect_uri / silentRefreshRedirectUri properties (client configuration and request parameters), params.set('redirect_uri', v), and redirect_uri= inside request URLs.
| Property | Value |
|---|---|
| Rule ID | NGB060 |
| Category | Navigation & authentication |
| Default severity | high |
| CWE | CWE-601, CWE-522 |
| 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 untrusted data (URL query / fragment, postMessage data, window.name, referrer, Web Storage) into the OAuth / OIDC redirect URI of an authorization or logout request: redirect_uri / redirectUri / post_logout_redirect_uri / silentRefreshRedirectUri properties (client configuration and request parameters), params.set('redirect_uri', v), and redirect_uri= inside request URLs. Values pinned by a constant origin or path prefix, the application's own current URL (location.href), and values guarded by a host allowlist are not reported.
Why it matters
The redirect URI is where the identity provider delivers the authorization code or tokens. If a link can choose it (/login?returnTo=https://evil.example/cb), the code is sent to the attacker. Identity providers that compare redirect URIs exactly stop this; providers configured with wildcards, prefix matching or many registered URIs (including an open redirect on your own domain) do not.
Detection behavior and supported patterns
- Object properties
redirect_uri,redirectUri,redirectUrl,post_logout_redirect_uri,postLogoutRedirectUri,silentRefreshRedirectUriwith an untrusted value params.set|append('redirect_uri', v)onURLSearchParams/HttpParams`…/authorize?…&redirect_uri=${v}`and'…redirect_uri=' + v- Not reported: constant prefixes (
location.origin + '/callback','/auth/' + x),location.href/Router.url(own origin), values checked against a host allowlist or same-origin comparison (as NGB011)
Example
this.oauth.configure({ ...cfg, redirectUri: this.route.snapshot.queryParams['returnTo'] });Safer alternative
this.oauth.configure({ ...cfg, redirectUri: `${location.origin}/auth/callback` });sessionStorage.setItem('returnTo', safeRelativePath(this.route.snapshot.queryParams['returnTo']));Remediation
Use a constant redirect URI (${location.origin}/auth/callback) registered exactly at the identity provider. Carry the page to return to in state (or session storage) and validate it as a same-origin path after sign-in.
False-positive considerations
- Applications whose identity provider enforces exact redirect URI matching are protected; keep the finding as a defence-in-depth issue or document an exception naming the IdP setting.
Known limitations
- The identity provider's redirect URI registration is not visible; exact-match providers make the finding unexploitable (confidence is therefore at most medium).
- Return-URL parameters passed through
stateand used after the callback are NGB011 (untrusted redirect), not this rule.
References
Run it
ngbastion explain NGB060