Commit Graph
1 Commits
Author SHA1 Message Date
0ffe305a62 fix(api): a second route shipped the user's credential hashes — and the gate that ends the class (#309)
* fix(api): a second route was shipping the user's credential hashes

POST /api/onboarding returned the whole users row — `{ ok: true, user }` —
so passwordHash and privateZonePinHash went to the browser on every
onboarding finish, exactly as GET /api/me did before #306. The client never
read that object; it checks `res.ok` and nothing else.

It survived the grep that found #306 only because it was nested one level
deeper (`json({ ok: true, user })`, not `json(user)`). That is the second
instance of one class, so this stops being something to grep for:

- scripts/test/no-raw-user-response.ts scans every route handler and server
  action, taints identifiers bound to a whole users row, and fails if one
  reaches a response call unprojected. Negative-tested against the real
  pre-fix source — it flags both branches — plus 13 fixtures covering the
  nested, shorthand and spread forms.

And the export had grown a second answer to the same question:

- src/lib/account-export.ts kept its own REDACTED_USER_FIELDS deny-list, so
  a secret column added later would be withheld by /api/me (allow-list) and
  shipped by /api/me/export (deny-list that never heard of it). Both now
  project through user-client-view.ts, which is exhaustive over the schema.
  The export additionally omits Stripe ids — a policy narrowing of the
  allow-list, not a second notion of what is secret.
- buildExportManifest generates its `excluded` lines from those same lists,
  so the document describing what was withheld cannot drift from what was,
  and the test asserts the linkage rather than a copy of the wording.

Verified: tsc clean, eslint 0 errors, 88/88 unit files, design-system ok.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(ci): the deploy-ref fixtures inherited a handle to the real repo

The husky pre-push hook exports GIT_DIR — for a worktree push that is
.git/worktrees/<name>, the real repository. scripts/test/deploy-ref-gate.sh
runs from that hook, so every git call in the fixture suite inherited it.

An explicit GIT_DIR is not a search path, so GIT_CEILING_DIRECTORIES (guard 1)
did not constrain it, and the g() assertion (guard 2) could not see it either:
with GIT_DIR set and no work tree, `git -C <fixture> rev-parse --show-toplevel`
answers `<fixture>` — matching exactly, while objects and refs land in the real
repo. The suite this file was written to make safe was, from a hook, pointed
back at the thing it must never touch.

Guard 5 ($TMP must not be inside a repo) is what actually held the line, and it
held it by failing closed: with GIT_DIR set, an empty mktemp dir reads as a repo
root, so every push from a worktree died with "temp dir is inside a git repo" —
a true refusal with a misleading reason, and no way to push at all.

Now the ambient git environment is cleared first, from `git rev-parse
--local-env-vars` so it cannot fall behind a new variable. Test 9 re-runs the
whole suite with GIT_DIR pointing at a decoy repo and asserts both that it
passes and that the decoy is unchanged.

Verified to bite: with the unset removed, test 9 fails and the child run dies at
guard 5 exactly as the real push did.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* refactor(ci): one definition of an isolated git fixture

not-behind-gate.sh has the same inherited-GIT_DIR hole the previous commit
fixed in deploy-ref-gate.sh — and found it itself: run from the pre-push hook,
its own isolation probe reported "g() accepted a non-repo dir nested in a repo
— it would have mutated the ENCLOSING repo". Correct, and it was right.

Fixing it in place would have been the third copy of the same paragraph. The
copies are the hazard: both suites carry scars from 2026-08-15, each was
hardened against what its own incident taught it, and neither against the
other's — deploy-ref-gate knew $TMP must not sit inside a repo, not-behind-gate
knew a fixture must never write git config. A third suite would have copied
whichever file it sat next to.

So the four properties that must hold before a fixture touches git now live in
scripts/test/lib/git-fixture-env.sh, sourced by both. Each suite keeps its own
g() — the per-command assertion that the directory about to be mutated is the
fixture — because their fixture shapes genuinely differ.

Verified under the real hook environment (GIT_DIR=.git/worktrees/<name>):
deploy-ref-gate 9 passed, not-behind-gate 15 passed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-16 09:41:51 +00:00