Repository navigation
Description
Target Language
python
Query Name (Optional)
CorsCspSecurityHeaders
Query Type
Security
Query Description
AI Scan reported 4 medium and low-severity CWE-693, CWE-942 (cors csp security headers) finding(s) in Python public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: query-absent. Existing queries considered: none.
Why CodeQL appears to have missed these (unverified until reproduced with a test database):
- CORSMiddleware with unanchored allow_origin_regex plus allow_credentials=True; no Python CORS misconfiguration query (JS has one).
- Access-Control-Allow-Origin: * set on responses; no Python CORS misconfiguration query.
- Header value containing unsafe-inline in CSP set in a Flask after_request could be matched syntactically.
- Setting Access-Control-Allow-Origin to "*" in Flask/Django responses has no Python query (JS has cors-misconfiguration).
Linked findings (gap-key: python/query-create/cors-csp-security-headers)
| Repo | CWE | Severity | AI scan alert | Summary |
|---|---|---|---|---|
| Damn-Vulnerable-RESTaurant-API-Game | CWE-942 | medium | https://github.com/codeql-forks-felickz/Damn-Vulnerable-RESTaurant-API-Game/security/code-scanning/26 | allow_origin_regex=".*.(restaurant.com/deliveryservice.com)" combined with allow_credentials=True and allow_methods=["*"]. The regex is not anchored to a sub-domain boundary and the dots are unescaped, so origins such as https://evilrestaurant.com, https://xrestaurant_com or https://attackerXrestaurantYcom match. Any such attacker-controlled origin can issue credentialed cross-origin requests to the API and read the responses. The pattern should be anchored and escaped (e.g. ^https://([a-z0-9-]+\.)?(restaurant\.com/deliveryservice\.com)$). |
| flask-webgoat | CWE-942 | medium | https://github.com/codeql-forks-felickz/flask-webgoat/security/code-scanning/22 | Every response is given Access-Control-Allow-Origin: *, allowing scripts on any website to read responses from the application's unauthenticated endpoints. This is particularly dangerous for deployments reachable only from a victim's browser or internal network, because a malicious origin can invoke and read results from sensitive endpoints such as process search. |
| shiftleft-python-demo | CWE-693 | low | https://github.com/codeql-forks-felickz/shiftleft-python-demo/security/code-scanning/22 | The global CSP includes 'unsafe-inline' in script-src. This negates CSP's protection against injected inline scripts and would allow an HTML injection flaw to execute JavaScript rather than being contained; nonce- or hash-based authorization should be used instead. |
| shiftleft-python-demo | CWE-942 | low | https://github.com/codeql-forks-felickz/shiftleft-python-demo/security/code-scanning/21 | Every response is assigned Access-Control-Allow-Origin: *. This allows scripts hosted on any attacker-controlled origin to read the application's unauthenticated responses, including user-search results and process-search output, and unnecessarily expands the exposure of an internal or locally hosted deployment. CORS should be limited to explicitly trusted origins and endpoints. |
Findings come from AI Scan on public synthetic apps. Hypotheses above are unverified until reproduced with a test database. Verify first whether CodeQL already covers a case (for example via a different query or threat model) before adding code.
Handling decision
- Type: Query Create
- Decision: Create a new CodeQL query. No existing query covers these patterns (most findings are gap type
query-absentormissing-query). Because coverage of lower-severity patterns can be heuristic, target Community Packs unless precision is shown to be high enough for github/codeql. - Recommended actions across the findings: write-new-query (4)
Patterns in this gap
permissive-cors-config(2 findings), for example Damn-Vulnerable-RESTaurant-API-Game app/init_app.pyweak-security-headers(1 finding), for example shiftleft-python-demo run.pypermissive-cors-python(1 finding), for example shiftleft-python-demo run.py
Finding details
Each finding below has its own context so the agent can work from this issue alone.
1. Damn-Vulnerable-RESTaurant-API-Game app/init_app.py:22 (CWE-942, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/Damn-Vulnerable-RESTaurant-API-Game/security/code-scanning/26
- AI Scan message:
allow_origin_regex=".*.(restaurant.com|deliveryservice.com)"combined withallow_credentials=Trueandallow_methods=["*"]. The regex is not anchored to a sub-domain boundary and the dots are unescaped, so origins such ashttps://evilrestaurant.com,https://xrestaurant_comorhttps://attackerXrestaurantYcommatch. Any such attacker-controlled origin can issue credentialed cross-origin requests to the API and read the responses. The pattern should be anchored and escaped (e.g.^https://([a-z0-9-]+\.)?(restaurant\.com|deliveryservice\.com)$). - Why CodeQL appears to miss it: query-absent: CORSMiddleware with unanchored allow_origin_regex plus allow_credentials=True; no Python CORS misconfiguration query (JS has one).
- Recommended action from the comparison: write-new-query (classification confidence: medium)
2. flask-webgoat run.py:8 (CWE-942, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/flask-webgoat/security/code-scanning/22
- AI Scan message: Every response is given
Access-Control-Allow-Origin: *, allowing scripts on any website to read responses from the application's unauthenticated endpoints. This is particularly dangerous for deployments reachable only from a victim's browser or internal network, because a malicious origin can invoke and read results from sensitive endpoints such as process search. - Why CodeQL appears to miss it: query-absent: Access-Control-Allow-Origin: * set on responses; no Python CORS misconfiguration query.
- Recommended action from the comparison: write-new-query (classification confidence: medium)
3. shiftleft-python-demo run.py:10 (CWE-693, low)
- AI Scan alert: https://github.com/codeql-forks-felickz/shiftleft-python-demo/security/code-scanning/22
- AI Scan message: The global CSP includes
'unsafe-inline'inscript-src. This negates CSP's protection against injected inline scripts and would allow an HTML injection flaw to execute JavaScript rather than being contained; nonce- or hash-based authorization should be used instead. - Context for the agent: In shiftleft-python-demo run.py:10: The global CSP includes
'unsafe-inline'inscript-src. This negates CSP's protection against injected inline scripts and would allow an HTML injection flaw to execute JavaScript rather than being contained; nonce- or hash-based authorization should be used Please re-validate whether CodeQL (existing queries none) misses this and what source/sink/model or query would be needed. - Why CodeQL appears to miss it: query-absent: Header value containing unsafe-inline in CSP set in a Flask after_request could be matched syntactically.
- Recommended action from the comparison: write-new-query (classification confidence: medium)
4. shiftleft-python-demo run.py:8 (CWE-942, low)
- AI Scan alert: https://github.com/codeql-forks-felickz/shiftleft-python-demo/security/code-scanning/21
- AI Scan message: Every response is assigned
Access-Control-Allow-Origin: *. This allows scripts hosted on any attacker-controlled origin to read the application's unauthenticated responses, including user-search results and process-search output, and unnecessarily expands the exposure of an internal or locally hosted deployment. CORS should be limited to explicitly trusted origins and endpoints. - Context for the agent: In shiftleft-python-demo run.py:8: Every response is assigned
Access-Control-Allow-Origin: *. This allows scripts hosted on any attacker-controlled origin to read the application's unauthenticated responses, including user-search results and process-search output, and unnecessarily expands th Please re-validate whether CodeQL (existing queries none) misses this and what source/sink/model or query would be needed. - Why CodeQL appears to miss it: query-absent: Setting Access-Control-Allow-Origin to "*" in Flask/Django responses has no Python query (JS has cors-misconfiguration).
- Recommended action from the comparison: write-new-query (classification confidence: high)
Expected Severity
Medium
Code Examples
See the linked alerts above for the vulnerable pattern; reduce each to a minimal test case with a safe counterpart that should not alert.
CWE/CVE Reference (Optional)
CWE-693, CWE-942
References (Optional)
https://cwe.mitre.org/data/definitions/693.html
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
felickz commentedon Nov 3, 2026
Upstream triage
precision:lowAudit-grade or weak signal. Community Packs, always tags:experimental.
tags:experimental
Goes to Community Packs: performance, false-positive or synthetic-only concerns.
Community Packs, experimental. Recommended for the Community Packs repository, not
github/codeql. The issue is labeledtags:experimentalfor this.Linked pull request: #332
Why. One query bundling three checks. Access-Control-Allow-Origin '*' and CSP 'unsafe-inline' are widely intentional settings, so those branches are audit grade, and the origin-regex check relies on regexp heuristics that review found over- and under-matching. The allow_origins star with credentials branch duplicates the upstream experimental py/cors-misconfiguration-with-credentials. Community Packs fits, ideally as per-check queries.
mediumin the pull request). One query bundles three checks. ACAO '*' and CSP 'unsafe-inline' on constant header writes are audit-grade, often intentional settings. The origin-regex check uses regexp heuristics (unescaped dot, leading wildcard) that review found over- and under-matching.Concerns, overlap and next steps
False-positive concerns
Heuristics used
What an upstream change would look like. Community Packs: python/src/<category>/ split into per-check queries (ACAO header, CSP, credentialed origin regex) with tests under python/test. The credentialed allow_origin_regex check could instead extend the upstream experimental CORS query.
Before opening an upstream pull request
Split note. The credentialed allow_origin_regex branch is a candidate extension of the upstream experimental CORS query; the ACAO '*' and CSP branches are audit grade. The single query is rated at its lowest branch.
This is a recommendation only. A human reviews it before any pull request is opened against
github/codeqlor the Community Packs repository.