Repository navigation
fix(redact): mask secrets nested in added, removed or retyped values - #6
Open
vishalhabib99 wants to merge 1 commit into
Open
vishalhabib99 wants to merge 1 commit into
vishalhabib99 wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
What this changes
redact(CLI--redact, the Action'sredact: true, MCPredact: true) prints secrets in plain text when they sit inside an object or array that was added, removed or changed type. Only a secret whose own key is the changed path was masked.Repro on
main(6920fcc):--redact --jsongives"newValue": {"password": "hunter2", ...}with no"redacted": true, and MCPdiff_configsreturns the same in its text andstructuredContent. The same happens for a removed subtree (- db = {"token":"abc"}), a container type change (~ db (type) "x" => {"password":...}), and new array elements (indexed,--array-set,--array-key, and{name: DB_PASSWORD, value: ...}entries without--array-key name).Cause
makeRedactMatcher(src/redact.ts:151-163) looks only at the last segment of the change's path (db,env[1]), andlooksHighEntropyonly accepts strings. When a whole subtree changes,diff.tsemits one change at the parent path (e.g.:275,277,:304-305,:320,322,:416,418,:439,442), andrender.ts(showat:33-34,renderJsonat:103-105) then prints the full value unmasked.Fix
src/redact.ts: newredactNested(value, path, redact)walks arrays and plain objects, calls the same matcher on each nested path (so built-in key names,--redact-keyglobs and--redact-entropyall apply at any depth), applies the name/value-pair rule to object elements, and returns a masked copy. Dates and other non-plain objects are left alone.src/render.ts:renderTextandrenderJsonuse it when the change is not already masked as a whole.renderJsonsets"redacted": truewhen anything inside was masked.action/confdiff.cjsanddocs/playground.jsare rebuilt withnpm run build:action/npm run build:web(both rebuild byte-identical onmainbefore this change, so their diff is only this fix). I did not rebuildpackages/confdiff-mcp/bin/confdiff-mcp.cjsor bump versions; I left that for your release.Tests
test/render.test.ts: added object (text + JSON), then removed / type change / indexed / set / keyed (nested two levels) / name-value element, a no-over-redaction case, and--redact-key+--redact-entropyinside an added object.test/mcp.test.ts:diff_configswithredact: trueon an addeddbobject, checking text andstructuredContent.npm testpasses 128/128.npm run buildis clean.dist/cli.js --redact,--redact --jsonandaction/confdiff.cjs --redacton the repro now print+ db = {"password":"«redacted:28c19f»","user":"x"}.