Skip to content

Release prep v0.9.0: Nasaq 1.x, CI, admin API contract, flow tests (#2) - #3

Merged
fadymondy merged 12 commits into
mainfrom
feat/2-release-v0.9.0
Oct 8, 2026
Merged

fadymondy merged 12 commits into
mainfrom
feat/2-release-v0.9.0

Conversation

@fadymondy

@fadymondy fadymondy commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What

  • Nasaq port moved from 0.5.0 to @fadymondy/nasaq ^1.2.0 (no breakages: tsc and next build clean). Next 16 conventions: flat ESLint (no next lint), react-hooks v7 clean, router-based navigation.
  • Client aligned with the auth admin API (/api/auth/admin/*, /api/auth/csrf, /api/auth/me, /api/auth/impersonation/stop, /api/auth/password/reset): typed 401/403/404 errors, forbidden state (no crash), CSRF on writes only, admin calls always use the admin session.
  • Impersonation security model: persistent banner from me.impersonator, explicit End calls POST /api/auth/impersonation/stop with the impersonation bearer, bearer sent only on acting-as-user calls (never /admin/*), Users/Mail nav and pages blocked while impersonating, expired token falls back to the admin session.
  • New /reset-password?token= page posting {token, password}. Reset/magic-link 403 for admin targets (AUTH_IMPERSONATE_ADMINS unset) shows a toast, not a forbidden page.
  • Fix: Submit button now type="submit" (Nasaq 1.x Button defaults to type="button", which silently broke every auth form).
  • CI: go job (Go version from go.mod) plus new web job: test-harness/assemble.mjs injects web/ into a minimal Next project, then npm ci, lint, typecheck, test, build.
  • Go: mail admin routes tested against a real kernel with auth's RequireRole: anonymous 401, non-admin 403 on GET/PUT/POST; admin passes. togo bumped to v0.21.0.

Why

Release train circlexo/apps#78. CI root cause: the premise did not reproduce (runs on 97eaec3 are green, Actions enabled); the real gap was that CI covered Go only, so web breakage was never exercised. The web job closes that.

How tested

Locally in the harness: eslint (0 errors, 2 warnings: window.location.href for dev-login/SSO external redirects), tsc --noEmit, Vitest 22/22, next build; go vet and go test pass.

Dependency on auth#5 / #6

Client assumes the contract of togo-framework/auth#6 (target v0.10.0, under security review, unmerged). go.mod stays on auth v0.8.0: bump to v0.10.0 once tagged (no replace, no pseudo-version). Until then admin user management returns 404 from older auth.

Security audit

  • Runtime/shipped deps (npm audit --omit=dev on the harness): 0 vulnerabilities.
  • Dev-only, 5 high, one chain in the lint tooling: eslint-config-next > @next/eslint-plugin-next > fast-glob > micromatch > braces (GHSA-vfj7-8cjw-p6xm, regex stack exhaustion on deeply nested glob patterns). Not shipped, fed only repo-controlled globs; the only offered fix is a downgrade to eslint-config-next 14, so it is deliberately not applied. Revisit when eslint-config-next updates.

Impersonation

Profile and /two-factor show no password, PIN or 2FA controls while impersonating, with a note that they belong to the account holder (Vitest covered). The plugin has no API-token UI. Server 403 remains the boundary.

Gaps

  • No Playwright E2E (the release-train acceptance test covers real-scaffold flows).
  • ESLint pinned to 9.x (10 conflicts with eslint-config-next peers).

Closes #2. Part of circlexo/apps#78.

🤖 Generated with Claude Code

fadymondy and others added 7 commits October 7, 2026 20:24
Port to @fadymondy/nasaq ^1.2.0 and Next 16 conventions, align the client with
the auth admin API (togo-framework/auth#5/#6) including the impersonation
security model and /reset-password, add a web CI job with a harness, committed
Vitest flow tests and Go tests for the mail admin guard, bump togo to v0.21.0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…tor) with tests

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…), demoted/deleted admins on mail routes, pinned-version check, Postgres variant

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…test commands

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e CI toolchain)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@fadymondy

Copy link
Copy Markdown
Contributor Author

dashboard#3 release gate: FAIL (F2, Medium). Release gate stopped.

Reviewed commit: 4fcd2f8ccf30addabcfb6b14ff81257112815b5a. It equals the PR head, and CI passes (go, web). The review was done by a fresh security-engineer who did not author this code. Nothing was merged, tagged or deployed.

F2 (Medium): the stored SMTP password can be recovered

  • Broken invariant: a masked stored secret must not be recoverable. mail.go:79-80 masks the password on GET with the comment "never leak the stored secret".
  • Repro:
    1. As an admin, PUT /api/dashboard/admin/mail with a new host (and port), sending the password as the mask or omitting it.
    2. POST /api/dashboard/admin/mail/test.
  • Expected: the password is withheld from a changed endpoint, or the PUT is refused until the password is re-entered.
  • Actual: putMail (mail.go:91-96) keeps the old password whatever the new host, and sendSMTP sends it through smtp.PlainAuth. The reviewer's fake SMTP server on 127.0.0.1 captured the original password in the AUTH PLAIN exchange. net/smtp sends PLAIN auth only to localhost or over TLS. TLS is verified against the attacker-chosen host name, and an attacker domain can hold a valid certificate, so remote exfiltration is feasible.
  • Why Medium (CVSS 3.1 AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:N/A:N, about 6.8): the masking is a deliberate confidentiality control, and this defeats it. The credential gives access to an external mail account (a scope change). PR:H applies because an admin session is required.
  • Code path: putMail keeps the password, then kvSet, then testMail, then sendSMTP, then smtp.PlainAuth. This code is unchanged from main, so the flaw predates the PR, but v0.9.0 ships it.
  • DB coverage: reproduced on Postgres. On SQLite the PUT itself fails (F4).
  • Recommended contained fix (dashboard mail.go only, auth untouched): in putMail, keep the stored password only when host, port, username and the TLS/secure mode all match the stored config. Otherwise return 400 and require the password to be re-entered. Add tests asserting that a changed host plus a masked password is refused, and that an unchanged config keeps the password.

Low findings (documented with reproductions; recommended for the same contained fix or a follow-up)

  • F1: with AUTH_ADMIN_CROSS_CONTROL=true, an impersonated admin session reaches the mail routes. RequireRole (auth guardBy) has no impersonator or PAT check, unlike requireAdmin. The default configuration is not reachable, and there is no privilege gain. Fix on the dashboard side: after RequireRole, refuse Impersonator != "" and Guard == "pat".
  • F3: sendSMTP has no dial or IO timeout, and /mail/test has no rate limit. Its raw error text also works as a port-scan oracle.
  • F4 (functional): PUT /mail always returns 500 on SQLite, because the kvSet upsert reuses ph(2). The PR's mail test should expect 200.
  • F5: the comment in web/app/(app)/layout.tsx claims the server refuses an impersonated session, which is not true (see F1).
  • F6: httpErrorFrom and testMail show raw server or SMTP error text.
  • F7: the generic admin client sends no CSRF header and has no allowlist on the [resource] route parameter.

What passed

  • Dependency: auth is v0.10.0 (38aea0d) with no replace, and go mod verify passes.
  • Promotion confirmation: no bypass found. Double submission, stale confirmations, a changed 409 and a malformed 409 are all handled.
  • Errors: both 403 kinds and the 429 are handled, and nothing is auto-retried.
  • Mail routes: admin status is revalidated against the database. A demoted admin gets 403 and a deleted admin gets 401 on an earlier-issued token. Confirmed on SQLite and Postgres.
  • Real-kernel integration: 409, 403 and 429 are real responses, and a mutation check made the tests fail as expected.
  • Web: 44 out of 44 tests pass, lint/typecheck/build are clean, and npm audit reports 0 vulnerabilities.
  • Evidence: dashboard-review3.patch and threat-model/dashboard3-review.md, both kept outside the repo.

FAIL. The release gate is stopped. No merge, tag or deployment was performed.

🤖 Generated with Claude Code

fadymondy and others added 5 commits October 8, 2026 10:59
…laceholder)

kvSet bound placeholder 2 twice, which on drivers with positional ? placeholders
means three binds for two arguments ("missing argument with index 3"). Use
excluded.v, valid on SQLite and PostgreSQL. Successful PUTs are now asserted as
exactly 200.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…tion

PUT /mail kept the stored password for a blank or masked value even when the
host changed, so POST /mail/test then sent it to the new host. Retain it only
when host, port, username and TLS mode are unchanged; otherwise answer 400
before anything is written. A config without a username sends no credentials,
so the old password is dropped instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
auth's RequireRole only checks the role, so with AUTH_ADMIN_CROSS_CONTROL=true a
borrowed admin session reached the SMTP routes. Add a guard after it that
mirrors auth's requireAdmin: impersonated and PAT callers get 403.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…il routes

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@fadymondy

Copy link
Copy Markdown
Contributor Author

dashboard#3 contained fixes (F2, F4, F1): PASS on af25dc4

Head: af25dc472ebc07113a2c7c4962de07c39db9c0db. CI passes (go, web). Nothing has been merged, tagged or deployed.

Fixes

Commit Fix
352f495 F2: the stored SMTP password is kept only while host, port, username and security mode are unchanged. Host comparison ignores case and surrounding whitespace, and port 0 is treated as 587. If any of these change and the request sends no password (or the mask), the server returns 400 with "password required when changing SMTP host, port, username or security" and writes nothing. Changing only From keeps the password. A new config with no username sends no credentials, so the old password is dropped and is not carried forward to a later change.
F4: the root cause was the upsert DO UPDATE SET v=ph(2), which reused a placeholder: SQLite's positional ? then needed 3 arguments where 2 were bound. It now uses SET v=excluded.v, which works on both SQLite and Postgres.
2fd4a79 F1: refuseBorrowedAdmin, placed after RequireRole("admin"), applies the same check as auth's own requireAdmin (Impersonator != "" or Guard == "pat" gets 403). Auth itself is unchanged.
894d350 F5: the layout.tsx comment is corrected. It is a comment-only change.
af25dc4 Adds a test that an admin's PAT is refused on every mail route. Auth already gives a PAT no account roles, so RequireRole refuses it first and the dashboard check is a second layer.

Tests

  • Go: 19 tests pass on SQLite and on Postgres (-tags dashpg, throwaway DB). There are no skips. go vet and go mod verify are clean.
  • New regression tests:
    • A PUT that changes host, port, username or security without a password returns 400, and the stored row is byte-identical afterwards.
    • Keeping the same connection keeps the password, and a new password is stored.
    • Mail test-send after a rejected PUT never sends the old password to the new host.
    • The first insert and the upsert both return exactly 200 on every driver.
    • An impersonated admin under AUTH_ADMIN_CROSS_CONTROL=true gets 403, while normal admins get 200.
    • An admin PAT gets 403.
  • Assertions: the demoted-admin pre-check went from "not 401/403" to exactly 200. No assertion was weakened.
  • Web: lint, typecheck, build and 44/44 tests pass.

Independent scoped review (security-engineer, not the author): PASS, no Medium or higher

  • F2: it held up against normalization tricks (case, whitespace, trailing dot, IP, port default, Secure toggle, mask, missing fields) and against two-step sequences.
  • Mutation testing: neutering sameConnection or the impersonation check makes the tests fail.
  • Its one Low ("PAT branch untested") was based on a mistaken premise. Auth v0.10.0 revalidate(keepGrants=true) gives PATs no roles. The PAT refusal is now pinned end-to-end in af25dc4, which changes tests only, and every Go gate and CI was rerun on it.

Dependency

togo v0.21.0 is required. auth v0.10.0's go.mod requires togo v0.21.0 (go mod graph), so minimal version selection forces it. It is kept.

Remaining findings (non-blocking, owner-deferred)

These are tracked in dashboard#4:

  • F3: no SMTP timeout or rate limit.
  • F6: raw error text is shown.
  • F7: the admin client has no CSRF header or resource allowlist.
  • Three Info notes.

PASS — dashboard#3 is ready for human merge/tag approval. No merge, tag or deployment performed.

🤖 Generated with Claude Code

@fadymondy
fadymondy merged commit 570ae80 into main Oct 8, 2026
2 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.

Release v0.9.0: Nasaq 1.x dashboard, CI restored, admin API contract, flow tests

1 participant