Skip to content

Validate required env vars against a schema and redact secrets in src/config.ts #175

Description

@Jagadeeshftw

📌 Description

src/config.ts (already improved to fail fast on missing vars) should go further and validate each var's shape (URL format, numeric ranges, allowed enum values) using a schema library, and ensure any error output never echoes secret values verbatim.

🧩 Requirements and context

  • Add schema validation (e.g. zod) covering type/format/range for each config value, not just presence.
  • On validation failure, list which fields failed and why, without printing secret values (DB URL credentials, API keys) into the error message.
  • Add a redactedConfig() helper safe to log for debugging.

🛠️ Suggested execution

  1. Introduce a schema in src/config.ts and validate the parsed env against it at startup.
  2. Add a redaction helper that masks known-sensitive fields.
  3. Add tests for a malformed value (wrong type/format) producing a redacted, actionable error.

✅ Acceptance criteria

  • Malformed (not just missing) env vars fail startup with a clear, field-specific error.
  • No secret value ever appears verbatim in a thrown error or log line.
  • redactedConfig() output is safe to log.

🔒 Security notes

This directly prevents secret leakage via error messages/logs during misconfiguration, a common accidental-disclosure vector.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issueStellar WaveIssues in the Stellar wave programbackendBackend / API worksecuritySecurity hardening / audit

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions