Repository navigation
fix: do not log raw json value in json validator error - #258
vergiLgood1 wants to merge 1 commit 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.
|
Hi, Thanks for taking a stab at this, I agree that secret handling is something that should be improved, but I don't think just handling this case in the json field is the way forward. Secrets are probably most commonly used in the str validator, so that one would also need to have the same safeguards. I have been thinking (no implementation yet) about supporting a Thoughts? |
|
Thanks for the thoughtful feedback! I agree that addressing this only in The Would you be open to me exploring and implementing this more general masking approach? |
|
Sure, I would appreciate help with the R&D on that idea. It may require some iterations before we land on a shippable implementation, but definitely take a crack at it and we'll see how it looks/feels to use |
|
Thanks again for the direction on this. I gave the general masking idea a shot and opened a draft to show it: #260 (stacked on top of this one). One thing I came across while exploring the Proxy route: Proxy traps only work on objects, not primitives ( It's still a draft and I'm not at all sure it's the shape you had in mind, so I'd really welcome your thoughts whenever you get a chance. If you'd prefer to keep this PR focused on the |
Summary
The
json()validator includes the entire raw value in its error message:Environment variables parsed as JSON often contain secrets — API tokens, service-account credentials, connection configs. When a JSON env var fails to parse, that raw value currently ends up in the console/log output via the error report.
This changes the error to
"Invalid json", mirroring the change already made for theurlvalidator in 1f67e8d ("Prevent logging of potentially sensitive data in url validator"):Behavior change note: the error message text changes from
Invalid json: "<value>"toInvalid json. No tests asserted the previous message, and debugging value content can still be done locally by inspecting the variable itself.Changes
src/validators.ts— stop including the raw value in the error (same pattern as theurlvalidator)tests/validators.test.ts— regression test: an unparseable JSON value containing a secret produces"Invalid json"with no trace of the raw valueVerification
bun run ts✅bun run lint✅bun run test:ci✅ (67 tests)bun run coverage✅ (functions 100%, lines 98.85%)