Restrict CORS origins instead of wildcard '*' (issue #334) - #341
Open
Diogo-Damasceno wants to merge 1 commit into
Open
Restrict CORS origins instead of wildcard '*' (issue #334)#341Diogo-Damasceno wants to merge 1 commit into
Diogo-Damasceno wants to merge 1 commit into
Conversation
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.
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.
Summary
Fixes #334. The server exposes unauthenticated endpoints (
/scan,/scan-csv,/stop,/verify).setup_cors()hard-codedallow_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: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=Falseis set explicitly.Verification
pytest tests/unit/test_cors_middleware.py→ 6 passed.test_fuzzer::test_successful_response_no_refusal) and 2test_static_icon_validationerrors are pre-existing and unrelated (require LLM/network assets), not caused by this change.Test plan for reviewers
curl -H "Origin: http://evil.example.com" http://localhost:8000/probe→ response has noaccess-control-allow-origin.AGENTIC_SECURITY_CORS_ORIGINS=https://app.example.com: same request withOrigin: https://app.example.com→access-control-allow-origin: https://app.example.com, and noaccess-control-allow-credentials: true.