Skip to content

fix(secret-patcher): mask JSON-object values in status when server key order differs#170

Open
SAY-5 wants to merge 1 commit into
crossplane-contrib:mainfrom
SAY-5:fix-jsonobject-status-mask
Open

fix(secret-patcher): mask JSON-object values in status when server key order differs#170
SAY-5 wants to merge 1 commit into
crossplane-contrib:mainfrom
SAY-5:fix-jsonobject-status-mask

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 7, 2026

Description of your changes

Fixes #169

When `secretInjectionConfigs.responseJQ` selects a JSON object (e.g. `.body`), the value is correctly stored in the referenced Secret but the sensitive object remains visible in the `DisposableRequest` status, `replaceSensitiveValues` never replaces it with the `{{secret-name:namespace:key}}` placeholder.

`extractValueToPatch` produces the value via `json.Marshal`, which sorts keys alphabetically, while `data.Body` preserves the server's original key ordering. `strings.ReplaceAll` does an exact substring match, so the two strings rarely match in practice and the replacement is silently skipped.

Walk the parsed body and replace the first subtree whose canonical (key-sorted) JSON form equals the extracted value with the placeholder. Fall back to the existing substring replacement when the body is not parseable as JSON.

I have:

  • Read and followed Crossplane's contribution process.
  • Run `make reviewable test` to ensure this PR is ready for review.

How has this code been tested

Added a regression test that mirrors the bug: response body with a nested object whose keys are in non-alphabetical order, and a `valueToPatch` produced by `json.Marshal` (key-sorted). Confirms the placeholder is now applied at the correct location. The existing `ShouldReplaceJSONObjectInBody` test was updated to reflect that the body is re-marshaled (insignificant whitespace is collapsed). Full `go test ./...` passes.

…y order differs from json.Marshal output

Fixes crossplane-contrib#169

Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sensitive value not masked in status when responseJQ selects a JSON object (e.g. .body)

1 participant