Skip to content

feat(#109): Security hardening - secrets, JWT, and pre-beta config Th… - #171

Merged
0xdevcollins merged 2 commits into
0xdevcollins:mainfrom
fairbid01:feat/issue-109-security-hardening
Jul 31, 2026
Merged

feat(#109): Security hardening - secrets, JWT, and pre-beta config Th…#171
0xdevcollins merged 2 commits into
0xdevcollins:mainfrom
fairbid01:feat/issue-109-security-hardening

Conversation

@fairbid01

@fairbid01 fairbid01 commented Jul 29, 2026

Copy link
Copy Markdown

Summary

Implements Issue #109 (pre-beta security hardening):

  • Secret generationscripts/generate-secrets.sh generates JWT_SECRET, BANK_SESSION_ENCRYPTION_KEY, and BANK_WEBHOOK_SECRET via openssl (single-line, .env-safe output) and lists the secrets that need manual setup (Stellar/EVM keys, Stripe, Circle, Resend, Cloudinary).
  • Startup validationapps/api/src/common/config/env-validation.ts validates critical env vars before boot: required vars must be set, no variable may remain at a .env.example placeholder value, and JWT_SECRET has a minimum length. Chain hot-wallet keys are required only when NODE_ENV=production, so local development and CI boot without provisioning real wallets. Validation throws a typed EnvValidationError; main.ts logs it and exits.
  • .env.example documentation — each variable now documents its purpose, format, and where to obtain it. API_KEY_SALT was removed: API keys are hashed with bcrypt (which embeds its own salts) and nothing in the codebase reads that variable.
  • README — adds a Pre-Beta Environment Setup Guide covering all environment variables by stage (local, beta, production) with sources and troubleshooting.
  • Tests — unit coverage for placeholder detection and the validation logic.

Note: .env.example previously contained only placeholder values (S..., 0x..., your-*) — no real secrets were ever tracked, so this PR documents and enforces good hygiene rather than remediating a leak.

Closes #109

…ta config This commit implements Issue 0xdevcollins#109 requirements: - Create secret generation script (scripts/generate-secrets.sh) * Generates JWT_SECRET, API_KEY_SALT, BANK_SESSION_ENCRYPTION_KEY, BANK_WEBHOOK_SECRET * Uses openssl for cryptographically secure random values * Executable and includes guidance for manual secret setup - Sanitize environment configuration * Clean .env.example of hardcoded private keys * Replace with safe placeholders (S..., 0x..., C..., your-*) * Add comprehensive inline documentation (60+ lines) - Add startup environment validation * New module: apps/api/src/common/config/env-validation.ts * Validates critical variables before API starts * Detects missing required secrets * Detects placeholder values using regex patterns * Halts startup with clear error messages * Integration in main.ts bootstrap function - Update documentation * README.md: Add Pre-Beta Environment Setup Guide (350+ lines) - Document 50+ environment variables - Include sources and how to obtain each secret - Setup by stage (local, beta, production) - Links to external service portals - Troubleshooting guide * Create SECURITY_HARDENING_IMPLEMENTATION.md - Implementation summary - Verification of acceptance criteria - Pre-release checklist - Security notes Acceptance Criteria Met: ✅ scripts/generate-secrets.sh exists and is executable ✅ No hardcoded private keys in tracked files ✅ .env.example sanitized with helpful placeholders ✅ main.ts validates critical environment secrets ✅ Validation fails on placeholder or missing values ✅ README.md contains comprehensive Pre-Beta guide ✅ All acceptance criteria verified
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Threadflow Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@fairbid01 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

- Strip base64 line wrapping in generate-secrets.sh so JWT_SECRET is a
  single-line value instead of a corrupted two-line entry
- Gate chain hot-wallet keys (STELLAR_RELAY_KEYPAIR_SECRET,
  EVM_RELAY_PRIVATE_KEY) on NODE_ENV=production so local development
  and CI can boot without provisioning real wallets; placeholder
  detection still applies everywhere
- Throw EnvValidationError instead of calling process.exit inside the
  validator; main.ts catches it, logs via Nest Logger, and exits
- Remove API_KEY_SALT from the script, example, README, and validation:
  API keys are hashed with bcrypt (embedded salts) and no code reads it
- Fix misleading 'placeholder or missing' error wording and collapse
  redundant placeholder patterns into the generic ones
- Add unit tests for isPlaceholder and validateEnvironmentConfig
- Remove SECURITY_HARDENING_IMPLEMENTATION.md: it claimed hardcoded
  private keys were removed, but .env.example only ever contained
  placeholders; the setup guidance lives in README and .env.example
@0xdevcollins
0xdevcollins merged commit be82193 into 0xdevcollins:main Jul 31, 2026
4 of 5 checks passed
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.

Environment: Harden Security — Secrets, JWT, and Pre-Beta Config Checklist

2 participants