Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,48 @@ export async function mapApiError(res: Response): Promise<CliError> {
return new PermissionError(cfg.activeWorkspaceSlug ?? '<unknown>');
}
if (res.status === 409) return new ConflictError(msg, code ?? 'CONFLICT');
// Phase 122 — bootstrap-code exchange error mapping.
// 404 and 410 collapse to the same user-facing message (oracle-attack
// defense — brute-force guessers can't distinguish "unknown code" from
// "already spent code"). ApiError.exitCode defaults to 1; we override
// to 5 on the instance so the CLI's exit-code contract stays honest
// ("API rejected the bootstrap code" is a distinct failure class).
if (res.status === 404 && code === 'BOOTSTRAP_NOT_FOUND') {
const err = new ApiError(
'Code invalid or already used. Ask the dashboard user to click Copy again.',
404,
);
err.exitCode = 5;
return err;
}
if (res.status === 410 && code === 'BOOTSTRAP_EXPIRED_OR_USED') {
const err = new ApiError(
'Code expired or already used. Ask the dashboard user to click Copy again.',
410,
);
err.exitCode = 5;
return err;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment on lines +99 to +114

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Unify 404/410 user-facing copy to preserve oracle-attack defense.

Line 94-96 says these statuses should collapse to the same message, but Line 101 and Line 109 currently differ (invalid vs expired), which leaks bootstrap-code state.

Proposed fix
+  const bootstrapCodeRejectedMsg =
+    'Code invalid or already used. Ask the dashboard user to click Copy again.';
+
   if (res.status === 404 && code === 'BOOTSTRAP_NOT_FOUND') {
-    const err = new ApiError(
-      'Code invalid or already used. Ask the dashboard user to click Copy again.',
-      404,
-    );
+    const err = new ApiError(bootstrapCodeRejectedMsg, 404);
     err.exitCode = 5;
     return err;
   }
   if (res.status === 410 && code === 'BOOTSTRAP_EXPIRED_OR_USED') {
-    const err = new ApiError(
-      'Code expired or already used. Ask the dashboard user to click Copy again.',
-      410,
-    );
+    const err = new ApiError(bootstrapCodeRejectedMsg, 410);
     err.exitCode = 5;
     return err;
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/api/client.ts` around lines 99 - 114, Both branches that check res.status
(404 with code 'BOOTSTRAP_NOT_FOUND' and 410 with code
'BOOTSTRAP_EXPIRED_OR_USED') return different user-facing strings and thus leak
bootstrap state; make the messages identical. Update the ApiError construction
in the 'BOOTSTRAP_EXPIRED_OR_USED' branch to use the same sentence as the
'BOOTSTRAP_NOT_FOUND' branch (the string passed to new ApiError) while keeping
the same status codes and err.exitCode assignments (leave ApiError, res.status
checks, and err.exitCode unchanged).

if (res.status === 429) {
// REUSE the existing ConflictError (exitCode 6) — output/error.ts has
// no dedicated rate-limit class, and inventing one here would fork the
// 7-code exit-code contract locked in Phase 108. The body.code
// 'RATE_LIMITED' matches the backend's UserIdThrottlerGuard structured
// 429 body.
return new ConflictError(
msg && msg !== 'Too Many Requests'
? msg
: 'Too many codes minted. Wait a minute and retry.',
'RATE_LIMITED',
);
}
if (res.status >= 500) {
return new ApiError('Something went wrong on our end. Try again later.', res.status);
}
return new ApiError(msg, res.status);
}

function isNetworkFailure(err: unknown): boolean {
export function isNetworkFailure(err: unknown): boolean {
if (err instanceof TypeError) return true;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const code = (err as any)?.code;
Expand Down
Loading
Loading