Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

FEAT-55: Harden local gateway auth with challenge-exchange flow - #17

Merged
shafty023 merged 3 commits into
mainfrom
FEAT-55
Mar 13, 2026
Merged

shafty023 merged 3 commits into
mainfrom
FEAT-55

Conversation

@shafty023

Copy link
Copy Markdown
Contributor

Replace origin-only browser auth with a cryptographic challenge-exchange session model. The browser obtains a short-lived challenge JWT from the API server, exchanges it with the local gateway (which verifies via the API), and receives a session token bound to the requesting origin.

Key changes:

  • Add LocalSessionStore for in-memory session management with TTL
  • Add local-auth-verifier to verify challenges against the API server
  • Rewrite isAuthorizedEngineerRequest to require session or gateway token
  • Add /gateway-auth/exchange route with fail-closed behavior (503 when API key missing, no silent fallback)
  • Add debug auth UI for dev-only token minting
  • Update CORS headers and CLAUDE.md documentation
  • Comprehensive tests for session store, verifier, exchange, and auth

Replace origin-only browser auth with a cryptographic challenge-exchange
session model. The browser obtains a short-lived challenge JWT from the
API server, exchanges it with the local gateway (which verifies via the
API), and receives a session token bound to the requesting origin.

Key changes:
- Add LocalSessionStore for in-memory session management with TTL
- Add local-auth-verifier to verify challenges against the API server
- Rewrite isAuthorizedEngineerRequest to require session or gateway token
- Add /gateway-auth/exchange route with fail-closed behavior (503 when
  API key missing, no silent fallback)
- Add debug auth UI for dev-only token minting
- Update CORS headers and CLAUDE.md documentation
- Comprehensive tests for session store, verifier, exchange, and auth
Comment thread apps/desktop/src/main/local-session-store.ts Outdated
Comment thread apps/desktop/src/server/router.ts
Comment thread apps/desktop/src/server/router.ts Outdated
@closedloop-ai-stage

Copy link
Copy Markdown

Code Review Summary

Status: Approved

Reviewers: Bug Hunter A, Bug Hunter B, Unified Auditor, Premise Reviewer, electron-specialist

Findings

Severity Count
Blocking 0
High 0
Medium 3

MEDIUM Issues (consider)

  1. [P2] [local-session-store.ts:38] tokenHash stores raw token bytes, not a hash — timingSafeEqual comparison is vacuous
  2. [P3] [router.ts:409] Non-loopback exchange attempt (403) logged as type: "request" instead of type: "security"
  3. [P2] [router.ts:414] Non-loopback exchange attempts logged as type='request' instead of type='security'

Validation Stats

  • Agent failures: 0 partitions skipped
  • Cross-file grouped: 0 findings consolidated
  • Duplicates merged: 3

Recommendation: Approve — no blocking or high-priority issues. Consider addressing the medium findings before merge.

- Hash session tokens with SHA-256 before storing so timingSafeEqual
  comparison is meaningful instead of comparing raw token bytes
- Log non-loopback exchange attempts as security events instead of
  generic request events
@shafty023
shafty023 merged commit 95ad44e into main Mar 13, 2026
1 check passed
@shafty023
shafty023 deleted the FEAT-55 branch March 13, 2026 21:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant