Skip to content

feat(oauth2): RFC 8707 resource indicators bind token audience (Wave 2a) - #421

Merged
voidvec merged 2 commits into
masterfrom
feat/rfc8707
Dec 3, 2026
Merged

voidvec merged 2 commits into
masterfrom
feat/rfc8707

Conversation

@voidvec

@voidvec voidvec commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Summary

Completes the remaining half of AI-productization Wave 2a (design: docs-local/designs/ai/v1.5.0-ai-productization-design.md; RFC 9207 iss already landed via a373cd5). Implements RFC 8707 §2 resource indicators at the token endpoint so an MCP-compliant resource server can verify audience binding — the exact confused-deputy defense the MCP spec (2026-07-28) makes mandatory for its ecosystem.

Behavior

  • Optional resource form parameter accepted on all four grants (authorization_code / refresh_token / client_credentials / device_code) at POST /oauth2/token.
  • Valid indicator → the issued access token's audience (introspection aud) is the resource URI, overriding the P0-4 default aud = client_id; absent → byte-for-byte existing behavior (pure opt-in).
  • Refresh rebinds per request's resource (RFC 8707 §2.1); id_token aud semantics unchanged (still client_id).
  • Malformed indicator → invalid_target (400, RFC 6749 §5.2 envelope), validated once before the F-017/F-018 gates so all grants share semantics.
  • Device grant now also stamps the P0-4 default audience (completion of Tracking: P0-4 — Write audience on token issuance (introspection aud) #258: the device path had missed it).
  • Postgres saveAccessToken now persists audience like the pair insert already did.
  • PAR-initiated flows: stage 1 keeps token-time binding (token-endpoint decides); authorize-side storage remains stage-2 hardening per design.

Sync checklist (invalid_target + openapi)

  • ErrorCatalog.cc OAuth table 13→14 + kRequiredOAuthCodes 13→14
  • ErrorCatalogRegressionTest / ErrorCatalogPropertyTest code lists
  • docs/domains/api-reference.md §5.2 row (ErrorCatalogDocTest green)
  • frontends zh-CN/en × admin/user (crossAppConsistency property test + i18nKeys parity green)
  • openapi.yaml TokenRequest.resource + 400 description; C++ doc registration; openapi.json regenerated; Python/Go/TS SDK regenerated (drift gate green)
  • api-diff baseline approved with --force — 6 modified declaration lines only append trailing defaulted parameters (source-compatible; precedent: generateAuthorizationCode authTime/amr/orgId)

Tests

  • TokenServiceTest: exchange + refresh audience override (gtest, 36/36 suite green)
  • RuleSet resource-indicator validation: 7 new DROGON cases (RFC 3986 scheme parse — accepts https:/urn:, rejects relative/fragment/whitespace/>255/bad-scheme)
  • OAuth2ProtocolEndpointRfcComplianceTest B3: live invalid_target routing case
  • local-gates.sh 6/6 green; naming gate green

Out of scope (by design)

  • CIMD (Wave 2b), authorize-side resource storage (stage 2), RFC 8693 token exchange (Wave 3).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T05:29:30.481611Z 2732d8b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2732d8b7f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// The device-code lookup (Mapper::findBy + atomic consume) is the same
// for both; wrapped in a local lambda so both paths converge on it.
auto runDeviceCodeLookup = [plugin, sharedCb, clientId, deviceCodeHash, dbClient]() {
auto runDeviceCodeLookup = [plugin, sharedCb, clientId, deviceCodeHash, deviceResource, dbClient]() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Migrate the touched device-code lookup into a repository

This change modifies the device-code lookup and its database callbacks while retaining direct Mapper access in the controller. libs/drogon/AGENTS.md explicitly requires migrating existing direct queries when they are touched; the historical exception does not waive that migrate-on-touch requirement. Move the affected lookup/consume operation behind a repository or Domain service and pass the resource indicator through that interface.

AGENTS.md reference: libs/drogon/AGENTS.md:L105-L107

Useful? React with 👍 / 👎.

Comment on lines +632 to +637
if (resource.find_first_of(" \t\r\n") != std::string::npos)
{
return "resource must not contain whitespace";
}

return std::nullopt;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate the URI remainder before accepting a resource indicator

For malformed resources such as https://api.example/%GG or https://[not-an-ip]/, this validator returns success because it only checks the scheme, fragment, and a few whitespace characters. I confirmed both inputs are accepted by compiling and running the extracted validator. Consequently, the token endpoint issues tokens with malformed audiences instead of returning the documented invalid_target response. Validate the complete absolute-URI syntax, including percent escapes and authority syntax, before accepting the indicator.

Useful? React with 👍 / 👎.

Thread an optional RFC 8707 §2 `resource` parameter through the token
endpoint's four grants. A valid indicator overrides the P0-4 default
audience (aud = client id) on the issued access token and rebinds on
refresh; absent parameters keep existing behavior byte-for-byte.
Malformed indicators are rejected with the new RFC 8707 protocol error
invalid_target (400) before any grant dispatch. The device grant also
gains the P0-4 default audience stamp the code/CC paths already had.

- TokenService/Plugin: source-compatible trailing defaulted `resource`
  params on exchangeCodeForToken / exchangeCodeForAuthenticatedClient /
  refreshAccessToken. api-diff baseline approved with --force:
  the 6 modified declaration lines only append trailing default
  parameters (source-compatible; precedent: generateAuthorizationCode
  authTime/amr/orgId).
- RuleSet::validateResourceIndicator: RFC 3986 absolute-URI scheme
  parse (scheme = ALPHA *( ALPHA / DIGIT / + / - / . ) ':'), no
  fragment, no whitespace, <=255 chars (audience column limit).
- Postgres saveAccessToken persists audience like insertPair already
  does (single-token path parity).
- invalid_target 8-place sync: ErrorCatalog (13->14), regression +
  property test code lists, api-reference §5.2 table, frontends
  zh-CN/en catalogs (admin+user), crossAppConsistency code domain,
  openapi.yaml (TokenRequest.resource + 400 description), C++ doc
  registration, openapi.json + Python/Go/TS SDK regenerated.
- Tests: TokenServiceTest exchange/refresh audience override (gtest),
  RuleSet indicator validation (7 DROGON cases), live-routing B3
  invalid_target case; ErrorCatalogDoc OAuth table test green.

Local verification: 36 TokenServiceTest gtests pass, 12 targeted
DROGON cases pass, local-gates.sh 6/6 green, spec-governance OK,
clients-sdk drift OK, naming gate OK.
- CategoryA initorder token-endpoint snapshot: 7 -> 8 query params
  (resource indicator joins grant_type/code/refresh_token/client_id/
  client_secret/redirect_uri/code_verifier in the registered set).
- website llms-full.txt regenerated (+1 line: the invalid_target row in
  docs/domains/api-reference.md) to satisfy the freshness gate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant