Skip to content

Commit 14ff1de

Browse files
authored
fix: recognize 401 step-up-required on passkey enrollment denial (SUF-02) (#91)
The framework's stale/factorless-session denial on POST /webauthn/register changed in ds-spring-user-framework 5.3.4 from a bare 403 to a 401 carrying error code "step-up-required" (StepUpEnrollmentAccessDeniedHandler, library #371), matching the passkey delete/rename endpoints. webauthn-register.js only branched on 403, so against 5.3.4 a stale-session enrollment fell through to the generic "Failed to register passkey. Please try again." instead of the actionable "sign out and sign in again" message, and the chromium-step-up E2E (step-up-flow.spec.ts:320) failed. Recognize both: 403 (framework < 5.3.4) or 401 with error code "step-up-required" (5.3.4+) now raise PasskeyEnrollmentStepUpError. Backward-compatible, so the test passes whether the demo is pinned to 5.3.3 or bumped to 5.3.4. Verified locally against a 5.3.4-SNAPSHOT publishLocal build: chromium-step-up 8/8. Claude-Session: https://claude.ai/code/session_01KL5qvKVGQLLQDjHToy34vj
1 parent d7f83cc commit 14ff1de

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

‎src/main/resources/static/js/user/webauthn-register.js‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import { getCsrfToken, getCsrfHeaderName, base64urlToBuffer, bufferToBase64url }
77
* Raised when passkey enrollment is refused because the session lacks a recent authentication (SUF-02).
88
*
99
* With step-up enabled the framework gates POST /webauthn/register on a factor issued within
10-
* `enrollmentTtlSeconds`, enforced as an authorization rule that returns a plain 403 (not a
11-
* `step-up-required` 401). Re-running the passkey ceremony cannot satisfy it: the user may have no passkey
12-
* yet, and enrollment accepts any factor, so the remedy is a fresh login, not a ceremony retry.
10+
* `enrollmentTtlSeconds`. Framework versions before 5.3.4 denied with a plain 403; 5.3.4+ denies with a
11+
* 401 carrying error code `step-up-required` (StepUpEnrollmentAccessDeniedHandler), matching the sibling
12+
* credential-management endpoints. Re-running the passkey ceremony cannot satisfy it either way: the user
13+
* may have no passkey yet, and enrollment accepts any factor, so the remedy is a fresh login, not a
14+
* ceremony retry.
1315
*/
1416
export class PasskeyEnrollmentStepUpError extends Error {
1517
constructor() {
@@ -93,20 +95,23 @@ export async function registerPasskey(labelInput) {
9395
});
9496

9597
if (!finishResponse.ok) {
96-
// The enrollment step-up gate is an authorization rule, so a stale/factorless session is refused here
97-
// with a bare 403 rather than the step-up-required 401 the other operations return. Surface it as its
98-
// own error so the UI can tell the user to sign in again instead of offering a passkey retry.
99-
if (finishResponse.status === 403) {
100-
throw new PasskeyEnrollmentStepUpError();
101-
}
98+
// A stale/factorless session is refused by the enrollment step-up gate. Framework versions before
99+
// 5.3.4 denied with a bare 403 (an authorization rule with no body); 5.3.4+ denies with a 401
100+
// carrying error code "step-up-required". Recognize both, and surface it as its own error so the UI
101+
// can tell the user to sign in again instead of offering a passkey retry.
102102
let msg = 'Registration failed';
103+
let errorCode;
103104
try {
104105
const data = await finishResponse.json();
105106
msg = data.message || msg;
107+
errorCode = data.error;
106108
} catch {
107109
const text = await finishResponse.text();
108110
if (text) msg = text;
109111
}
112+
if (finishResponse.status === 403 || (finishResponse.status === 401 && errorCode === 'step-up-required')) {
113+
throw new PasskeyEnrollmentStepUpError();
114+
}
110115
throw new Error(msg);
111116
}
112117

0 commit comments

Comments
 (0)