Skip to content

[New Audit Query - githubsecuritylab/audit/rust/permissive-cors] - detect Rust permissive CORS policies - #261

Draft
felickz wants to merge 2 commits into
mainfrom
rust/permissive-cors
Draft

felickz wants to merge 2 commits into
mainfrom
rust/permissive-cors

Conversation

@felickz

@felickz felickz commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds githubsecuritylab/audit/rust/permissive-cors (CWE-942), an audit query for Rust that reports a CORS policy, or an Access-Control-Allow-Origin header, that allows any origin.

Why

A wildcard origin lets every website read the responses of a service from a visitor's browser. That is harmless for public data, but it exposes anything else that the service returns to requests without credentials, such as a service on localhost or on a private network. A browser does not honor a wildcard for requests that carry credentials, but a policy that reflects the request origin and allows credentials (CorsLayer::very_permissive(), or AllowOrigin::mirror_request() with allow_credentials(true)) exposes data that a session protects. A query cannot tell public data from sensitive data, so this is an audit query: its message asks for a review and does not claim a vulnerability.

What is reported

  • warp and actix-cors: allow_any_origin() and Cors::permissive().
  • tower-http: CorsLayer::permissive(), CorsLayer::very_permissive(), and allow_origin(...) given Any, "*" (parsed, or through HeaderValue::from_static), AllowOrigin::any() or AllowOrigin::mirror_request().
  • rocket_cors: AllowedOrigins::all().
  • Iron: AccessControlAllowOrigin::Any.
  • A raw header: Access-Control-Allow-Origin (a string, or ACCESS_CONTROL_ALLOW_ORIGIN) set to "*" with an insert call or a name and value tuple.

Not reported: a policy with an explicit list of origins, and a policy that is built from configuration at run time.

Evidence

  • Tests cover each form above and a safe counterpart for each. They pass with the pinned CLI (codeql test run), and the query compiles with --warnings=error. The fixtures do not fetch the third party crates, so the query recognizes the shape of the calls and not resolved call targets.
  • On a random sample of 11 public Rust repositories (1,521 source files, plus the crates they depend on) the query reports 0 alerts, so there is no real finding from this sample yet.
  • Cost: the query's own predicates take about 0.3 seconds on the largest database (about 19,000 Rust files, almost all of them dependency sources). Most of a whole run is the shared library, which other Rust queries need as well.

Notes

  • Metadata: @precision very-low, tags security, experimental, audit, external/cwe/cwe-942.
  • Audit queries are not part of rust.qls, and there is no Rust audit suite yet, so the query runs when it is selected by path or from a custom suite.
  • The pack version is not changed here. It changes when a release is cut.

Add githubsecuritylab/audit/rust/permissive-cors (CWE-942). It reports a CORS
policy or an Access-Control-Allow-Origin header that allows any origin, for
warp, actix-cors, tower-http, rocket_cors, Iron and raw headers. It is an audit
query: a wildcard origin is often intended for public data, so the message asks
for a review, and the query is not selected by the default Rust suite.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752
Copilot AI balanced review requested due to automatic review settings November 22, 2026 03:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two active findings show false-positive risks from tracing unrelated call arguments as wildcard origins and treating read-only helpers as response-header writes.

2 open issues
What changed in this PR

Adds a Rust CWE-942 audit query to flag permissive CORS policies and wildcard response headers for manual review, rather than claiming a vulnerability.

Changes:

  • Recognizes permissive configurations across several Rust web frameworks and raw header patterns.
  • Adds query help with permissive and restricted-origin examples.
  • Adds positive and negative fixtures with 22 expected alerts.
File Description
rust/​test/​audit/​CWE-942/​PermissiveCors/​PermissiveCors.qlref Connects the tests to the audit query.
rust/​test/​audit/​CWE-942/​PermissiveCors/​PermissiveCors.expected Records 22 expected alerts.
rust/​test/​audit/​CWE-942/​PermissiveCors/​main.rs Covers framework policies, raw headers, and safe counterparts.
rust/​src/​audit/​CWE-942/​PermissiveCorsGood.rs Demonstrates a restricted origin.
rust/​src/​audit/​CWE-942/​PermissiveCorsBad.rs Demonstrates a wildcard origin.
rust/​src/​audit/​CWE-942/​PermissiveCors.ql Implements permissive CORS detection and audit messages.
rust/​src/​audit/​CWE-942/​PermissiveCors.qhelp Explains the query, risks, and remediation.

Review effort: Balanced

Follow call arguments only for constructors of header values, so a wildcard
that is only the message of expect no longer makes an exact origin look like
a wildcard. Accept a header name and value pair only for calls that set a
header, so a read-only helper that receives them is not reported.

Add a regression for each.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752
Copilot AI balanced review requested due to automatic review settings November 22, 2026 03:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The query falsely flags restricted origins by traversing value-changing methods such as replace, while the help text overstates wildcard CORS exposure for credentialed responses.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Avoid tracing origins through value-changing receiver methods

rust/​src/​audit/​CWE-942/​PermissiveCors.ql:48

Following every method receiver reports CorsLayer::new().allow_origin("*".replace("*", "https://trusted.example.com").parse::<HeaderValue>().unwrap()), although the resulting origin is restricted. The same false positive affects raw-header values because traversal reaches the original "*" through value-changing methods. Restrict receiver traversal to recognized value-preserving wrappers and conversions, and add a negative regression case for replace.

Low severity Clarify wildcard CORS exposure for credentialed requests

rust/​src/​audit/​CWE-942/​PermissiveCors.qhelp:18

This overstates what a wildcard origin exposes: browsers reject Access-Control-Allow-Origin: * for credentialed requests, so it does not by itself expose cookie-authenticated responses. Distinguish sensitive data returned without credentials from session-protected data exposed by origin reflection combined with Access-Control-Allow-Credentials: true, as the PR description does. That distinction is important when users assess these audit alerts.

2 resolved since last review

Review effort: Balanced

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.

2 participants