fix(secret-patcher): mask JSON-object values in status when server key order differs#170
Open
SAY-5 wants to merge 1 commit into
Open
fix(secret-patcher): mask JSON-object values in status when server key order differs#170SAY-5 wants to merge 1 commit into
SAY-5 wants to merge 1 commit into
Conversation
…y order differs from json.Marshal output Fixes crossplane-contrib#169 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
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.
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:
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.