fix: bug where query clone params are assigned to claim params#2184
fix: bug where query clone params are assigned to claim params#2184
Conversation
WalkthroughFixes Context.Clone() to correctly copy URL.Query into the cloned context. Adds comprehensive tests covering cloning behavior, including handling of nil/empty maps and slices, separation of mutable state, and verification that modifying the clone does not affect the original. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes ✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Router image scan passed✅ No security vulnerabilities found in image: |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
router/internal/expr/expr.go (1)
40-47: Clarify cloning semantics: not a true deep copy.Clone duplicates top-level maps/slices but intentionally does not deep-copy nested values (e.g., map/slice entries inside Claims). The comment “deep copy” is misleading.
Apply:
-// Clone creates a deep copy of the Context +// Clone returns a copy of Context with fresh top-level maps/slices (Auth.Claims, Auth.Scopes, URL.Query). +// Nested reference values inside Claims are not deep-copied by design. Nil inputs become non-nil, empty. func (copyCtx Context) Clone() *Context {router/internal/expr/expr_test.go (2)
60-80: Good regression for URL.Query cloning; optional extra assertion.Consider also asserting map instance inequality for consistency with the earlier pointer-based checks.
clone := exprContext.Clone() require.Equal(t, exprContext.Request.URL.Query, clone.Request.URL.Query) // Verify modifying clone doesn't affect original clone.Request.URL.Query["new"] = "value2" require.NotEqual(t, exprContext.Request.URL.Query, clone.Request.URL.Query) + // Also ensure different map instances + require.NotEqual(t, + reflect.ValueOf(exprContext.Request.URL.Query).Pointer(), + reflect.ValueOf(clone.Request.URL.Query).Pointer(), + )
132-178: Make shallow-copy intent explicit by mutating nested values in the test.You already assert pointer equality for nested slice/map in Claims. Add a quick mutation to document the shared-reference behavior.
sliceFromOriginal := exprContext.Request.Auth.Claims["slice"].([]string) sliceFromClone := clone.Request.Auth.Claims["slice"].([]string) require.Equal(t, reflect.ValueOf(sliceFromOriginal).Pointer(), reflect.ValueOf(sliceFromClone).Pointer()) mapFromOriginal := exprContext.Request.Auth.Claims["map"].(map[string]string) mapFromClone := clone.Request.Auth.Claims["map"].(map[string]string) require.Equal(t, reflect.ValueOf(mapFromOriginal).Pointer(), reflect.ValueOf(mapFromClone).Pointer()) + + // Mutate via clone to make the contract explicit + sliceFromClone[0] = "x" + mapFromClone["key"] = "changed" + require.Equal(t, "x", sliceFromOriginal[0]) + require.Equal(t, "changed", mapFromOriginal["key"])
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
router/internal/expr/expr.go(1 hunks)router/internal/expr/expr_test.go(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
router/internal/expr/expr_test.go (1)
router/internal/expr/expr.go (4)
Context(34-38)Request(65-74)RequestURL(102-112)RequestAuth(118-123)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: build-router
- GitHub Check: integration_test (./. ./fuzzquery ./lifecycle ./modules)
- GitHub Check: integration_test (./events)
- GitHub Check: integration_test (./telemetry)
- GitHub Check: image_scan (nonroot)
- GitHub Check: image_scan
- GitHub Check: build_push_image (nonroot)
- GitHub Check: build_push_image
- GitHub Check: build_test
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (5)
router/internal/expr/expr.go (1)
56-56: Bug fix is correct: query values now copied into the query map.This resolves the misassignment to claims during cloning and restores independent URL.Query state in clones.
router/internal/expr/expr_test.go (4)
6-7: Import change LGTM.
82-105: Empty maps/slices behavior covered well.
107-130: Nil-to-empty contract verified cleanly.
180-209: Separation of top-level mutable state verified.
Summary by CodeRabbit
Bug Fixes
Tests
Checklist