Repository navigation
Description
Follow-up to #320 (merged) and to @jackspiece's review on that PR, which asked for this to be tracked separately.
#320 removed allow_credentials=True, which fixed the invalid header combination. It left allow_origins = ["*"] in place. That wildcard is the more important half of the problem, and I now think it is worse than a plain CSRF surface.
What the code does today
agentic_security/middleware/cors.py:6—origins = ["*"], passed toCORSMiddlewarewithallow_methods=["*"]andallow_headers=["*"].agentic_security/__main__.py:13— the server binds to127.0.0.1:8718by default.agentic_security/routes/scan.py—POST /verify(:28),POST /scan(:67),POST /stop(:79) andPOST /scan-csv(:85) are all state-changing and all unauthenticated.require_authexists atagentic_security/core/security.py:146but is not applied to any route (grep -rn "require_auth" . --include="*.py"returns only its own definition).agentic_security/static/base.js:1—let SELF_URL = window.location.href;. The bundled UI is same-origin by construction and never needs a cross-origin grant.
So the wildcard is not serving the shipped client. It is only granting access to third parties.
Why this matters more than "someone can stop your scan"
/verify and /scan-csv both take an operator-supplied HTTP spec. parse_http_spec substitutes the locally configured secrets into the spec body before dispatch:
# agentic_security/http_spec.py:234
for key, value in secrets.items():
if not value:
continue
key = key.strip("$")
body = body.replace(f"${key}", value)Those secrets come from [secrets] in agentic_security.toml, expanded from the environment (core/app.py:60, expand_secrets). The destination URL is whatever the caller put on the spec's request line. A caller who controls the spec therefore controls where the operator's API keys are sent.
Combined with ACAO: *, any page the operator visits while the scanner is running can drive these endpoints, and for /verify can also read the response.
I verified this locally with a canary value in OPENAI_API_KEY and a local sink server, against origin/main at 1ef1314:
OPTIONS /stop,OPTIONS /verify,OPTIONS /scanwithOrigin: https://evil.example→ 200,Access-Control-Allow-Origin: *.POST /stopwith that Origin → 200{"status": "Scan stopped"}.POST /verifywith that Origin and a spec pointing at my sink → 200; the sink received{"stolen": "sk-CANARY-…"}, i.e. the real env value, and the JSON response was returned underACAO: *so a foreign origin could read it.
I have not built a browser proof-of-concept page, so the above is the server-side half measured through Starlette's TestClient; the browser half follows from ACAO: * on a preflight that is answered 200.
One wrinkle: CORS alone is not sufficient
Tightening the allowlist is necessary but does not close everything, because CORS decides whether the browser exposes the response, not whether the request is sent. Two endpoints qualify as CORS simple requests and are never preflighted:
POST /stop— no body, sofetch()sets noContent-Type.POST /scan-csv—multipart/form-datais a simple content type.
I confirmed both: with the allowlist patch applied and no origins configured, POST /scan-csv from a foreign origin still returned 200 and still delivered the canary key to my sink. POST /verify and POST /scan are safe once the allowlist is tight, because they reject Content-Type: text/plain with a 422 and therefore genuinely require a preflight.
Proposed fix
Two parts:
- Default to an explicit, configurable allowlist in
middleware/cors.py— read fromAGENTIC_SECURITY_CORS_ORIGINSor aserver.cors_allow_originssetting, defaulting to[](same-origin only). Warn if an operator explicitly configures"*". Keepallow_credentials=False. - Guard unsafe methods by
Originfor the non-preflighted paths: noOriginheader → allow (curl, the CLI and the test suite send none); same-origin → allow; allowlisted origin → allow; otherwise 403.
An alternative to (2) is a CSRF token minted into the UI, but the Origin check is a lot less machinery for a single-operator localhost tool, and it does not break any non-browser client.
Patch
I have this implemented and tested on DevamShah:harden-cors-origin-allowlist (d888659) — 6 files, the two middleware modules plus a [server] section in the generated settings, and 23 tests across tests/unit/test_cors_middleware.py and tests/unit/test_origin_guard.py.
Verified with the project venv on Python 3.14.5:
python -m pytest tests/unit/test_cors_middleware.py tests/unit/test_origin_guard.py -q→23 passedpython -m pytest tests -q -p no:randomly→1 failed, 407 passed, 3 skipped, 41 deselected, plus 1 collection error. I checked the failure and the error against unmodifiedmainby stashing the patch and they reproduce there too:tests/unit/probe_actor/test_fuzzer.py::TestProcessPrompt::test_successful_response_no_refusalfails on'OneClassSVM' object has no attribute '_effective_probability'(scikit-learn drift against the pickled classifier), andtests/system/test_lib.py::TestLibraryLevel::test_classerrors with aFileNotFoundError. Neither is related to this change.- Re-ran the canary check with the patch applied:
OPTIONSon all three endpoints → 400 with noACAO; foreign-originPOST /stop,/verify,/scan,/scan-csv→ 403; the sink received nothing. Same-originPOST /stopand no-OriginPOST /stopstill return 200, andGET /still serves the UI.
Happy to open it as a PR if you want it in this shape. If you would rather ship only part 1 and treat the Origin guard separately, say so and I will split it.
One aside: I filed this publicly because SECURITY.md still carries the unedited GitHub template text under "Reporting a Vulnerability", so there is no private channel listed, and #298 was handled in the open. Worth filling in either way.
Activity
rwinkelman commentedon Sep 1, 2026
@DevamShah your
harden-cors-origin-allowlistbranch looks like the right shape (allowlist default + Origin guard for simple POST paths). Please open the PR when ready — happy to review from the security-scanning side.fix: restrict CORS and guard scan endpoints by origin (msoedov#334)
jackspiece commentedon Sep 6, 2026
@DevamShah thanks for checking this further. The simple POST paths are the key reason an allowlist alone does not close #334. I see #337 now includes both the CORS allowlist and an Origin guard, while #341 changes CORS only. I would keep #334 open until the unsafe requests themselves are rejected, including a multipart POST to /scan-csv, and coordinate those PRs before merging overlapping fixes. I have compared the middleware changes, but have not run either branch's full suite.
fix: restrict CORS and guard scan endpoints by origin (msoedov#334)
fix: restrict CORS and guard scan endpoints by origin (msoedov#334)