-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
[rust-server] Restrict from_headers matches to the intended auth scheme #24607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wing328
merged 5 commits into
OpenAPITools:master
from
twistali:fix/rust-server-untyped-from-headers-auth-bypass
Aug 8, 2026
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ddd272f
[rust-server] Restrict from_headers matches to the intended auth scheme
twistali caa2250
[rust-server] Add auth-scheme precedence tests for context.rs
twistali bfd4aa0
[rust-server] Add a runtime test for a Basic block preceding a Bearer…
twistali 97b9ef8
[rust-server] Drop imports left unused by the scheme-restricted auth …
twistali e4625a7
[rust-server] Allow the unreachable catch-all in the client auth match
twistali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| generatorName: rust-server | ||
| outputDir: samples/server/petstore/rust-server/output/overlapping-auth-schemes | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/rust-server/overlapping-auth-schemes.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/rust-server | ||
| generateAliasAsModel: true | ||
| additionalProperties: | ||
| hideGenerationTimestamp: "true" | ||
| packageName: overlapping-auth-schemes |
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
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
47 changes: 47 additions & 0 deletions
47
modules/openapi-generator/src/test/resources/3_0/rust-server/overlapping-auth-schemes.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| openapi: 3.0.1 | ||
| info: | ||
| title: overlapping auth schemes test | ||
| version: '1.0' | ||
| servers: | ||
| - url: 'http://localhost:8080/' | ||
| paths: | ||
| /ping: | ||
| get: | ||
| operationId: pingGet | ||
| responses: | ||
| '201': | ||
| description: OK | ||
| components: | ||
| # This spec exists to exercise the auth-scheme blocks generated into context.rs when | ||
| # several schemes compete for the same request. See issue #24095. | ||
| # | ||
| # Two properties matter, and no other rust-server fixture has both: | ||
| # | ||
| # * `basicAuth` and `bearerAuth` are HTTP schemes that both read the `Authorization` | ||
| # header, so an unrestricted block for either one also matches the other. This is | ||
| # the `isBasicBasic` / `isBasicBearer` pairing; the petstore fixture only covers | ||
| # `isBasicBasic` alongside `isOAuth`. | ||
| # * `apiKeyAuth` is declared *between* the two HTTP schemes. Blocks are emitted in | ||
| # declaration order and each returns early, so an unrestricted Basic block does not | ||
| # merely pick the wrong scheme for a bearer-credentialed request - it makes the | ||
| # apiKey block below it unreachable, which is an authorization bypass rather than a | ||
| # mislabelling. The interleaving is also what makes the bug observable at runtime: | ||
| # were the two HTTP blocks adjacent, a broken and a fixed generator would both | ||
| # resolve bearer credentials to `AuthData::Bearer` and no request-level test could | ||
| # tell them apart. | ||
| securitySchemes: | ||
| basicAuth: | ||
| scheme: basic | ||
| type: http | ||
| apiKeyAuth: | ||
| type: apiKey | ||
| name: x-api-key | ||
| in: header | ||
| bearerAuth: | ||
| scheme: bearer | ||
| bearerFormat: token | ||
| type: http | ||
| security: | ||
| - basicAuth: [] | ||
| - apiKeyAuth: [] | ||
| - bearerAuth: [] |
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
19 changes: 19 additions & 0 deletions
19
samples/server/petstore/rust-server/output/overlapping-auth-schemes/.cargo/config.toml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| [build] | ||
| rustflags = [ | ||
| "-W", "missing_docs", # detects missing documentation for public members | ||
|
|
||
| "-W", "trivial_casts", # detects trivial casts which could be removed | ||
|
|
||
| "-W", "trivial_numeric_casts", # detects trivial casts of numeric types which could be removed | ||
|
|
||
| # unsafe is used in `TokioIo` bridging code copied from `hyper`. | ||
| # "-W", "unsafe_code", # usage of `unsafe` code | ||
|
|
||
| "-W", "unused_qualifications", # detects unnecessarily qualified names | ||
|
|
||
| "-W", "unused_extern_crates", # extern crates that are never used | ||
|
|
||
| "-W", "unused_import_braces", # unnecessary braces around an imported item | ||
|
|
||
| "-D", "warnings", # all warnings should be denied | ||
| ] |
2 changes: 2 additions & 0 deletions
2
samples/server/petstore/rust-server/output/overlapping-auth-schemes/.gitignore
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| target | ||
| Cargo.lock |
23 changes: 23 additions & 0 deletions
23
...les/server/petstore/rust-server/output/overlapping-auth-schemes/.openapi-generator-ignore
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # OpenAPI Generator Ignore | ||
| # Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
|
||
| # Use this file to prevent files from being overwritten by the generator. | ||
| # The patterns follow closely to .gitignore or .dockerignore. | ||
|
|
||
| # As an example, the C# client generator defines ApiClient.cs. | ||
| # You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
| #ApiClient.cs | ||
|
|
||
| # You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
| #foo/*/qux | ||
| # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
|
||
| # You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
| #foo/**/qux | ||
| # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
|
||
| # You can also negate patterns with an exclamation (!). | ||
| # For example, you can ignore all files in a docs folder with the file extension .md: | ||
| #docs/*.md | ||
| # Then explicitly reverse the ignore rule for a single file: | ||
| #!docs/README.md |
23 changes: 23 additions & 0 deletions
23
samples/server/petstore/rust-server/output/overlapping-auth-schemes/.openapi-generator/FILES
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| .cargo/config.toml | ||
| .gitignore | ||
| Cargo.toml | ||
| README.md | ||
| api/openapi.yaml | ||
| bin/cli.rs | ||
| docs/default_api.md | ||
| examples/ca.pem | ||
| examples/client/client_auth.rs | ||
| examples/client/main.rs | ||
| examples/server-chain.pem | ||
| examples/server-key.pem | ||
| examples/server/main.rs | ||
| examples/server/server.rs | ||
| examples/server/server_auth.rs | ||
| src/auth.rs | ||
| src/client/mod.rs | ||
| src/context.rs | ||
| src/header.rs | ||
| src/lib.rs | ||
| src/models.rs | ||
| src/server/mod.rs | ||
| src/server/server_auth.rs |
1 change: 1 addition & 0 deletions
1
...es/server/petstore/rust-server/output/overlapping-auth-schemes/.openapi-generator/VERSION
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 7.25.0-SNAPSHOT |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.