Skip to content

Restrict CORS to localhost origins#3

Open
pmalaviya wants to merge 1 commit intofabriqaai:mainfrom
pmalaviya:fix/restrict-cors-to-localhost
Open

Restrict CORS to localhost origins#3
pmalaviya wants to merge 1 commit intofabriqaai:mainfrom
pmalaviya:fix/restrict-cors-to-localhost

Conversation

@pmalaviya
Copy link

Summary

  • Replaces wildcard Access-Control-Allow-Origin: * with an allowlist that only reflects localhost and 127.0.0.1 origins
  • Adds Vary: Origin header for correct caching behavior
  • Adds isLocalhostOrigin() helper with comprehensive test coverage

Problem

The wildcard CORS header allows any website visited in the browser to make JavaScript requests to the local API (/api/search, /api/stats) and read Claude Code chat log data. While the server correctly binds to 127.0.0.1, the permissive CORS policy means a malicious site could exfiltrate session data if the server is running.

Fix

CORS is now restricted to localhost origins only:

  • http://localhost / http://localhost:<port>
  • http://127.0.0.1 / http://127.0.0.1:<port>

Requests from any other origin will not receive CORS headers, so browsers will block cross-origin reads.

Test plan

  • All existing tests pass (go test ./...)
  • Updated TestCorsMiddleware to verify localhost origins are allowed and external origins are rejected
  • Added TestIsLocalhostOrigin table-driven test covering localhost, 127.0.0.1, external domains, and edge cases

🤖 Generated with Claude Code

The wildcard Access-Control-Allow-Origin header allows any website
to make requests to the local server and read chat log data via the
search and stats APIs. This restricts CORS to only localhost and
127.0.0.1 origins, preventing cross-origin data access from external
sites while preserving normal local usage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant