knowless 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,7 +7,49 @@ Versioning is [SemVer](https://semver.org/).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ - **Turnkey Docker image** (`knowless/knowless-server:0.2.x`)
11
+ bundling Postfix + null-route + the binary so a self-hoster
12
+ runs `docker compose up` and has a working auth gateway in
13
+ one step. Material UX win for the PRD §4.2 self-hoster
14
+ audience. Targeted for v0.2.0.
10
15
  - Caddy forward-auth Docker integration test (TASKS.md 6.8).
16
+ - `knowless-server --check-null-route`: CLI probe that submits a
17
+ test message to `shamRecipient` and confirms the local MTA
18
+ discarded it. Targeted for v0.2.0.
19
+
20
+ ## [0.1.9] — 2026-04-28
21
+
22
+ addypin manual smoke turned up one real bug, one defaults footgun,
23
+ and one DX gap.
24
+
25
+ ### Fixed
26
+
27
+ - **`auth.deriveHandle(email)` now normalizes the email before
28
+ HMAC (AF-13).** Prior versions skipped `normalize()` while
29
+ `auth.startLogin` and `POST /login` ran it — adopters using
30
+ `deriveHandle` to precompute owner-keyed lookups got silent
31
+ handle mismatches whenever email casing varied between
32
+ create-time and click-time. Symptom was "user's records
33
+ disappear after login," which is awful to debug. The bare
34
+ `deriveHandle(emailNormalized, secret)` re-export still
35
+ expects pre-normalized input — that contract is unchanged.
36
+
37
+ ### Documentation
38
+
39
+ - **GUIDE flags the `failureRedirect` Mode-A footgun (AF-14).**
40
+ Adopters running programmatic-only (`startLogin` without
41
+ mounting `loginForm`) hit a default `failureRedirect = /login`
42
+ pointing at a route they don't serve — expired/replayed
43
+ magic-link clicks 302 to a 404. The GUIDE now leads with this
44
+ in the Mode-A walkthrough and adds a callout in the config
45
+ table. Default unchanged to avoid breaking Mode-B users with
46
+ custom paths.
47
+ - **OPS.md §11b — MailHog dev workflow (AF-15).** `docker run
48
+ mailhog/mailhog`, point knowless at port 1025, inspect every
49
+ outgoing mail (including sham submissions) in a UI at port
50
+ 8025. Verifies `bodyFooter`, `subjectOverride`, and the
51
+ URL-line-isn't-QP-soft-broken invariant without spinning up
52
+ real Postfix.
11
53
 
12
54
  ## [0.1.8] — 2026-04-28
13
55
 
package/GUIDE.md CHANGED
@@ -62,8 +62,8 @@ built-in auth is either missing or weak. The existing alternatives
62
62
  (Authelia, Authentik, Keycloak, oauth2-proxy) are heavyweight for
63
63
  the job: "redirect to login if no cookie, otherwise let through."
64
64
 
65
- knowless's standalone server (v0.2.0, in development) sits behind
66
- Caddy / nginx / Traefik via forward-auth. One auth subdomain, one
65
+ knowless's standalone server (`bin/knowless-server`, shipped in
66
+ v0.1.3) sits behind Caddy / nginx / Traefik via forward-auth. One auth subdomain, one
67
67
  session cookie scoped to the parent eTLD+1, SSO across all your
68
68
  services for free.
69
69
 
@@ -106,7 +106,7 @@ nothing else*.
106
106
  - **Walks away at v1.0.0.** Maintenance mode (security patches +
107
107
  bug fixes) after that, by design.
108
108
 
109
- ## Walkthrough: library mode (v0.1.0)
109
+ ## Walkthrough: library mode
110
110
 
111
111
  The shape: import `knowless`, configure it, mount the handlers on
112
112
  your HTTP framework.
@@ -175,7 +175,9 @@ sending domain):
175
175
  Without all three, Gmail / Outlook will silently drop your auth
176
176
  mail. This is the operator commitment knowless asks of you.
177
177
 
178
- > Full Postfix walkthrough lives in `OPS.md` (shipping with v0.2.0).
178
+ > Full Postfix walkthrough lives in [`OPS.md`](OPS.md) Postfix
179
+ > install, null-route, SPF/DKIM/PTR, systemd, reverse-proxy
180
+ > forward-auth examples, multi-process deployments.
179
181
 
180
182
  ### Step 4: Mount the handlers
181
183
 
@@ -295,7 +297,19 @@ callers. See SPEC §7.3a for the full contract.
295
297
 
296
298
  `auth.deriveHandle(email)` returns the same opaque HMAC handle
297
299
  that the form path uses, without you having to import the helper
298
- or pass the secret around.
300
+ or pass the secret around. The instance method **normalizes the
301
+ email** (lowercase, trim) before HMAC (AF-13), so `Alice@X.com`
302
+ and `alice@x.com` produce the same handle — match what the form
303
+ and `startLogin` would compute. The bare `deriveHandle` re-export
304
+ takes pre-normalized input; use the instance method unless you
305
+ have a specific reason to call the lower-level primitive.
306
+
307
+ > **Mode-A heads-up: set `failureRedirect`.** If you only mount
308
+ > `auth.callback` (not `auth.loginForm`), the default
309
+ > `failureRedirect` cascade points at `/login` — a route you
310
+ > don't serve. An expired or replayed magic-link click will 302
311
+ > to a 404. Set `failureRedirect: '/'` (or any route you do
312
+ > serve) when wiring Mode A.
299
313
 
300
314
  ### Step 5: Pre-seed users (closed-registration mode, default)
301
315
 
@@ -402,11 +416,10 @@ Library doesn't ship a built-in HTTP endpoint for this — operator
402
416
  chooses the UX (admin CLI, in-app self-service, ticket-driven
403
417
  support).
404
418
 
405
- ## Walkthrough: standalone server mode (v0.2.0, coming)
419
+ ## Walkthrough: standalone server mode
406
420
 
407
- The shape: run `npx knowless-server`, point Caddy / nginx /
408
- Traefik at it for forward-auth, protect any HTTP service behind
409
- magic-link login.
421
+ Run `npx knowless-server`, point Caddy / nginx / Traefik at it for
422
+ forward-auth, protect any HTTP service behind magic-link login.
410
423
 
411
424
  The deployment-shape pattern:
412
425
  ```
@@ -418,7 +431,9 @@ The deployment-shape pattern:
418
431
  [Caddy redirects to auth.example.com/login?next=...]
419
432
  ```
420
433
 
421
- Sample Caddyfile (forthcoming OPS.md will have the full setup):
434
+ Sample Caddyfile (full setup including TLS/ACME + multiple gated
435
+ services lives in [`OPS.md`](OPS.md) §7):
436
+
422
437
  ```caddy
423
438
  auth.example.com {
424
439
  reverse_proxy localhost:8080
@@ -427,7 +442,7 @@ auth.example.com {
427
442
  kuma.example.com {
428
443
  forward_auth localhost:8080 {
429
444
  uri /verify
430
- copy_headers X-User-Handle
445
+ copy_headers X-Knowless-Handle
431
446
  }
432
447
  reverse_proxy localhost:3001 # Uptime Kuma
433
448
  }
@@ -435,7 +450,7 @@ kuma.example.com {
435
450
  adguard.example.com {
436
451
  forward_auth localhost:8080 {
437
452
  uri /verify
438
- copy_headers X-User-Handle
453
+ copy_headers X-Knowless-Handle
439
454
  }
440
455
  reverse_proxy localhost:3000 # AdGuard Home
441
456
  }
@@ -444,9 +459,11 @@ adguard.example.com {
444
459
  One auth subdomain, one cookie, SSO across all gated services
445
460
  because the cookie is scoped to the parent eTLD+1.
446
461
 
447
- Until v0.2.0, you can replicate this yourself with ~30 lines of
448
- `node:http` wrapping the library-mode handlers — see
449
- `knowless.context.md` for the pattern.
462
+ Configuration is via `KNOWLESS_*` env vars see
463
+ [`config.example.env`](config.example.env) and run
464
+ `knowless-server --help` for the full list. `knowless-server
465
+ --config-check` validates your env, SMTP reachability, and DB
466
+ write access; suitable for systemd `ExecStartPre`.
450
467
 
451
468
  ## Configuration reference
452
469
 
@@ -479,7 +496,7 @@ Full options table:
479
496
  | `trustedProxies` | no | `['127.0.0.1', '::1']` | IPs allowed to set `X-Forwarded-For`. |
480
497
  | `shamRecipient` | no | `null@knowless.invalid` | Where sham mail goes (your MTA must discard it). |
481
498
  | `sweepIntervalMs` | no | `300000` | Sweeper tick (5 min default). |
482
- | `failureRedirect` | no | (= `loginPath`) | Where /auth/callback failures redirect. |
499
+ | `failureRedirect` | no | (= `loginPath`) | Where /auth/callback failures redirect. **Mode-A adopters:** if you don't mount `loginForm`, set this to a route you actually serve (e.g. `/`) — otherwise expired/replayed magic-link clicks 302 to a 404. |
483
500
  | `store` | no | (built-in better-sqlite3) | Inject your own store implementation. |
484
501
  | `mailer` | no | (built-in nodemailer) | Inject your own mailer. |
485
502
 
package/OPS.md CHANGED
@@ -589,6 +589,54 @@ want for forward-auth-style deployments anyway.
589
589
 
590
590
  ---
591
591
 
592
+ ## 11b. Local development without a real Postfix
593
+
594
+ Spinning up Postfix on a developer laptop just to inspect what
595
+ knowless sends is heavy. Two leaner options:
596
+
597
+ ### Option A — `devLogMagicLinks: true` (no MTA needed)
598
+
599
+ knowless already supports this for the URL. When SMTP submission
600
+ fails AND `devLogMagicLinks: true` is set, the magic link is
601
+ printed to stderr tagged `[knowless dev:<from>]`. Sufficient for
602
+ smoke-testing the click flow, not the email content. AF-6.2.
603
+
604
+ ### Option B — MailHog (visual UI for the rendered mail)
605
+
606
+ For verifying subject/body/footer rendering or the timing of
607
+ sham-vs-real submissions, run [MailHog](https://github.com/mailhog/MailHog)
608
+ or any compatible test SMTP catcher (e.g. mailpit, smtp4dev) on
609
+ the dev machine and point knowless at it.
610
+
611
+ ```sh
612
+ # Docker one-liner for MailHog
613
+ docker run --rm -p 1025:1025 -p 8025:8025 mailhog/mailhog
614
+ ```
615
+
616
+ Then in your dev knowless config:
617
+
618
+ ```js
619
+ const auth = knowless({
620
+ secret: process.env.KNOWLESS_SECRET,
621
+ baseUrl: 'http://localhost:3000',
622
+ from: 'auth@dev.local',
623
+ smtpHost: 'localhost',
624
+ smtpPort: 1025, // MailHog's SMTP port
625
+ cookieSecure: false, // localhost-only dev
626
+ });
627
+ ```
628
+
629
+ Open `http://localhost:8025` in your browser; every magic-link mail
630
+ (including sham submissions to `null@knowless.invalid`) shows up in
631
+ the inbox UI with full subject/body/headers visible. Perfect for
632
+ verifying `bodyFooter`, `subjectOverride`, the URL line is intact
633
+ without QP soft-breaks, etc.
634
+
635
+ > Don't ship MailHog into production. It accepts mail from anywhere
636
+ > and stores it forever — defeats the entire knowless threat model.
637
+
638
+ ---
639
+
592
640
  ## 12. Backup and recovery
593
641
 
594
642
  The only stateful file is the SQLite database (`KNOWLESS_DB_PATH`,
package/README.md CHANGED
@@ -7,7 +7,7 @@ that don't need to email their users for anything but the sign-in link.
7
7
  npm install knowless
8
8
  ```
9
9
 
10
- > v0.1.8 | Node.js >= 20 | 2 deps (nodemailer, better-sqlite3) | Apache-2.0
10
+ > v0.1.9 | Node.js >= 20 | 2 deps (nodemailer, better-sqlite3) | Apache-2.0
11
11
 
12
12
  ## What this is
13
13
 
@@ -1,7 +1,7 @@
1
1
  # knowless -- Integration Guide
2
2
 
3
3
  > For AI assistants and developers wiring knowless into a project.
4
- > v0.1.0 | Node.js >= 20 | 2 deps (nodemailer, better-sqlite3) | Apache-2.0
4
+ > v0.1.9 | Node.js >= 20 | 2 deps (nodemailer, better-sqlite3) | Apache-2.0
5
5
 
6
6
  ## What this is
7
7
 
@@ -18,11 +18,13 @@ npm install knowless
18
18
 
19
19
  Two integration paths:
20
20
 
21
- 1. **Library mode (v0.1.0):** `import { knowless } from 'knowless'` --
22
- mount five handlers on Express / Fastify / Hono / `node:http`
23
- 2. **Standalone server (v0.2.0, in development):** `npx knowless-server` --
24
- forward-auth gateway for Caddy / nginx / Traefik in front of
25
- no-auth services like Uptime Kuma, AdGuard, Pi-hole
21
+ 1. **Library mode:** `import { knowless } from 'knowless'` --
22
+ mount five handlers on Express / Fastify / Hono / `node:http`,
23
+ gate your endpoints with `auth.handleFromRequest(req)`.
24
+ 2. **Standalone server:** `npx knowless-server` -- forward-auth
25
+ gateway for Caddy / nginx / Traefik in front of no-auth services
26
+ like Uptime Kuma, AdGuard, Pi-hole. Configured via `KNOWLESS_*`
27
+ env vars; see [`OPS.md`](OPS.md) for the full deployment guide.
26
28
 
27
29
  This document is the dense reference. For the why, see
28
30
  `docs/01-product/PRD.md`. For the wire formats, see
@@ -148,7 +150,7 @@ const auth = knowless({
148
150
  | `deleteHandle` | (handle: string) | void | Atomic delete of handle + tokens + sessions (FR-37a, GDPR) |
149
151
  | `revokeSessions` | (handle: string) | number | Drops every session for `handle` without deleting the account ("log out everywhere"). Returns rows removed. AF-6.1. |
150
152
  | `startLogin` | ({email, nextUrl?, sourceIp?, subjectOverride?, bypassRateLimit?}) | Promise\<{handle, submitted: true}\> | Programmatic magic-link send for "use first, claim later" flows. Same 12-step sham-work as form. `subjectOverride` (AF-9) replaces `cfg.subject` per call. `bypassRateLimit: true` (AF-10) opts trusted server-side callers (CLI, cron, worker) out of IP-rate-limit accounting. SPEC §7.3a. AF-7.3. |
151
- | `deriveHandle` | (email: string) | string | HMAC-SHA256(secret, normalize(email)) using the configured secret. Use to compute owner-handles outside HTTP context. AF-7.4. |
153
+ | `deriveHandle` | (email: string) | string | `HMAC-SHA256(secret, normalize(email))` using the configured secret. Normalizes input (lowercase + trim) so `Alice@X.com` and `alice@x.com` produce the same handle. Match what `startLogin` and `POST /login` compute. AF-7.4 / AF-13. |
152
154
  | `_sweep` | -- | void | Trigger one sweep tick on demand (tests, operator scripts). AF-5.3. |
153
155
  | `config` | -- | object | Merged effective config; safe to read (do not mutate) |
154
156
  | `close` | -- | void | Stops sweeper, closes mailer + store. Call on shutdown. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knowless",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Small, opinionated, full-stack passwordless auth for Node.js services that don't need to email their users for anything but the sign-in link.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createStore } from './store.js';
2
2
  import { createMailer, validateBodyFooter } from './mailer.js';
3
3
  import { createHandlers } from './handlers.js';
4
- import { deriveHandle as deriveHandleRaw } from './handle.js';
4
+ import { deriveHandle as deriveHandleRaw, normalize } from './handle.js';
5
5
 
6
6
  /** Default sweeper tick: 5 minutes. Per FR-13. */
7
7
  const DEFAULT_SWEEP_INTERVAL_MS = 5 * 60 * 1000;
@@ -153,9 +153,12 @@ export function knowless(options = {}) {
153
153
  * See SPEC §7.3a. AF-7.3. */
154
154
  startLogin: handlers.startLogin,
155
155
  /** Derive the opaque handle for an email using the configured
156
- * secret. Lets adopters compute owner-handles outside HTTP context
157
- * without spreading the secret across modules. AF-7.4. */
158
- deriveHandle: (email) => deriveHandleRaw(email, options.secret),
156
+ * secret. Normalizes the email first (AF-13) so handles match
157
+ * what `auth.startLogin` and `POST /login` would compute for the
158
+ * same address typed with different casing or surrounding
159
+ * whitespace. Adopters should treat this as the canonical handle
160
+ * derivation. AF-7.4 / AF-13. */
161
+ deriveHandle: (email) => deriveHandleRaw(normalize(email), options.secret),
159
162
  /** Effective config (with defaults applied), useful for routing. */
160
163
  config: handlers._config,
161
164
  /** Run a sweep tick on demand. Useful for tests and operator scripts. */