fix(middleware): fail-closed JWT/OAuth auth adapters (C2)#59
Open
ucekmez wants to merge 1 commit into
Open
Conversation
The auth adapters in `@eep-dev/middleware` (TypeScript) and `eep-middleware`
(Python) turned attacker-controlled credentials into trusted EEP proofs:
- `JWTAuthAdapter` base64-decoded the JWT payload and emitted
`{type:"identity", method:"did_verified"}` and capability proofs WITHOUT
verifying the signature or the `alg` header. An `alg: none` token, or any
forged token, was accepted at face value.
- The TypeScript `OAuthAuthAdapter` derived capability proofs straight from a
client-supplied `X-OAuth-Scope` header (or `scope` query param), so a caller
could assert any scope it wanted.
Both adapters now fail closed:
- `JWTAuthAdapter` rejects `alg: none` unconditionally, verifies HS256/384/512
signatures against a configured `secret` (constant-time compare), delegates
asymmetric/custom algorithms to a `verifyToken` / `verify_token` callback,
enforces `exp`/`nbf`/`iat` with a configurable clock-skew tolerance (60s
default), and emits no proofs (warning once) when no verification material is
configured. The algorithm router never lets an HMAC secret verify an
asymmetric token, and never lets the asymmetric callback rubber-stamp an HS
token. An explicit `algorithms` allowlist is supported.
- `OAuthAuthAdapter` requires an RFC 7662 `introspect` callback and reads scope
and subject only from the authorization server's response. A client-supplied
`X-OAuth-Scope` header is ignored.
The TypeScript `JWTAuthAdapterOptions` is extended (non-breaking) with `secret`,
`verifyToken`, `algorithms`, and `clockToleranceSec`; `OAuthAuthAdapter` now
takes a required `{ introspect }` option (mirrors `APIKeyAuthAdapter`'s required
resolver). `EEPServer` defaults are unaffected (it uses `HeaderProofAuthAdapter`).
Tests cover signed/forged/tampered/expired tokens, `alg: none`, algorithm
confusion, the allowlist, callback delegation (sync + async), introspection
states, and fail-closed construction. Coverage of the changed files is 100%
(TS jwt.ts/oauth.ts; Python jwt.py at 100% statements + branches, package gate
`--cov-fail-under=100` satisfied). READMEs and CHANGELOG updated.
Surfaced by the EEP protocol audit.
Signed-off-by: Ugur Cekmez <ucekmez@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
C2 — Fail-closed JWT / OAuth auth adapters
The vulnerability
The
@eep-dev/middleware(TS) andeep-middleware(Python) auth adapters converted unverified input into trusted EEP proofs:JWTAuthAdapterbase64-decoded the JWT payload and emitted{ type: "identity", method: "did_verified" }plus capability proofs without checking the signature or thealgheader. Analg: nonetoken — or any forged token — was accepted, so a caller could impersonate any DID and grant itself any capability/scope. Combined with structural-only proof checks (or any verifier that trustsdid_verified), this is a full authentication bypass.OAuthAuthAdapterread scopes straight from a client-suppliedX-OAuth-Scopeheader /scopequery param, so a caller could assert arbitrary capabilities.The fix (both languages, fail-closed, at parity)
JWTAuthAdapteralg: none(any casing) unconditionally.secretwith a constant-time compare.verifyToken/verify_tokencallback that returns verified claims ornull(wrapjose/ PyJWT / your AS). Sync and async callbacks supported.exp/nbf/iatwith a configurable clock-skew tolerance (default 60s).secretnorverifyTokenis configured.secretnever verifies an asymmetric token, and the asymmetric callback is never used to rubber-stamp an HS token. An explicitalgorithmsallowlist is honored.OAuthAuthAdapter(TypeScript)introspectcallback (mirrorsAPIKeyAuthAdapter's required resolver).X-OAuth-Scopeheader is ignored.EEPServerdefaults are unaffected (it usesHeaderProofAuthAdapter). The TSJWTAuthAdapterOptionsgains optionalsecret/verifyToken/algorithms/clockToleranceSec(non-breaking). The TSOAuthAuthAdapternow takes a required{ introspect }option (behavioral break for the previously trust-the-header constructor — justified, since the old behavior was the vulnerability).Files
packages/@eep-dev/middleware/src/auth/jwt.ts— native HS verification +verifyTokendelegation + temporal checks.packages/@eep-dev/middleware/src/auth/oauth.ts— introspection-based, header no longer trusted.packages/@eep-dev/middleware/src/index.ts— export new option types.packages/eep-middleware-python/eep_middleware/auth/jwt.py— Python parity (stdlibhmac).CHANGELOG.md— Security entry.Test plan
npx vitest run --coverage(Node 22, mirrors CItest-middleware): 94 passed;jwt.ts,oauth.ts,index.tsat 100% stmts/branch/funcs/lines.tsc --noEmit: clean.pytestwith the package gate--cov-fail-under=100: 48 passed, total coverage 100% (jwt.py100% statements + branches).scripts/verify-llms-docs.py: OK (no doc drift).alg:none/wrong-length-sig/algorithm-confusion/allowlist/clock-tolerance,verifyTokendelegation (sync+async, null, throw, temporal), OAuth introspection (active/inactive/null/throw/empty-scope/header-ignored), and fail-closed construction warnings.Notes for reviewer