You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
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.
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.
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
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
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.
Clarify wildcard CORS exposure for credentialed requests
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.
…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
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.
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
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.
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
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
githubsecuritylab/audit/rust/permissive-cors(CWE-942), an audit query for Rust that reports a CORS policy, or anAccess-Control-Allow-Originheader, 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(), orAllowOrigin::mirror_request()withallow_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
allow_any_origin()andCors::permissive().CorsLayer::permissive(),CorsLayer::very_permissive(), andallow_origin(...)givenAny,"*"(parsed, or throughHeaderValue::from_static),AllowOrigin::any()orAllowOrigin::mirror_request().AllowedOrigins::all().AccessControlAllowOrigin::Any.Access-Control-Allow-Origin(a string, orACCESS_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
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.Notes
@precision very-low, tagssecurity,experimental,audit,external/cwe/cwe-942.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.