Skip to content

web: ask for a fresh code when a step-up window has passed (§7.3 rule 6) - #28

Merged
Yoshiofthewire merged 16 commits into
mainfrom
kyguard/web-restepup
Nov 26, 2026
Merged

Yoshiofthewire merged 16 commits into
mainfrom
kyguard/web-restepup

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: When a privileged action is refused because its five-minute step-up window has passed, the web shell now asks for an authenticator code and sends the action again, instead of only showing the error.

What changed

  • secureFetch recognizes a 403 stepup_stale and asks the shell for a code through one registered prompt.
  • A new ReStepUp dialog posts the code to /api/auth/stepup/totp. On success the original request is sent once more; on cancel the caller gets the 403 as before.
  • Every other 403 goes straight to the caller.
  • web/dist rebuilt with Node 26 (CI's NODE_VERSION).

Review this

  • web/src/api.ts: the retry. It runs once, and only for stepup_stale.
  • Safe to skip: web/dist (generated; CI's dist check covers it).

Checked: npm test (46 tests), npm run build (dist matches; the base rebuilt byte-identical with this toolchain first), npm run audit (0 vulnerabilities), npm run test:browser (8 passed, 4 skipped by the spec's own conditions) on Major, Node 26.13.1. Two mutations fail their tests (below).
Not checked: the Go suite at this head. Its Go code is identical to #27's head, which passed race and FIPS on both drivers; only web/dist differs.
You need to: review. Held unmerged by rule.

§13 Phase 0: the web half of per-action step-up (§7.3 rule 6), left over from #17/#18.

Review fix (8e9b4b9): concurrent stale refusals share one dialog and all hear its answer; unmounting with the prompt open resolves them as cancelled (Guide). Re-checked at 8e9b4b9: 48 unit tests, build, audit, browser suite (8 passed, 4 skipped).

Review fix, round 2: a lost connection on the code request shows a retryable error, and the open dialog makes the shell inert and returns focus on close (Guide). Re-checked at this head: 50 unit tests, build, audit, browser suite (8 passed, 4 skipped).

Detail

Mutation table

# Property Mutation Failing test
W1 The action goes through after a fresh code return the refusal instead of retrying asks for a fresh code on stepup_stale and sends the action again
W2 Only stepup_stale prompts prompt on any 403 does not prompt for any other 403
W3 Every concurrent waiter is answered keep only the last waiter answers every action refused while the prompt was open
W4 Unmount cancels an open prompt skip resolving on unmount returns the refusal when the shell goes away with the prompt open
W5 A lost connection is reported, retryably drop the catch shows a retryable error when the server cannot be reached
W6 The shell is inert behind the dialog skip inert keeps the shell inert while open and gives focus back on close

Stack

… → #26 → #27 → this.

Review fix, round 3 (hawthorn fix-auth-3): the shell unmounting while a 403 body is still being read no longer throws a TypeError: secureFetch takes the registered prompt after parsing, and with none it returns the 403 (Guide, "Unmount race"). This head also merges kyguard/cli-login, which carries #7's fail-closed SSO sign-in up the stack; that merge clears this PR's conflict.

# Property Mutation Failing test
W7 An unmount during parsing returns the refusal call the handler read before parsing (the old code) returns the refusal when the shell goes away while the refusal is being read (TypeError: reStepUp is not a function)

Re-checked at this head on Major, Node 26.13.1: 51 unit tests, npm run build (committed dist matches), npm run audit (0 vulnerabilities), npm run test:browser (8 passed, 4 skipped by viewport), make smoke, make notes-check, make tidy-check, reuse lint. Go suite: race and FIPS suites, PostgreSQL 17 on k80 (14/14 packages, exit 0) and SQLite on Major (every K host was busy; exit 0).

Round 4 (hawthorn): stack merged up from main

Round 4b (hawthorn): Guide "Blocked cancellation"

  • Cancel is always enabled. It aborts the in-flight /api/auth/stepup/totp check through an AbortController, and an aborted check shows no error. A stalled request therefore cannot leave the shell inert.
Property Mutation Test Result
A stalled code check can be cancelled the old ReStepUp.tsx (Cancel disabled while busy, no abort) ReStepUp.test.tsx "cancels a stalled code check" fails

Checks at 6f23507: web build, unit 54/54 and audit (0 vulnerabilities), all on Node 26.13.1. Go code is unchanged since f018d93, whose race + FIPS suites passed on SQLite (k80) and PostgreSQL 17 (own container).

Round 4c (hawthorn): Guide "Cancellation race"

  • Each code submission changes the dialog (error, code, busy) only while it is still the current one, and the check is repeated after the refusal body is read. Cancelling resets busy itself. A cancelled check that finishes late therefore cannot touch a prompt opened after it.
Property Mutation Test Result
A late, cancelled check cannot touch the next prompt drop the recheck after the body read "ignores a cancelled check that finishes after a new prompt opened" fails (the new prompt's code is erased)
The same the previous ReStepUp.tsx same test fails (Confirm stays disabled: the stale submission holds busy)

Checks at this head: web build, unit 55/55 and audit (0 vulnerabilities), all on Node 26.13.1. Go code is unchanged since f018d93; its race + FIPS suites passed on SQLite (k80) and PostgreSQL 17 (own container).

Round 4d (hawthorn): CI flake in the inert test

  • CI at 3b77a5d failed keeps the shell inert while open and gives focus back on close (origin.inert undefined). inert was set in a passive useEffect, which can run after the dialog is already in the DOM. That leaves a short window where the shell behind is still usable, and a race in the test. It is now a useLayoutEffect, so inert is applied in the same commit that shows the dialog.
  • Unproven locally: the failure never reproduced on Major, before or after the change. The ReStepUp suite passed 8 of 8 consecutive runs, and build, unit 55/55 and audit all pass (Node 26.13.1). CI at this head is the real check.

Round 4e (hawthorn): main (#8) merged up

Round 6 (hawthorn): main (#11) merged up; Guide "Focus trap"

  • dbb8d5d merges origin/main (37b302b, through Broker journal and rotation state machine (§4.2, §4.3, §4.6) #11). It merged cleanly, with no web change from main.
  • 67b6acd: inert kept focus off the shell but not out of the browser chrome. The dialog now handles Tab on its last control (Cancel) and Shift+Tab on its first (the code input) by moving focus to the other end. Focus moves between those two normally. web/dist was rebuilt with Node 26.13.1.
Property Mutation Test Result
Tab and Shift+Tab stay inside the dialog drop onKeyDown={wrapTab} ReStepUp.test.tsx "wraps Tab and Shift+Tab inside the dialog" fails
The same, in real Chromium (production server and CSP) same mutation, dist rebuilt ad-hoc Playwright spec: 5 Tabs then 5 Shift+Tabs from the code input fixed: focus cycles input → Confirm → Cancel → input both ways. Mutated: focus leaves to the document body (and on to the browser chrome)

The Chromium check is not committed. No route in Phase 1A has a step-up window yet, so the only way to reach the dialog is to stub one stepup_stale refusal (page.route), and web/browser/AGENTS.md bars mocked responses in that suite. The unit test is the committed regression.

Checks at 67b6acd (Node 26.13.1): unit 56/56, npm run build (committed dist matches), npm run audit (0 vulnerabilities). The Go code is unchanged from dbb8d5d, where gofmt, go vet, and go test -race -count=1 -p 2 ./... plus the same under GODEBUG=fips140=on passed: SQLite on Major (every K host was busy; exit 0) and PostgreSQL 17 on k80 (exit 0). The full Playwright suite was not run locally this round; CI runs it.

🤖 Generated with Claude Code

A privileged action refused with 403 stepup_stale now opens a dialog
for an authenticator code, refreshes the step-up through
/api/auth/stepup/totp and sends the action once more; cancelling
returns the refusal. Any other 403 is untouched. web/dist rebuilt with
Node 26 (CI's NODE_VERSION).

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

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyguard-server-28, where it is readable by the operator and expires seven days after the last post.

Review input was truncated; omitted changes were not reviewed.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

PR Reviewer Guide: a second stale refusal replaced the first waiter, so
the first action never settled, and unmounting the shell with the
prompt open left its caller pending. Concurrent refusals now share one
dialog and all resolve with its answer; unmounting resolves them as
cancelled (the original 403). web/dist rebuilt with Node 26.

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

Copy link
Copy Markdown
Member Author

Guide (lost requests; unresolved cancellation) fixed in 8e9b4b9: concurrent stepup_stale refusals share one dialog and every waiter gets its answer; unmounting ReStepUp resolves open prompts with false, so callers get the original 403. Two new tests, each failing under its mutation (keep only the last waiter; skip the unmount resolve).

PR Reviewer Guide: a transport failure on the code request now shows a
retryable error instead of escaping, and while open the dialog makes
the shell behind it inert and gives focus back on close. web/dist
rebuilt with Node 26.

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

Copy link
Copy Markdown
Member Author

Guide (unhandled failure; modal focus) fixed in 69b74b0: a transport error on the code request shows a retryable error in the dialog, and while open the dialog marks the shell behind it inert and restores focus to the initiating control on close. Two tests, each failing under its mutation.

Yoshiofthewire and others added 4 commits November 25, 2026 09:30
…) into kyguard/web-restepup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
secureFetch checked the registered ReStepUp prompt before reading the
403 body. If the shell unmounted while the body was being parsed, the
prompt was null by the time it was called, and the action rejected with
a TypeError instead of receiving its 403. It now takes the prompt after
the body is read and returns the refusal when there is none (PR
Reviewer Guide, "Unmount race").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Picks up the stack's merge commits as pushed. No content change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings #17's step-up retry and #18/#25 fixes up. web/dist rebuilt from
the merged sources with Node 26.13.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire and others added 6 commits November 25, 2026 16:09
Cancel stayed disabled while the code check was in flight, so a stalled
request left the shell inert with no way out. Cancel is now always
enabled and aborts the in-flight check; an aborted check shows no error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings #17's blocked-enrollment notification fix up. web/dist rebuilt
from the merged sources with Node 26.13.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A cancelled check whose refusal body arrived late could clear the next
prompt's code, show its error and re-enable Confirm mid-check. Each
submission now changes the dialog only while it is still the current
one, and cancelling resets busy itself. web/dist rebuilt (Node 26.13.1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A passive effect set inert after the dialog was already in the DOM: a
brief window where the shell behind stayed usable, and a CI flake in the
inert test. A layout effect applies it in the same commit. web/dist
rebuilt (Node 26.13.1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire
Yoshiofthewire changed the base branch from kyguard/cli-login to main November 26, 2026 00:00
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Merger (saltmarsh-merge): closing and reopening right away so CodeQL runs now that the base is main. The branch is unchanged.

Inert keeps focus off the shell behind the dialog, but Tab from Cancel
(or Shift+Tab from the code input) still left the page for the browser
chrome. The dialog now wraps focus at its first and last controls.
Fixes the PR Reviewer Guide's "Focus trap" note on #28.

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

Copy link
Copy Markdown
Member Author

Fixed the Guide's Focus trap note in 67b6acd. The dialog now wraps Tab at Cancel and Shift+Tab at the code input. ReStepUp.test.tsx "wraps Tab and Shift+Tab inside the dialog" fails without the handler. A real-Chromium check against the production server showed focus leaving the dialog without the fix and cycling with it (details in the body, round 6). This head also merges main through #11.

@Yoshiofthewire
Yoshiofthewire merged commit e8ac5e3 into main Nov 26, 2026
16 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.

1 participant