advanced26 min studyLesson 425 in Engineering

Audience binding and constrained delegation

Prevent token substitution and confused-deputy access by preserving recipient and caller authority boundaries.

On this page

What you’ll understand

  • Explain why a valid token for one audience is not automatically valid elsewhere.
  • Separate an authenticated caller from a service's own ambient authority.
  • Constrain delegated permissions using a documented exchange policy.

A token can have a valid signature and still be inappropriate for the service receiving it. Audience binds an assertion to its intended recipient or use context. Delegation adds another question: when a service acts for a caller, whose authority is being exercised? Without that distinction, a less privileged caller can induce a powerful service to perform an action the caller could not request directly. Validate both recipient binding and the permitted delegation relationship.

Recipient validation prevents one class of substitution

A resource service must apply the validation rules for the token type it accepts, including issuer, audience, time, algorithm, and relevant subject or scope constraints. Do not accept every signed JWT as an API access token. An OpenID Connect ID Token is intended for a relying party's authentication context and is not automatically a bearer access token for an unrelated resource API. A token's audience claim is meaningful only when the recipient compares it with the audience it is configured to accept.

Multiple audiences and token types need explicit policy, not a substring match on a service name. Validate identifiers according to their format and avoid treating an attacker-supplied key URL as an authority-selection shortcut. A token intended for service A should not gain acceptance at service B merely because both trust the same issuer. Audience is one necessary boundary; it does not by itself define the actions or resources that an authenticated subject may access.

recipient⁡∈aud⁡(T)\operatorname{recipient}\in\operatorname{aud}(T)
For a token format requiring audience validation, the intended recipient must match an accepted audience under that format's rules. Membership is a logical check, not a substitute for issuer, signature, time, type, or authorization validation.↔ Scroll wide equations horizontally.

A deputy must not lend all its privileges

A service may possess credentials that permit broad backend access while exposing a narrow user-facing operation. If it blindly forwards a caller-selected resource under its own identity, it can become a confused deputy. Bind the request to the caller's allowed resource and action, or use an explicit delegated credential whose authority is appropriately constrained. A trustworthy service identity tells the backend which service called; it does not automatically preserve the originating user's permissions.

OAuth token exchange can express subject and actor relationships under a defined issuer policy. Exchange does not inherently mean downscoping, one-time use, or revocation of the original token. The authorization server must enforce which callers may exchange which evidence for which audiences and permissions. Preserve audit context for both represented subject and acting service when the protocol supplies it. Avoid logging the exchanged tokens themselves, since ordinary bearer artifacts can be replayable during validity.

Adelegated⊆Acaller∩Aexchange policy\mathcal A_{\rm delegated}\subseteq\mathcal A_{\rm caller}\cap\mathcal A_{\rm exchange\ policy}
This is the desired downscoping invariant for this lesson's delegated-access design. It is not an automatic property of every token exchange. Sets contain allowed action-resource pairs, and broader impersonation designs require their own explicit authorization rules.↔ Scroll wide equations horizontally.

Test cross-recipient and cross-resource failures

Present a token intended for another service and verify rejection before the business operation runs. Then test a valid caller token with a forbidden resource, action, or tenant. Exercise an exchange request asking for more scope than the policy permits, and inspect issued claims and backend decisions. Include cache keys and authorization caches: reusing a decision across audiences or caller contexts can undo correct token validation at the entry point. Return useful rejection diagnostics without exposing complete credentials.

The vectors lab is an explicit contrast with permission composition. Reset and set both angle 0, magnitude 2, predict(2,0), then inspect; Reset and re-set angle 90, magnitude 2 to predict(0,2). Geometric projections are not scopes, token audiences, or a cryptographic proof. In particular, adding two vectors is not how authority should be combined. Use the example to explain why a deputy should enforce a set intersection and recipient checks rather than simply add its own powers to the caller's request.

A deputy with four powers and a caller with two

A service can read A, read B, write A, and delete B. Its caller is allowed only read A and read B. The exchange policy permits those same two read operations for the downstream audience.

  1. Represent authority as action-resource pairs rather than unqualified action names. The service has four pairs, while the caller and exchange policy each contain the two reads.

  2. Under the stated downscoping rule, the delegated set has at most two pairs: read A and read B. The service's write and delete powers are not inherited by the caller.

  3. A request to delete B must be rejected even if the service's own credential could perform it. The downstream token must also target the intended audience; correct scope does not repair a wrong-recipient token.

The result

Delegation needs an enforced caller-and-policy boundary. A valid service identity alone can otherwise expose its ambient authority.

Explore the model

Interactive lab

Interactive lab · vectors

Authority is not vector addition

Reset, set angle 0°, magnitude 2, predict(2,0). Reset and re-set 90°,2, predict(0,2). This geometry contains no tokens, audiences, scopes, or delegation checks and cannot verify a permission intersection.

Authority is not vector additionPlayback traces a fixed vector and its projections. Angle and magnitude set the geometry; the moving marker does not change them. Current readings: x component: 1.393; y component: 0.975; Magnitude: 1.7. All parameters are adjustable with the labeled controls below.−7.46−3.7303.737.46−3.5−1.7501.753.5xyvvₓ = 1.39
Vectorx / y projectionsTrace marker
x component
1.393
y component
0.975
Magnitude
1.7
t = 0 s

Playback traces a fixed vector and its projections. Angle and magnitude set the geometry; the moving marker does not change them. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forKeep caller authority, service authority, and recipient binding explicit instead of combining them by intuition.

Check your understanding

A valid signed token names service A as its audience. Service B trusts the same issuer. What should B do if its required audience is absent?

Try it yourself

A caller can read records 1 and 2. A backend service can read records 1 through 100. Explain how a request for record 90 can become a confused-deputy bug and identify the check that prevents it.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Distinguish the credential used for the backend call from the caller's permitted resource set.

Compare with the solution

If the service uses its broad backend credential for any caller-selected record without checking the caller's resource permission, the caller gains access to 90 through the deputy. Enforce the caller's action-resource authorization or issue a correctly constrained delegated credential for the intended audience. Merely authenticating the service and caller does not establish that record 90 is allowed.

Take it with you

  • Audience validation prevents inappropriate recipient substitution.
  • A deputy's own credentials must not silently expand caller authority.
  • Token exchange needs explicit audience, scope, subject, and actor policy.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.