Skip to content

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

Merged
felickz merged 4 commits into
mainfrom
rust/permissive-cors
Nov 23, 2026
Merged

felickz merged 4 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, directly or held in a local variable) set to "*" with an insert call or a name and value tuple.

Not reported: a policy with an explicit list of origins, a policy that is built from configuration at run time, and a value that is changed before it is used (for example "*".replace("*", "https://app.example.com")). A wildcard is followed only through parsing, unwrapping and conversions that keep the value, and through constructors of header values.

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 1 second 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

…lp text

Follow the receiver of a method call only for methods that keep the value
(parse, unwrap, expect, to_string, to_owned, into, try_into, clone, as_str,
as_ref, as_bytes, to_vec, ok, map_err), so a wildcard that is changed with
replace before it is used is not reported. Add regressions for an origin and a
raw header value.

Correct the query help: a browser does not honor a wildcard origin for requests
that carry credentials. A wildcard exposes data that is protected only by the
location of the client, and session-protected data is exposed by a reflected
origin together with Access-Control-Allow-Credentials: true.

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 23, 2026 15:23
@felickz

felickz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the second pass. Both findings in the review body were valid, and both are fixed in 6fcfffa.

  • Value-changing methods: good_wildcard_replaced_by_exact_origin and good_raw_header_wildcard_replaced were reported (24 alerts before, 22 now). A method receiver is followed only for methods that keep the value (parse, unwrap, expect, to_string, to_owned, into, try_into, clone, as_str, as_ref, as_bytes, to_vec, ok, map_err).
  • Help text: agreed. The help now says that a browser does not honor a wildcard for requests with credentials, that a wildcard exposes data that is protected only by where the client is, and that session-protected data is exposed by a reflected origin together with Access-Control-Allow-Credentials: true, as the pull request description does.

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 misses wildcard CORS headers when the header name is stored in a local binding, requiring local data-flow tracking for header names and positive and reassignment-negative regression tests.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Resolve local aliases when matching header names

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

A local binding hides an otherwise constant header name: let name = header::ACCESS_CONTROL_ALLOW_ORIGIN; headers.insert(name, HeaderValue::from_static("*")); does not match any branch here. The response still emits a wildcard CORS header, but the query misses it because, unlike origin values, header names are not followed through reaching assignments. Please follow local data flow for header names too, with positive and reassignment-negative regression cases.

Review effort: Balanced

The header name of a raw Access-Control-Allow-Origin header was recognized
only when it was written in the call. A name that is held in a local
variable, as in `let name = ACCESS_CONTROL_ALLOW_ORIGIN;`, was missed.
Follow the variable to the value that reaches it, as is already done for the
header value, so that a later assignment replaces an earlier one.

Add regressions for a name from a constant and from a constructor, and for
a name that is replaced before it is used.

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 23, 2026 17:25
@felickz

felickz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the third pass. The finding in the review body was valid and is fixed in 51793cf with a failing test first.

let name = header::ACCESS_CONTROL_ALLOW_ORIGIN; headers.insert(name, HeaderValue::from_static("*")); (bad_raw_header_name_alias) and the same with a name from HeaderName::from_static (bad_raw_header_name_constructor_alias) were not reported. The header name now follows the local variable to the value that reaches it, with the same predicate that the origin value already used, so a later assignment replaces an earlier one: good_raw_header_name_alias_reassigned (the name is replaced by ACCESS_CONTROL_ALLOW_METHODS before the call) is not reported.

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

Human assessment is needed because the CORS query can miss equivalent wildcard and header encodings while flagging permissive settings that are later replaced by restricted origins.

No open issues 🎉

Review effort: Balanced

@felickz
felickz marked this pull request as ready for review November 23, 2026 22:29

@felickz felickz left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Audit for now..

@felickz
felickz merged commit d149ca5 into main Nov 23, 2026
31 checks passed
@felickz
felickz deleted the rust/permissive-cors branch November 23, 2026 22:30
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