Skip to content

fix: do not log raw json value in json validator error - #258

Open
vergiLgood1 wants to merge 1 commit into
af:mainfrom
vergiLgood1:fix/json-error-leaks-value
Open

vergiLgood1 wants to merge 1 commit into
af:mainfrom
vergiLgood1:fix/json-error-leaks-value

Conversation

@vergiLgood1

Copy link
Copy Markdown

Summary

The json() validator includes the entire raw value in its error message:

throw new EnvError(`Invalid json: "${x}"`)

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 the url validator in 1f67e8d ("Prevent logging of potentially sensitive data in url validator"):

// Not logging the json value as it could contain sensitive data
throw new EnvError(`Invalid json`)

Behavior change note: the error message text changes from Invalid json: "<value>" to Invalid 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 the url validator)
  • tests/validators.test.ts — regression test: an unparseable JSON value containing a secret produces "Invalid json" with no trace of the raw value

Verification

  • bun run ts ✅
  • bun run lint ✅
  • bun run test:ci ✅ (67 tests)
  • bun run coverage ✅ (functions 100%, lines 98.85%)

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.
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.

1 participant