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