Repository navigation
feat: add mask spec option to redact env values in error output - #260
Draft
vergiLgood1 wants to merge 2 commits into
Draft
vergiLgood1 wants to merge 2 commits into
vergiLgood1 wants to merge 2 commits into
Conversation
The raw value could contain sensitive data (API keys, tokens, service credentials) and would end up in logs via the error output. Follows 1f67e8d, which made the same change for the url validator.
Draft/R&D follow-up to af#258. Secrets are commonly held in `str`, so this adds a general `mask` option applied where the library formats error messages, instead of patching a single validator. - `mask: 'all' | 'last4' | (value) => string` - Validators render through a helper, so redaction is exact (no string replace) - No breaking changes: without `mask`, messages are byte-identical - url/json stay value-free by default, but show a masked value when `mask` is set - Custom validators: quoted values in thrown errors are redacted automatically - `example` is masked too (it appears in missing-var errors)
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.
Context
#258 stops
json()from echoing the raw value. Aaron pointed out secrets are more commonly held instr, and suggested a generalmaskoption (possibly with Proxy traps). This is my attempt at that.Finding on the Proxy idea
Proxy traps only work on objects —
new Proxy('x', {})throwsTypeError. Sincestr/num/boolreturn primitives, a Proxy can't wrap them, andstris where secrets usually live. So I went a different way and may have missed something obvious — happy to be corrected.What this does
A
maskspec option, applied where the library formats error messages:'all' | 'last4', plus a custom(value) => stringrenderer.displayValue/displayMasked), so redaction is exact — no string replacement. (My first attempt didmsg.replace(raw, masked)and corrupted messages when the value was short: an input of"a"ate theain "Invalid".)mask, messages are byte-identical, and the publicmakeValidatorsignatures are unchanged.url/jsonstay value-free by default but show a masked value whenmaskis set.exampleis masked too (it shows up in missing-var errors).Stacked on #258
This branch is based on
fix/json-error-leaks-value, so the diff currently shows 2 commits. Only the second (e38e28b) is new; the first is #258 itself and will drop out once #258 merges.Verification
npm run test:ci— 80 tests passnpm run tsandnpm run lint— cleanmask.tsandmakers.tsat 100% coverageOpen questions
maskis set, like theurl/jsoncommits)? It's a one-line change indisplayValue.Leaving this as a Draft for now — I'm not sure it's the shape you had in mind, so happy to redo or drop it.