Secure code review

Reviewing self-contained token provenance and signature trust

Access lifetime: key, clock, server arranged to illustrate reviewing self-contained token provenance and signature trust.

Self-contained tokens carry assertions that a trusted verifier must validate against the intended use. Understanding self-contained token provenance and signature trust 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 token that is well formed but intended for a different context is accepted for a protected operation.

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.

A code audit connects a stated requirement to the implementation responsible for enforcing it. Source review and targeted behavioural checks should explain the same boundary and any relevant exceptions.

How penetration testers check for it

Review the specific control expectations below against the code, deployment and observable application behaviour.

  • 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

Implement the required boundary in the component that actually performs the sensitive operation and retain focused regression coverage.

  • 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.

Read about our methodology or contact pentested.com to discuss the security of your application code.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo