-
Notifications
You must be signed in to change notification settings - Fork 0
Add optional authentication to memory API routes #12
Copy link
Copy link
Open
Labels
Description
Problem
The /api/memory/* routes are intentionally unauthenticated, which is fine for local-only usage. However, if the app is ever exposed beyond localhost (e.g., via tunnel, LAN, or future cloud deployment), the memory API becomes an open read/write surface.
Proposed Solution
Add optional authentication that can be enabled via configuration:
- Default: no auth — Preserve current behavior for local development
- Opt-in token auth — When
OPENTRUST_MEMORY_API_AUTH=true, require a Bearer token matchingOPENTRUST_AUTH_TOKEN - Shared middleware — Reuse the existing auth verification from
lib/opentrust/auth.ts - Localhost bypass — Respect
OPENTRUST_ALLOW_LOCALHOST_BYPASSfor local access
Acceptance Criteria
- Memory API routes work without auth by default (backward compatible)
- When enabled, unauthenticated requests receive
401 Unauthorized - Token auth uses the same timing-safe comparison as login
- Localhost bypass works when configured
- Documentation updated with new env variable
- Unit tests for authenticated and unauthenticated scenarios
🤖 Generated with Claude Code
Reactions are currently unavailable