NHI Forum
Read full article from Curity here: https://curity.io/blog/transaction-tokens-new-phantom-tokens/?utm_source=nhimg
Modern software architectures are increasingly componentized. Whether via microservices or modular monoliths, most backend requests now traverse multiple services. This evolution introduces new security challenges, particularly when adopting zero-trust principles.
The IETF’s OAuth working group proposes transaction tokens as a new standard to strengthen access control in multi-service environments. At Curity, we’ve also long advocated a similar approach called the phantom token pattern. This article explores both approaches, their similarities, differences, and practical implementation guidance.
Why Transaction Tokens Are Needed
In distributed architectures, traditional access tokens are often insufficient. Consider a scenario where:
- A request passes through multiple internal services.
- One service is compromised due to remote code execution, supply-chain attacks, cloud vulnerabilities, or rogue insiders.
Even with access tokens, an attacker could potentially:
- Reuse stolen tokens to call other services.
- Abuse tokens outside the context of the original request.
Zero-trust security requires both infrastructure-level and application-level controls:
- Infrastructure-level security: Limits which services can communicate internally.
- Application-level security: Ensures each service independently authorizes requests using access tokens.
Transaction tokens address the remaining gap: token misuse within internal networks.
How Transaction Tokens Work
Transaction tokens are short-lived credentials tied to a specific request or transaction. The flow typically looks like this:
- The incoming access token is exchanged for a transaction token, usually at the API gateway.
- The gateway requests a transaction token from the token service (OAuth authorization server), which returns a JWT containing:
- Relevant access information (subject ID, roles)
- A unique transaction ID to prevent token replay
- Request context (endpoint, HTTP method, IP address)
- The transaction token is passed downstream in a Txn-Token header.
Benefits:
- Limits token reuse to a single request.
- Ensures tokens are context-aware, reducing the risk of misuse.
- Can track and enforce call chains, e.g., ensuring a fraud-check service handled a payment request first.
The Phantom Token Pattern
Phantom token pattern offers similar protections:
- External clients receive opaque tokens that reveal no internal information.
- The API gateway introspects the opaque token, retrieving a JWT for internal use.
- Internal services use the JWT for authorization, but it cannot be replayed externally.
Key Difference: The JWT generated in the phantom token pattern does not contain request-specific context. Its lifetime matches the original access token, and every introspection returns the same JWT.
Comparing Transaction and Phantom Tokens
|
Feature |
Transaction Tokens |
Phantom Tokens |
|
External token format |
Not defined |
Opaque token issued to clients |
|
Internal token format |
JWT |
JWT from introspection |
|
Scope |
Single transaction/request |
Access token lifespan |
|
Context awareness |
Yes, can include endpoint, method, IP, call chain |
No, static per access token |
|
Standards |
OAuth Token Exchange |
OAuth Token Introspection |
|
Integration effort |
Requires custom headers and processing |
Uses standard Authorization header, easier integration |
Similarities:
- Both protect internal JWTs from external misuse.
- Both use different tokens inside and outside the infrastructure.
- Both rely on JWTs for offline verification to reduce internal traffic to the token service.
Differences:
- Transaction tokens are transaction-specific and context-aware.
- Phantom tokens are longer-lived, introspected per access token, and simpler to integrate.
Implementation Guidelines
Both approaches are complementary, and you may choose to implement either or both. Key principles:
- Use opaque tokens externally to protect sensitive data.
- Never reuse tokens across external and internal boundaries.
- Enrich internal tokens with request context and additional information for finer-grained authorization.
- Implement exchanges or introspection at the API gateway.
- Decide on architecture:
- Transaction tokens: follow draft standard, use Txn-Token headers.
- Phantom tokens: forward JWTs in Authorization headers for easier integration.
Conclusion
Both phantom tokens and transaction tokens address the risk of internal token theft in distributed systems.
- Phantom tokens: Easier to implement today, leverage standard introspection, protect tokens from external misuse.
- Transaction tokens: Provide transaction-specific, context-aware security, ideal for zero-trust architectures spanning multiple services.
For most organizations, phantom tokens are a practical starting point, while transaction tokens represent the future standard once libraries and RFCs mature.