Skip to content

Restrict CORS origins instead of wildcard '*' (issue #334) - #341

Open
Diogo-Damasceno wants to merge 1 commit into
msoedov:mainfrom
Diogo-Damasceno:fix/cors-restrict-origins
Open

Restrict CORS origins instead of wildcard '*' (issue #334)#341
Diogo-Damasceno wants to merge 1 commit into
msoedov:mainfrom
Diogo-Damasceno:fix/cors-restrict-origins

Conversation

@Diogo-Damasceno

Copy link
Copy Markdown

Summary

Fixes #334. The server exposes unauthenticated endpoints (/scan, /scan-csv, /stop, /verify). setup_cors() hard-coded allow_origins=["*"], so any web origin could drive those endpoints from a victim's browser (drive-by scanning / CSRF-like abuse).

Change

agentic_security/middleware/cors.py:

  • Allowed origins are now opt-in via AGENTIC_SECURITY_CORS_ORIGINS (comma-separated). When unset/empty, no cross-origin origin is allowed — safe default for a server-side scanning API.
  • allow_credentials=False is set explicitly.

Verification

  • pytest tests/unit/test_cors_middleware.py → 6 passed.
  • Full suite: 389 passed; the only failure (test_fuzzer::test_successful_response_no_refusal) and 2 test_static_icon_validation errors are pre-existing and unrelated (require LLM/network assets), not caused by this change.
  • Ruff: clean on both changed files.

Test plan for reviewers

  1. Default (no env var): curl -H "Origin: http://evil.example.com" http://localhost:8000/probe → response has no access-control-allow-origin.
  2. AGENTIC_SECURITY_CORS_ORIGINS=https://app.example.com: same request with Origin: https://app.example.comaccess-control-allow-origin: https://app.example.com, and no access-control-allow-credentials: true.

The server exposes unauthenticated endpoints (/scan, /scan-csv, /stop,
/verify). Previously allow_origins was hard-coded to ['*'], so any web
origin could drive those endpoints from a victim's browser (drive-by
scanning / CSRF-like abuse).

Make allowed origins opt-in:
- Read AGENTIC_SECURITY_CORS_ORIGINS (comma-separated). When unset/empty,
  no cross-origin origin is allowed (safe default).
- Set allow_credentials=False explicitly.

Update tests/unit/test_cors_middleware.py to assert the new policy:
default has no wildcard origin, env var configures the allow list,
disallowed origins receive no ACAO header, allowed origins receive it
without credentials.
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.

CORS: allow_origins=["*"] exposes unauthenticated /scan, /scan-csv, /stop, /verify to any web origin

1 participant