Skip to content

fix(common-server): race-condition and security improvements#272

Merged
ron96g merged 4 commits into
mainfrom
fix/common-server-security
Mar 11, 2026
Merged

fix(common-server): race-condition and security improvements#272
ron96g merged 4 commits into
mainfrom
fix/common-server-security

Conversation

@ron96g
Copy link
Copy Markdown
Member

@ron96g 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

ron96g added 2 commits March 11, 2026 15:20
…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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Unstructured on update to avoid mutating shared informer/cache objects.
  • Add PrefixFromContext helper 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.

Comment thread common-server/pkg/store/inmemory/inmemory_store.go Outdated
Comment thread common-server/pkg/server/middleware/security/check_access.go Outdated
stefan-ctrl
stefan-ctrl previously approved these changes Mar 11, 2026
Copy link
Copy Markdown
Member

@stefan-ctrl stefan-ctrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM & had have discussed this PR on other platforms

@ron96g ron96g added bug Something isn't working SECURITY labels Mar 11, 2026
@ron96g ron96g merged commit 9d08e02 into main Mar 11, 2026
117 checks passed
@ron96g ron96g deleted the fix/common-server-security branch March 11, 2026 14:42
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working SECURITY

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants