Skip to content

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

Open

Description

@DevamShah

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 to CORSMiddleware with allow_methods=["*"] and allow_headers=["*"].
  • agentic_security/__main__.py:13 — the server binds to 127.0.0.1:8718 by default.
  • agentic_security/routes/scan.py — POST /verify (:28), POST /scan (:67), POST /stop (:79) and POST /scan-csv (:85) are all state-changing and all unauthenticated. require_auth exists at agentic_security/core/security.py:146 but 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 /scan with Origin: https://evil.example → 200, Access-Control-Allow-Origin: *.
  • POST /stop with that Origin → 200 {"status": "Scan stopped"}.
  • POST /verify with 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 under ACAO: * 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, so fetch() sets no Content-Type.
  • POST /scan-csv — multipart/form-data is 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:

  1. Default to an explicit, configurable allowlist in middleware/cors.py — read from AGENTIC_SECURITY_CORS_ORIGINS or a server.cors_allow_origins setting, defaulting to [] (same-origin only). Warn if an operator explicitly configures "*". Keep allow_credentials=False.
  2. Guard unsafe methods by Origin for the non-preflighted paths: no Origin header → 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 passed
  • python -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 unmodified main by stashing the patch and they reproduce there too: tests/unit/probe_actor/test_fuzzer.py::TestProcessPrompt::test_successful_response_no_refusal fails on 'OneClassSVM' object has no attribute '_effective_probability' (scikit-learn drift against the pickled classifier), and tests/system/test_lib.py::TestLibraryLevel::test_class errors with a FileNotFoundError. Neither is related to this change.
  • Re-ran the canary check with the patch applied: OPTIONS on all three endpoints → 400 with no ACAO; foreign-origin POST /stop, /verify, /scan, /scan-csv → 403; the sink received nothing. Same-origin POST /stop and no-Origin POST /stop still return 200, and GET / 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

  1. rwinkelman commented on Sep 1, 2026

    @rwinkelman
    Contributor

    @DevamShah your harden-cors-origin-allowlist branch 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.

  2. jackspiece commented on Sep 6, 2026

    @jackspiece
    Contributor

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions