Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds configurable CORS support: the root crate gains the ChangesCORS Support for Proxy and Admin Routers
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
src/proxy/mod.rs (1)
26-27: 💤 Low value
#[allow(dead_code)]onconfigis now stale.
state.configis accessed at Line 86 after this PR, so the suppression attribute can be dropped and the compiler will naturally validate usage.🔧 Suggested change
#[derive(Clone)] pub struct AppState { - #[allow(dead_code)] config: Arc<Config>,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/proxy/mod.rs` around lines 26 - 27, Remove the now-stale #[allow(dead_code)] attribute on the config field: open the struct containing "config: Arc<Config>" (the same struct whose instance is referenced as state.config) and delete the #[allow(dead_code)] line so the compiler will validate usage normally; no other code changes are required since state.config is accessed elsewhere in the file.src/config/types.rs (1)
308-325: ⚡ Quick winAdd a test case for the wildcard + credentials combination.
The existing tests cover a valid multi-field config and an invalid method, but miss the
"*"origin +allow_credentials: truecase — the exact combination that causes the panic. Without the validation guard from above, this test would itself panic rather than assertis_err().🧪 Suggested test
+ #[test] + fn to_cors_layer_rejects_wildcard_with_credentials() { + let cors = ServerCommonCors { + enabled: true, + allowed_origins: Some(vec!["*".into()]), + allow_credentials: Some(true), + ..Default::default() + }; + + let result = cors.to_cors_layer(); + assert!(result.is_err()); + assert!( + result + .err() + .map(|e| e.to_string().contains("wildcard origin")) + .unwrap_or(false) + ); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/config/types.rs` around lines 308 - 325, Add a unit test that verifies ServerCommonCors::to_cors_layer rejects the combination of origin "*" with allow_credentials set to true (the case that previously panicked); create a new test (e.g., to_cors_layer_rejects_wildcard_with_credentials) that constructs ServerCommonCors with allowed_origins = Some(vec!["*".into()]) and allow_credentials = Some(true), calls to_cors_layer(), and asserts the result is Err (assert!(result.is_err())) and that the error message contains a clear token (e.g., "wildcard" or "credentials") to ensure the guard prevents a panic rather than letting the test crash.Cargo.toml (1)
140-140: 💤 Low valueConsider adding
default-features = falsefor consistency with other tower crates.The sibling
towerentry on Line 132 usesdefault-features = false, features = ["util"]. Applying the same pattern totower-httpensures only the explicitly requestedcorsfeature surface is compiled in.🔧 Suggested change
-tower-http = { version = "0.6.10", features = ["cors"] } +tower-http = { version = "0.6.10", default-features = false, features = ["cors"] }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Cargo.toml` at line 140, Update the tower-http dependency declaration to mirror the sibling tower entry by disabling default features: change the tower-http dependency to include default-features = false while keeping features = ["cors"] so only the cors feature is enabled; locate the existing tower-http = { version = "0.6.10", features = ["cors"] } line and add default-features = false to that table.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@config.yaml`:
- Around line 23-29: Update the example CORS config to avoid the wildcard-origin
+ credentials combination that panics: change cors.allowed_origins from ["*"] to
a specific origin (e.g., ["http://localhost:3000"]) if cors.allow_credentials is
true, or set cors.allow_credentials to false if you want to keep a wildcard;
ensure this matches the expectations in the to_cors_layer() code that constructs
the tower-http CORS middleware (so cors.allowed_origins and
cors.allow_credentials are consistent and do not trigger the Any +
allow_credentials panic).
In `@src/config/types.rs`:
- Around line 62-103: The to_cors_layer implementation on ServerCommonCors
currently sets allow_credentials before processing allowed_origins which causes
tower-http to panic when AllowOrigin::any() is later applied; change the logic
to first parse allowed_origins (using Self::parse_cors_values and checking for
"*" / AllowOrigin::any()) and if the parsed origins indicate a wildcard and
self.allow_credentials.unwrap_or(false) is true, return an Err explaining the
invalid combination, otherwise build the CorsLayer with the parsed AllowOrigin
and only then apply allow_credentials (or apply allow_credentials false) so that
AllowOrigin::any() is never combined with allow_credentials(true); update
references in the flow around allowed_origins, allow_credentials,
AllowOrigin::any, and to_cors_layer accordingly.
---
Nitpick comments:
In `@Cargo.toml`:
- Line 140: Update the tower-http dependency declaration to mirror the sibling
tower entry by disabling default features: change the tower-http dependency to
include default-features = false while keeping features = ["cors"] so only the
cors feature is enabled; locate the existing tower-http = { version = "0.6.10",
features = ["cors"] } line and add default-features = false to that table.
In `@src/config/types.rs`:
- Around line 308-325: Add a unit test that verifies
ServerCommonCors::to_cors_layer rejects the combination of origin "*" with
allow_credentials set to true (the case that previously panicked); create a new
test (e.g., to_cors_layer_rejects_wildcard_with_credentials) that constructs
ServerCommonCors with allowed_origins = Some(vec!["*".into()]) and
allow_credentials = Some(true), calls to_cors_layer(), and asserts the result is
Err (assert!(result.is_err())) and that the error message contains a clear token
(e.g., "wildcard" or "credentials") to ensure the guard prevents a panic rather
than letting the test crash.
In `@src/proxy/mod.rs`:
- Around line 26-27: Remove the now-stale #[allow(dead_code)] attribute on the
config field: open the struct containing "config: Arc<Config>" (the same struct
whose instance is referenced as state.config) and delete the #[allow(dead_code)]
line so the compiler will validate usage normally; no other code changes are
required since state.config is accessed elsewhere in the file.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 12774070-de7d-4b9d-aa4d-3c507a316234
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (6)
Cargo.tomlconfig.yamlsrc/admin/mod.rssrc/config/types.rssrc/lib.rssrc/proxy/mod.rs
Summary by CodeRabbit
New Features
Improvements
Tests