🐛 bug: prevent SharedState namespace key collisions#4274
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughClarifies IsFromLocal() docs to state loopback-IP detection and changes SharedState.storageKey to hex-encode user keys before prefixing; adds a test ensuring namespacing prevents collisions for overlapping app-name prefixes. ChangesInterface Documentation Updates
Shared State Key Namespacing Fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.1)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the documentation for IsFromLocal to clarify loopback IP usage and modifies the SharedState key generation to use hex encoding, preventing potential key collisions between applications with overlapping prefixes. A new test case validates this namespacing logic. Feedback suggests removing a redundant utils.CopyString call in storageKey to avoid unnecessary allocations, as string concatenation and hex encoding already produce fresh strings.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR restores unambiguous SharedState storage-key derivation to prevent cross-namespace key collisions when multiple Fiber apps share the same backend storage.
Changes:
- Reintroduce hex-encoding of caller-supplied SharedState keys when deriving the backend storage key.
- Add a regression test covering overlapping default prefixes (e.g.,
appvsapp-one) to ensure isolation. - Regenerate interface files to update
IsFromLocalcomment wording.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| shared_state.go | Restores hex-encoding when deriving the storage key to prevent prefix/key ambiguity collisions. |
| shared_state_test.go | Adds a regression test validating isolation between overlapping default prefixes. |
| req_interface_gen.go | Regenerated comment text for IsFromLocal to clarify loopback semantics. |
| ctx_interface_gen.go | Regenerated comment text for IsFromLocal to clarify loopback semantics. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4274 +/- ##
=======================================
Coverage 91.21% 91.21%
=======================================
Files 130 130
Lines 12760 12760
=======================================
Hits 11639 11639
Misses 709 709
Partials 412 412
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot Error: shared_state.go:416:1: File is not properly formatted (gofmt) |
Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/60c247c0-fd61-493b-8cda-5337dbb8023f Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Motivation
Description
SharedState.storageKey, now returningutils.CopyString(s.prefix + hex.EncodeToString(utils.UnsafeBytes(key)))to preserve a clear namespace delimiter.TestSharedState_KeyNamespacingWithOverlappingPrefixesthat reproduces the overlapping-prefix scenario (appvsapp-one) and verifies namespaces remain isolated.make generatewhich updatedctx_interface_gen.goandreq_interface_gen.goas part of the repository generation workflow.