fix(common-server): race-condition and security improvements#272
Merged
Conversation
Member
ron96g
commented
Mar 11, 2026
- fix(common-server): fix malformed datastore prefix and expose PrefixFromContext
- fix(common-server): deep-copy object in OnUpdate to prevent data race
…romContext
The team-level prefix template (e.g. "{{ .B.Environment }}--{{ .B.Group }}--{{ .B.Team }}--")
produced a malformed prefix like "test--group--team--/" when the DB separator "/" was appended.
Strip the trailing "--" before adding "/" so the prefix reads "test--group--team/" instead.
Also add an exported PrefixFromContext helper that retrieves the prefix
set by the check_access middleware from the request context, along with
table-driven tests covering present, absent, and wrong-type values.
OnUpdate mutates the unstructured object via SanitizeObject before serializing it. Without a deep copy, this modifies the caller's original object, causing a data race when the informer or other goroutines still reference it.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a datastore-prefix formatting bug in the security middleware and reduces data-race risk by copying updated objects before mutation/serialization, while also exposing a helper to retrieve the computed prefix from request context.
Changes:
- Adjust prefix normalization for team client type to avoid malformed
--/datastore prefixes. - Deep-copy
unstructured.Unstructuredon update to avoid mutating shared informer/cache objects. - Add
PrefixFromContexthelper and expand middleware tests accordingly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| common-server/pkg/store/inmemory/inmemory_store.go | Adds a deep copy in OnUpdate to prevent races caused by mutating shared unstructured objects. |
| common-server/pkg/server/middleware/security/check_access.go | Fixes team-prefix formatting and adds PrefixFromContext helper. |
| common-server/pkg/server/middleware/security/check_access_test.go | Updates expected prefix strings and adds unit tests for PrefixFromContext. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
stefan-ctrl
previously approved these changes
Mar 11, 2026
Member
stefan-ctrl
left a comment
There was a problem hiding this comment.
LGTM & had have discussed this PR on other platforms
stefan-ctrl
approved these changes
Mar 11, 2026
dtit-semantic-release Bot
pushed a commit
that referenced
this pull request
Mar 18, 2026
# [0.18.0](v0.17.0...v0.18.0) (2026-03-18) ### Bug Fixes * **common-server:** race-condition and security improvements ([#272](#272)) ([9d08e02](9d08e02)) * **gateway:** add deny-all sentinel to ACL plugin when no consumers exist ([#277](#277)) ([0dd6017](0dd6017)) ### Features * **common-libs:** improve error handling, add feature flags, and fix logger type ([#260](#260)) ([03165a0](03165a0)) * **common-server:** unify latency format in logs ([#267](#267)) ([5fbb19e](5fbb19e)) * **gateway:** add buffering config, dynamic upstream, access control fix, and secret-manager integration ([#259](#259)) ([719c58f](719c58f)) * introduce event-driven communication to the control plane ([#265](#265)) ([f1ed1f5](f1ed1f5)) * **rover-ctl:** add EventSpec handler, env placeholder substitution, and HTTP client improvements ([#264](#264)) ([f15e0f7](f15e0f7)) * **rover-ctl:** support for get-info-many cmd ([#246](#246)) ([1d9f194](1d9f194)) * **secret-manager:** add write strategy support and improve caching ([#263](#263)) ([3f311bf](3f311bf))
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.