Skip to content

Prevent commandstore cache poisoning when backend Get fails after UpdateStatus - #7231

Open
vanshika2720 wants to merge 3 commits into
pipe-cd:masterfrom
vanshika2720:fix/commandstore-cache-poisoning
Open

Prevent commandstore cache poisoning when backend Get fails after UpdateStatus#7231
vanshika2720 wants to merge 3 commits into
pipe-cd:masterfrom
vanshika2720:fix/commandstore-cache-poisoning

Conversation

@vanshika2720

@vanshika2720 vanshika2720 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

What this PR does:

Prevents commandstore from caching a nil command when the datastore Get fails after a successful command status update. It also adds a defensive nil check in the cache and regression tests covering the failure path.

Why we need it:

A transient Get failure could previously result in nil being cached as JSON null. On a later cache read, this could become a zero-value Command with an empty PipedId, causing ReportCommandHandled to return PermissionDenied for the legitimate piped.

Which issue(s) this PR fixes:

Fixes #7230

Does this PR introduce a user-facing change:

  • How are users affected by this change: No direct user-facing behavior change. This prevents a transient datastore error from poisoning the command cache and incorrectly rejecting subsequent command-handling requests.
  • Is this breaking change: No.
  • How to migrate (if breaking change): Not applicable.

Copilot AI lite review requested due to automatic review settings August 24, 2026 06:43
@vanshika2720
vanshika2720 requested a review from a team as a code owner August 24, 2026 06:43
@netlify

netlify Bot commented Aug 24, 2026

Copy link
Copy Markdown

Deploy Preview for pipecd-site canceled.

Name Link
🔨 Latest commit 5116824
🔍 Latest deploy log https://app.netlify.com/projects/pipecd-site/deploys/6a8f177b58baf10008a92dd7

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the control-plane commandstore cache behavior so transient datastore read failures during UpdateCommandHandled don’t poison the Redis-backed cache and later break command-handling authorization paths.

Changes:

  • Stop UpdateCommandHandled from writing to cache when the post-UpdateStatus backend.Get fails.
  • Add a defensive nil guard to commandCache.Put to prevent caching nil as JSON null.
  • Add regression tests for the failure path and the new cache guard.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/app/server/commandstore/store.go Skips cache write when backend.Get fails after a successful status update.
pkg/app/server/commandstore/cache.go Adds a defensive nil check in Put to prevent writing invalid cache payloads.
pkg/app/server/commandstore/store_test.go Adds regression tests covering transient Get failure after UpdateStatus and subsequent GetCommand behavior.
pkg/app/server/commandstore/cache_test.go Adds a unit test ensuring commandCache.Put rejects nil inputs.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/app/server/commandstore/cache.go
Comment thread pkg/app/server/commandstore/store_test.go
Comment thread pkg/app/server/commandstore/cache.go
…ateStatus

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
@vanshika2720
vanshika2720 force-pushed the fix/commandstore-cache-poisoning branch from 47bc31d to 5116824 Compare August 26, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

commandstore cache poisoning after transient Get failure following successful status update

3 participants