Skip to content

fix(mail): validate SMTP_URL, isolate mailer from DB, guided SMTP setup - #12

Merged
t11z merged 1 commit into
mainfrom
claude/wayfare-photo-app-leku36
Nov 1, 2026
Merged

t11z merged 1 commit into
mainfrom
claude/wayfare-photo-app-leku36

Conversation

@t11z

@t11z t11z commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Problem

On the first real Firebase deployment, /api/health returned 503 and every Firestore-backed page returned 500, with TypeError: Invalid URL. The cause was a malformed SMTP_URL in the WAYFARE_ENV secret (the host was missing: …@://gmail.com):

  • nodemailer threw while the composition root was being built.
  • Because db, blobs and mailer were built in one promise, a mail misconfiguration also took down database access.
  • The thrown error object, including the SMTP password in input, ended up in Cloud Logging.
  • The bootstrap script asked for the full URL as hidden input and only checked it with a lax regex, which made typos likely.

Changes

  • src/server/config.ts: SMTP_URL is validated at startup (isValidSmtpUrl: smtp:/smtps: plus a real hostname). The error message never echoes the value.
  • src/server/container.ts: the mailer is now its own lazy singleton, so a broken mail setup can no longer take the DB down. A failed build is no longer cached.
  • src/server/adapters/mail/smtp.ts: transport errors are rethrown without the URL.
  • scripts/firebase-bootstrap.sh:
    • Guided SMTP setup: host, port and user are entered visibly, only the password is hidden. The script assembles and URL-encodes the URL itself (Gmail app-password spaces are removed).
    • Validation follows the same rule as the app.
    • A malformed SMTP_URL already stored in the secret is detected; you can re-enter it interactively, and with --yes it is removed.
  • Tests:
    • Unit tests for isValidSmtpUrl.
    • A new dry-run scenario badsmtp checks detection, removal, the new secret version, and that the password is never printed.
  • Docs (DE/EN):
    • configuration.md: validation note.
    • mail.md: Gmail example.
    • firebase.md: guided SMTP step.

Checks

  • npm run typecheck && npm run lint && npm test: 280 passed, 23 skipped.
  • npm run test:integration: 63 passed.
  • bash scripts/test/bootstrap-dry-run.sh: ALL CHECKS PASSED.

Generated by Claude Code

… setup

A malformed SMTP_URL (`smtps://user:pass@://gmail.com`) made nodemailer throw
"Invalid URL" while the composition root was built. Because db, blobs and
mailer were built in one promise, every Firestore-backed page and
/api/health failed with 503/500, and the error object (incl. the password)
ended up in the logs.

- config: SMTP_URL is validated at startup (smtp/smtps + real hostname);
  the error message never echoes the value
- container: mailer is built separately, so a broken mail setup can no
  longer take the database down; failed builds are no longer cached
- smtp adapter: transport errors are rethrown without the URL
- bootstrap: SMTP is entered as host/port/user (visible) + password
  (hidden) and the URL is assembled and encoded by the script; a stored
  malformed SMTP_URL is detected and re-entered or removed
- tests: isValidSmtpUrl unit tests, dry-run scenario for a broken secret
- docs (de/en): validation note, Gmail example, guided SMTP step

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QcqxZNX1wgX8w3T7xRWFvZ
@t11z t11z self-assigned this Nov 1, 2026
@t11z t11z added the bug Something isn't working label Nov 1, 2026
@t11z
t11z merged commit f1933da into main Nov 1, 2026
2 checks passed
@t11z
t11z deleted the claude/wayfare-photo-app-leku36 branch November 1, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants