Skip to content

feat(compat): the auth stage, S03 to S06: CSRF token, email-check, sign-up and sign-in as JSON - #80

Merged
aRustyDev merged 1 commit into
mainfrom
feat/compat-auth-stage
Oct 24, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
feat/compat-auth-stage

Conversation

@aRustyDev

@aRustyDev aRustyDev commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

What

Second of nine PRs for #44. The four /auth/ routes the stock sign-up and sign-in pages call, as the JSON contract Thrust's copy of the React auth client will use (D-022):

Row Route Answer
S03 GET /auth/get-csrf-token/ {"csrf_token"} and the CSRF cookie
S04 POST /auth/email-check/ {"existing", "status": "CREDENTIAL"}, or Plane's 400 EMAIL_REQUIRED / INVALID_EMAIL
S05 POST /auth/sign-up/ 200 {"redirect_path"} and the session cookies, or 400 with error_code, error_message, email
S06 POST /auth/sign-in/ the same shape, 429 for the rate limit

Plane's order of checks is kept (required, valid email, taken, strong password), and the fixtures pin it with exchanges that have two faults at once.

Underneath: core gets sign_up, email_exists, is_valid_email and password_is_strong. The ports and both adapters get insert_user (a taken email or id is a Conflict from the unique index). thrust-api makes its cookie helpers public so the compat routes spell the cookies the same way.

Owner decisions needed

Both are recorded as deviations and marked pending owner confirmation:

  • D-022, the JSON contract. The change itself is yours (Q-0009.1). The details are mine: 200 {"redirect_path"} on success, 400 (429 for 5900) with the pin's error dict on failure, and a stricter next_path that is percent-encoded when kept (the pin writes it into the query raw, so a & or # corrupts the query). This is the contract PR 8 (the React client change) will code against.
  • D-023, the password rule. At least 10 characters, at least 5 distinct, and not one of about 40 common passwords once the decoration is stripped, in place of Plane's zxcvbn score of 3. I did not measure zxcvbn's size in the Worker bundle; that is the reason I did not take it. Adopting the zxcvbn crate is the alternative.

Gaps you should know about (G-16)

  • No per-address limit. The pin throttles email-check, sign-in and sign-up to 10 a minute per IP. Thrust keeps only sign-in's per-email limit, so sign-up and email-check are unthrottled, and email-check tells anyone whether an email has an account, as the pin does. Core never sees the address, and a global limit would let anyone lock everyone out.
  • A deactivated user's sign-in answers 5065, not 5019.
  • ENABLE_SIGNUP, magic-code and OAuth codes do not exist.
  • The redirect after sign-in is always the root until the boot stage adds the profile.

Controls (each shown failing)

Control Result
sign-up checks swapped (weak password before taken email) parity_s05_sign_up fails: recorded 5030, answered 5021
Postgres insert_user with ON CONFLICT DO NOTHING the model fails, shrunk to UserInsert{EmailTaken}: got Ok(()), want conflict
a router that strips Set-Cookie the cookie check reports a divergence
a recorded error code, a success, a next_path or a password changed in a fixture each is a divergence
tokio added to the compat crate scripts/check-deps.sh exits 1 (shown in #79; the crate is covered)

Mutation testing (cargo-mutants 27.1.0, nextest 0.9.140):

Scope Result
thrust-compat-plane 68 mutants: 54 caught, 14 unviable, 0 missed (first run: 4 missed)
thrust-core (--in-diff, the new code) 50 mutants: 49 caught, 1 unviable, 0 missed (first run: 3 missed)
memory adapter insert_user 3 of 3 caught

The first runs found seven real gaps: the || in both "required fields" checks (no exchange had one field present and one missing, so I recorded them), origin() for the base URLs (the normaliser erases them, so a hermetic test now sets Host and X-Forwarded-Proto), the exact-5-distinct-characters password boundary, a top-level domain with a digit, and a dead len > 4 clause that I removed. Not mutated: the Postgres adapter, which the generated model covers.

Recording

tools/compat-record/record.py now records the whole journey on a fresh stack, paced under the pin's throttle (about three minutes), and refuses a stack that has been used. tools/compat-record/fresh-oracle.sh recreates one (ORACLE_DIR points at the fork checkout; the pin tag is local to the fork). Recordings on two independent fresh stacks are byte-identical, which closes the gap I left open in #79.

The harness replays the journey in order and projects the pin's 302 onto Thrust's JSON by the rules in tests/common/mod.rs. A sign-in or sign-up that the recording says worked must set the session cookie, and one that failed must not.

Verified

  • cargo nextest run --workspace: 1228 passed.
  • scripts/contract.sh native-memory and native-pg: 44 of 44 (EXPECT_MAIN 39 to 44). The other two targets are for CI.
  • Postgres adapter and model: cargo nextest run --ignore-default-filter -E 'binary(pg_adapter)', 13 passed.
  • scripts/check-deps.sh: no forbidden dependency; cargo check -p thrust-worker --target wasm32-unknown-unknown: builds.
  • CI: all 28 reported checks pass and the PR is CLEAN, after one re-run of the mutants job. Its first run reported csrf-switch-ignored-when-off ... did not run (exit=4): contract.sh exit 4 means the target never became healthy or exited early, and the CI log does not show why. I could not reproduce it: the same mutant build (THRUST_SERVER_FEATURES=mutant_csrf_always scripts/contract.sh native-memory csrfoff) is killed locally (3 tests fail, exit 101), and the other eight mutants were killed in the failing run. I believe it was a startup flake (a random port in pick_port is one candidate), but I have not proved that. If it recurs, mutants.sh should keep the server log of a mutant that does not start.

Effort

Modelled for the rows (research/0003 §8.1): S03 0.3, S04 0.8, S05 1.5, S06 1.5, so 4.1 pd of auth-redirect, which the model prices as 302 emulation; this PR builds JSON instead, plus a use-case, an adapter method and a password rule the model excludes. I did not time the work, so there is no actual pd to report.

Refs: plane-byd.12.2

🤖 Generated with Claude Code

…gn-up and sign-in as JSON

Second stage of #44. The four /auth/ routes the stock sign-up and sign-in pages call, as the JSON contract Thrust's copy
of the auth client will use (D-022): a success is a 200 with {"redirect_path"} and the session cookies, a failure a 400
(429 for the rate limit) with Plane's error_code, error_message and email. Plane's order of checks is kept; the fixtures
pin it with two-fault exchanges.

Core gets sign_up, email_exists, is_valid_email and password_is_strong (D-023: a modest rule in place of zxcvbn, which
would put a dictionary in the Worker bundle). Ports and both adapters get insert_user: a taken email or id is a
Conflict from the unique index. The Postgres-vs-model sequences generate it (UserInsert, three new step classes).

The recorder now runs the whole journey on a fresh stack, paced under the pin's 10-a-minute throttle, and refuses a used
stack (tools/compat-record/fresh-oracle.sh recreates one). Recordings on two independent fresh stacks are byte-identical.
The harness replays the journey in order and projects the pin's 302 onto Thrust's JSON by rules it documents.

Controls shown red: swapping the taken-email and weak-password checks fails parity_s05 with "recorded 5030, answered
5021"; Postgres insert_user with ON CONFLICT DO NOTHING fails the model, shrunk to UserInsert{EmailTaken}; a router that
strips Set-Cookie fails the cookie check; mutated fixtures fail the projection. cargo-mutants: compat crate 54 caught, 14
unviable, 0 missed (4 missed on the first run, each fixed by a test or a recorded exchange); core's new code 49 caught, 1
unviable, 0 missed; memory insert_user 3 of 3. Not mutated: the Postgres adapter (covered by the generated model).

EXPECT_MAIN 39 -> 44, native-memory and native-pg 44/44; workspace nextest 1228 passed; worker wasm32 builds.

Refs: plane-byd.12.2
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev merged commit ad07a79 into main Oct 24, 2026
52 of 54 checks passed
@aRustyDev
aRustyDev deleted the feat/compat-auth-stage branch October 24, 2026 22:48
This was referenced Nov 15, 2026
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.

1 participant