T09 · Insecure Skill Coding Practices
- Location
references/examples.md:450- Finding
Bearer Token Forwarded to Unrestricted Request Destinations
- Content
View full analysis
Vulnerability Details
File Location:
references/examples.md, lines 450–460
Vulnerability Type: Unrestricted credential forwarding
Risk Level: Hightypescript const token = authService.getToken(); if (token) { req = req.clone({ setHeaders: { Authorization: `Bearer ${token}` } }); } return next(req);Technical Analysis
The example interceptor adds the user's bearer token to every request processed by Angular's HTTP client. It does not verify that the request uses HTTPS or that its destination origin belongs to the application's trusted API.
Angular interceptors can process both relative same-origin requests and absolute requests to third-party origins. Consequently, application code or a compromised dependency can initiate a request to an attacker-controlled server and cause the interceptor to attach the authentication token. An attacker-controlled server can permit the browser's CORS preflight and receive the resulting request with its
Authorizationheader.Credential forwarding exceeds the minimum privilege needed for an authentication interceptor. The token should only be attached to explicitly trusted API origins and paths.
Attack Path
- A compromised dependency, injected application component, or other attacker-controlled frontend code initiates an Angular HTTP request to an attacker-controlled HTTPS origin.
- The global interceptor processes the outbound request without validating its destination.
- The interceptor retrieves the active bearer token and adds it to the
Authorizationheader. - The attacker-controlled server permits the CORS request and records the bearer token.
- The attacker replays the token against the legitimate API until it expires or is revoked.
Impact Assessment
Disclosure gives an attacker the same API access represented by the bearer token. Depending on the token's scopes and the authenticated user's privileges, ...[truncated 283 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse each request URL and attach the token only when its exact origin matches an explicit trusted API allowlist.
- Restrict credential attachment further by validating expected API path prefixes.
- Reject or omit credentials for non-HTTPS destinations.
- Avoid suffix-based or substring hostname checks; compare normalized origins exactly.
- Consider secure,
HttpOnly,Secure, and appropriately configuredSameSitecookies where the application's architecture supports them. - Add unit tests proving that the interceptor does not add
Authorizationto third-party, malformed, look-alike, or non-HTTPS URLs. - Apply short token lifetimes, narrow scopes, rotation, and prompt revocation to reduce the impact of disclosure.
