JWT signature and algorithm validation in API gateways
A JWT verifier must use trusted algorithms and keys instead of accepting instructions from an untrusted token. Understanding JWT signature and algorithm validation in API gateways helps establish which security property the feature needs and where that property is actually enforced.
What does this involve?
Session and token controls preserve an authentication decision over time. They need a defined scope, lifetime and invalidation policy. A token should be accepted because a trusted service has verified the relevant properties, not simply because its structure looks familiar.
Why it matters
Consider a realistic failure: a gateway accepts a token signed with an unintended verification key.
A reusable credential can let someone continue acting as an account after the intended access should have ended. Long-lived access, excessive token contents and inconsistent revocation can increase the exposure beyond the initial event.
An API review follows the server-side behaviour behind the interface. Direct requests, alternate methods and background operations can reveal boundaries that the normal frontend journey does not exercise.
How penetration testers check for it
Review allowed algorithms, issuer trust, key selection and failure paths.
- Confirm that self-contained tokens are validated using their digital signature or MAC to protect against tampering before accepting the token's contents.
- Confirm that only algorithms on an allowlist can be used to create and verify self-contained tokens, for a given context. The allowlist must include the permitted algorithms, ideally only either symmetric or asymmetric algorithms, and must not include the 'None' algorithm. If both symmetric and asymmetric must be supported, additional controls will be needed to prevent key confusion.
- Confirm that key material that is used to validate self-contained tokens is from trusted pre-configured sources for the token issuer, preventing attackers from specifying untrusted sources and keys. For JWTs and other JWS structures, headers such as 'jku', 'x5u', and 'jwk' must be validated against an allowlist of trusted sources.
- Test logout, permission changes and credential replacement.
- Inspect replay and concurrent use according to the documented design.
How to fix it
Pin verification policy to trusted configuration and validate the relevant claims.
- Use appropriately scoped credentials with bounded lifetimes.
- Validate trusted issuance and relevant claims consistently.
- Rotate and revoke according to the session model.
- Keep credentials out of unnecessary URLs, logs and persistent copies.
Some designs intentionally use short-lived credentials without immediate global revocation. Assess the complete lifetime and access model before calling that design a failure.
Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.
Related issues
- API request schema and content type validation
- API refresh token rotation and replay detection
- OAuth access token audience and scope validation in APIs
Read about our methodology or contact pentested.com to discuss your APIs and integrations.