Final-head review fold:
- verify_jwt: the expired / bad-signature / not-yet-valid arms existed only
because the catch-all used to raise ProviderError; all now raise the same
InvalidCodeError, so one InvalidTokenError arm covers them (PyJWT's own
message names the failure; the clock-skew test matches it). The aud/iss
arm's diagnostic re-decode runs only after the signature verified, so its
try/except-pass guarded nothing.
- Docstrings: ProviderError also covers a malformed JWKS and a provider-wide
contract failure (oauth_contract_version); the refresh comment no longer
assumes Portal's rotate-on-use refresh tokens.
- Cookie tests use the __Host- names the server sets over HTTPS, so they
keep exercising verify/refresh once bare names stop being read there
(#136772); the access-token-only case asserts the session-expired reason
rather than any 401.
Round-2 review: the drift WARNING fired on every InvalidTokenError. PyJWT
checks the algorithm before the signature, so a forged token naming the
published kid with another alg reached that branch unauthenticated and
logged attacker-chosen iss/aud of any length.
Warn only on InvalidAudienceError / InvalidIssuerError, which PyJWT raises
after the signature verified (a real IdP-signed token: a foreign client's,
or config drift), with the echoed unverified values capped at 128 chars.
Other claim failures stay a plain InvalidCodeError, unlogged.
Tests: a forged-alg token with the published kid is a 401 with no drift
line (fails against the previous shape), and a gate-level cookie+RT case
where Portal's rotated token does not verify here is a signed-out 401.
Folds the pre-arm review of the salvaged stack:
- Map a grant's "minted token is not ours" InvalidCodeError to
RefreshExpiredError once, in JwtOAuthProvider.refresh_session, instead of
a copy in each provider's _grant (the auth-code path already raises
InvalidCodeError -> 400, so the copies only mattered for refresh).
- A wrong aud/iss is also what config drift looks like (wrong client_id or
portal URL). Now that it is a 401 instead of a 503, nothing logged it:
verify_jwt logs the token's and the configured iss/aud at WARNING. The
diagnostics tests assert that log through verify_session instead of
calling _claims_for/_verify_id_token directly.
- oauth_contract_version mismatch deliberately stays a 503 (every token
Portal mints would fail it); say so beside the check.
- Fix the now-stale InvalidCodeError and classify_jwks_lookup_error
docstrings and trim per-branch comments that restated the rule.
- Tests: fold the gate-level cases into test_opaque_bearer_not_unreachable.py
with one JWKS-server helper and one gated-app helper (three server copies
-> one), add a cookie-path case, close the server socket.
verify_jwt raised ProviderError for every decode-time rejection except
expiry, so a token minted for a different client on the same IdP (e.g. the
Hermes Desktop app reusing one session across two same-issuer gateways)
surfaced as '503 Auth provider self-hosted unreachable' — the IdP was
reachable and had answered; the token was simply not ours (audience
mismatch). Operators only saw the real reason in errors.log.
Denials are now InvalidCodeError end-to-end:
- verify_jwt: wrong audience/issuer, bad signature, missing claims ->
InvalidCodeError (diagnostic iss/aud still appended). verify_session
returns None per protocol -> middleware refreshes / re-logins.
- JwtOAuthProvider grants (self-hosted + nous) map a verify-stage
InvalidCodeError to the caller's bad_request_exc (InvalidCodeError for
the auth-code path, RefreshExpiredError for refresh) so the middleware
refresh scan rejects the provider instead of crashing on an uncaught
InvalidCodeError.
- JWKS transport failures stay ProviderError (503) — unreachable means
unreachable.
45 conflicts, all from #135177 (lefthook + `ruff check --fix` over 2,366 files). No other main commit
touches a conflicted file. Resolution: the branch side of each file, then main's exact autofix
(ruff 0.15.10, `--config ./ruff.strict.toml --fix`) on it — rewrites only (typing generics, noqa
drops, import forms), no import removed. tests/cron/test_bot_chat_cli_home.py stays deleted
(1cc9cb9199 retired its lane).
Conflict: tui_gateway/server.py (f3ef9db683 voice-turn reasoning leak). The branch moved
_runtime_model_config/_persist_live_session_runtime to tui_gateway/agent_factory.py; main's
session_runtime_view edits ported there, and kept in place for _live_session_identity and
_session_info.
Reverts the plugins/dashboard_auth half of ca38caeea0.
_request_limited_response streamed the body via iter_bytes() (already
gzip-decoded by httpx) and rebuilt an httpx.Response with the ORIGINAL
headers, Content-Encoding: gzip included, so .json() tried to gunzip
plaintext. Every Nous Portal dashboard login failed with
503 "Provider unreachable: Portal token endpoint unreachable: Error -3
while decompressing data: incorrect header check". Self-hosted OIDC
discovery/token/revocation used the same helper.
The urllib half (gateway health probe, ElevenLabs voices) is kept:
urllib does not decode Content-Encoding, and c061068b26 builds on its
_read_dashboard_json_response helper.
Dashboard-side urllib readers (gateway health probe, ElevenLabs voices)
and self-hosted OIDC httpx readers (discovery, token exchange, revocation)
buffered remote response bodies with no size bound — a hostile or
compromised upstream could exhaust memory. Both halves now read with a
1 MiB hard cap: a shared _read_dashboard_json_response for urllib JSON
reads and a streaming _request_limited_response for IdP endpoints that
prechecks Content-Length and caps the chunked body regardless.
Adapted from #54809 and #55122 (credit @ooiuuii) to current main, where
the token exchange lives in plugins/dashboard_auth/_shared.py and the
health probe in hermes_cli/web_server_gateway.py.
Fixes#54808, Fixes#55121
Both dashboard-auth JWT verification paths (self-hosted OIDC ID token and the
Nous Portal access token, via the shared verify_jwt) called PyJWT jwt.decode
with the default leeway=0 while requiring iat. Any host whose clock lags the
issuer's — unsynced containers/VMs, NTP jitter — failed login with
ImmatureSignatureError, and the failure was folded into ProviderError, i.e.
HTTP 503 'provider unreachable', discarding already-rotated refresh tokens
and forcing unrecoverable re-logins.
- verify_jwt gains leeway (default 60s, RFC 7519 §4.1.4-4.1.6) and classifies
ImmatureSignatureError as InvalidCodeError (validation failure -> 401 /
refresh) instead of ProviderError/503.
- New parse_leeway helper: fail-closed parsing (unparseable / negative / NaN /
inf -> 0, never widens the window); 0 honours strict mode.
- Self-hosted OIDC: id_token_leeway kwarg + dashboard.oauth.self_hosted.id_token_leeway.
- Nous: token_leeway kwarg + dashboard.oauth.token_leeway.
- No new env vars (config.yaml-only knobs).
Fixes#47815
verify_jwt folded jwt.InvalidSignatureError into the generic InvalidTokenError branch and
raised ProviderError, so the gated API answered a tampered/foreign-key OIDC bearer with
HTTP 503 "Auth provider 'self-hosted' unreachable" (cookies retained, no fall-through to
the next provider) while the IDP was healthy. Live remote-bind probe on 127.0.0.2 showed it.
Signature failure now maps to InvalidCodeError -> verify_session None -> 401
session_expired, same as an expired token. Genuine iss/aud drift keeps its diagnostic 503.
For each issue anchor present in BASE 63279301bc non-test .py and absent on HEAD, the BASE comment/docstring block was re-attached at the HEAD location of the code it explained (matched by the distinctive code line / enclosing def). Sentences already covered by an existing HEAD comment were deduped; the issue number always survives. Insert-only: no code lines changed.