source: Klonkt/src/config/mailer.js@ a64f642

main
Last change on this file since a64f642 was 9e27d64, checked in by roboburr <roboburr@…>, 3 months ago

auth: password admin + per-instance Google for listeners (no broker)

Robin's choice: every self-hoster has their own password admin account,
and can optionally let listeners log in to comment using their OWN Google
client. No central broker (that would tie every customer site to Robin's
Google Cloud -> systemic risk on abuse).

  • Admin = username/password (bcrypt). First-time setup via /auth/register (only when there are 0 users); closed afterwards. No public registration.
  • Forgot password: /auth/reset-request -> email (if SMTP configured) with reset link; CLI break-glass npm run reset-admin always works (no email needed).
  • Change password (logged in) restored in /account.
  • Google = per-instance own credentials, OPTIONAL, listeners only -> always role member, never admin (god/admin email is rejected; google_sub mismatch too).
  • config/google.js back to direct Google OAuth; config/mailer.js new (nodemailer).
  • jose removed from deps; nodemailer added.

Security review (workflow) incorporated:

  • Reset token no longer in production logs (dev only).
  • Reset link from PUBLIC_BASE_URL instead of X-Forwarded-Host (host poisoning).
  • Reset tokens stored SHA-256-hashed in the DB.
  • Same-origin check on all state-modifying POSTs (CSRF layer on top of sameSite-lax).
  • Login always runs one bcrypt comparison (no timing enumeration).

Co-Authored-By: Claude <noreply@…>

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[9e27d64]1// E-mail versturen (wachtwoord-reset). Optioneel: alleen actief als de self-hoster
2// SMTP heeft ingesteld. Niet ingesteld? Dan valt de reset terug op de CLI
3// (`npm run reset-admin`) — zie README.
4//
5// Config via env:
6// SMTP_HOST, SMTP_PORT (default 587), SMTP_USER, SMTP_PASS
7// SMTP_FROM (afzender; default = SMTP_USER)
8
9import nodemailer from 'nodemailer';
10
11const HOST = process.env.SMTP_HOST || '';
12const PORT = parseInt(process.env.SMTP_PORT || '587', 10);
13const USER = process.env.SMTP_USER || '';
14const PASS = process.env.SMTP_PASS || '';
15const FROM = process.env.SMTP_FROM || USER;
16
17export function mailerConfigured() {
18 return !!(HOST && USER && PASS);
19}
20
21let _transport = null;
22function transport() {
23 if (!_transport) {
24 _transport = nodemailer.createTransport({
25 host: HOST,
26 port: PORT,
27 secure: PORT === 465, // 465 = impliciete TLS; 587 = STARTTLS
28 auth: { user: USER, pass: PASS },
29 });
30 }
31 return _transport;
32}
33
34export async function sendMail({ to, subject, text, html }) {
35 if (!mailerConfigured()) throw new Error('SMTP niet geconfigureerd');
36 return transport().sendMail({ from: FROM, to, subject, text, html });
37}
Note: See TracBrowser for help on using the repository browser.