fix(web): log session-token provenance and hint at stale .env on mismatch - #78901
Closed
andrexibiza wants to merge 2 commits into
Closed
fix(web): log session-token provenance and hint at stale .env on mismatch#78901andrexibiza wants to merge 2 commits into
andrexibiza wants to merge 2 commits into
Conversation
…atch Signed-off-by: andrexibiza <84248988+andrexibiza@users.noreply.github.com>
The provenance classifier labels the stale-.env clobber state 'injected' (HERMES_DESKTOP=1 survives the override while the token is replaced), so the old early-return suppressed the actionable hint on the exact lockout scenario it was built for. A loopback mismatch with an env-sourced server token IS the signature — a genuinely adopted injection would have matched and never reached the hint. Fire for injected+env alike; 'generated' keeps its restart wording. Signed-off-by: andrexibiza <84248988+andrexibiza@users.noreply.github.com>
Contributor
Author
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.
What
Part of the coordinated close for #40680 (stale
.envsession token poisoning desktop auth). This PR makes the backend say where its token came from and name the fix when a mismatch happens._resolve_session_token()now records provenance:injected(env token +HERMES_DESKTOP=1),env(token present, no desktop marker — includes the stale-.env-clobber case), orgenerated(fresh random).dashboard session token: source=<provenance> length=<n>— never the token value itself.token_mismatchin loopback mode, when the server token source is notinjected, a WARNING names the likely cause and the fix: a staleHERMES_DASHBOARD_SESSION_TOKENin<hermes-home>/.env— remove the line or runhermes setup. Existing rejection log line preserved verbatim (compat).Auth semantics are unchanged — this is diagnostics only.
Dedup/composition note — overlapping open PR #54034 (authored by @Kewe63): #54034 changes the same
_SESSION_TOKENresolve line in the opposite direction (persisting the token across daemon restarts; sweeper-flagged as an unresolved security-boundary decision —keep_open salvageability=medium). This PR is diagnostics-only and deliberately written to compose: the provenance classifier is a pure function (_session_token_source()) that classifies whatever value ends up in_SESSION_TOKEN, so it works identically whether that value came from env,.env, or a future persistence layer. No conflict in direction, but both PRs touchhermes_cli/web_server.py— merge order matters only for whitespace, not semantics.Reproduction (current vs expected)
Current (pre-fix): a desktop lockout produced exactly one opaque log line —
console auth rejected reason=token_mismatch mode=loopback cred=token peer=127.0.0.1— with no indication that the server token came from a stale.envvalue._resolve_session_token()(web_server.py:330) silently took whichever env value won.Expected (post-fix): the startup log says
dashboard session token: source=env length=32(never the value), and a loopbacktoken_mismatchwithsource != injectedis followed by a WARNING naming the exact fix: a staleHERMES_DASHBOARD_SESSION_TOKENin<hermes-home>/.env— remove the line or runhermes setup.How to test
New unit tests cover: provenance classification for injected/env/generated (pure classifier function, no source-file reads), and the mismatch hint emitted via caplog when source != injected.
Platforms tested
git diff --checkclean,scripts/check-windows-footguns.py hermes_cli/web_server.pyclean.Why this matters to users
Before, a desktop lockout produced one opaque line (
console auth rejected reason=token_mismatch) with no hint about the cause — users stared at a dead app for hours. After, the startup log tells you in one line whether the backend is holding your injected token, and a mismatch tells you exactly which file and key to clear.