Skip to content

Require auth on sensitive endpoints, add single-flight task guard, clipboard fallback, and token fingerprinting#42

Open
AmrDab wants to merge 1 commit intov0.7.1from
codex/conduct-complete-codebase-audit-z6aiku
Open

Require auth on sensitive endpoints, add single-flight task guard, clipboard fallback, and token fingerprinting#42
AmrDab wants to merge 1 commit intov0.7.1from
codex/conduct-complete-codebase-audit-z6aiku

Conversation

@AmrDab
Copy link
Owner

@AmrDab AmrDab commented Mar 19, 2026

Motivation

  • Protect sensitive/read-only endpoints from unauthenticated access by enforcing the existing Bearer token requirement.
  • Avoid leaking full auth tokens to stdout while still giving operators a short reference to connect tools.
  • Prevent race conditions from concurrent /task requests by making task execution single-flight per Agent instance.
  • Make text typing more robust in environments where the clipboard bridge is unavailable.

Description

  • Added requireAuth to several endpoints in src/server.ts including GET /favorites, GET /task-logs, GET /task-logs/current, GET /logs, GET /screenshot, and the POST /action path so mutating and sensitive read routes require the Bearer token.
  • Introduced tokenFingerprint() in src/index.ts and replaced full-token logging with a short fingerprint when starting the API and tool servers, while keeping the full token saved to ~/.clawdcursor/token.
  • Added a synchronous single-flight guard to Agent.executeTask by introducing taskRunning and checking/setting it around task execution, and moved initial state setup earlier; taskRunning is always cleared in a finally block.
  • Updated ActionRouter.handleType to catch clipboard bridge failures and fall back to desktop.typeText(text) instead of failing the entire action.
  • Adjusted tests and test configuration: added tsconfig.tests.json, added typecheck and typecheck:tests scripts to package.json, extended vitest.config.ts to include tests/**, and updated tests/smoke.test.ts to use initServerToken() and a withAuth helper for authenticated requests; also tweaked an OCR unit test expectation.

Testing

  • Ran unit/integration tests with npm test (Vitest); the test suite including updated smoke tests completed successfully.
  • Ran type checks for tests with npm run typecheck:tests (uses tsc --noEmit -p tsconfig.tests.json) and npm run typecheck (tsc --noEmit) locally; both passed.

Codex Task

AmrDab added a commit that referenced this pull request Mar 19, 2026
Cherry-picked the best of both Codex audit PRs into a unified build:

Security:
- Log sanitization: API keys, Bearer tokens redacted from task logs
  (opt-out with CLAWD_DEBUG_RAW_LOGS=1)
- Token fingerprinting: startup prints first 8 chars, not full token
- Auth on sensitive GET endpoints: /favorites, /task-logs, /logs now
  require Bearer token (dashboard updated to include auth on all calls)

Reliability:
- Task execution lock: prevents TOCTOU race on concurrent /task requests
- Clipboard fallback: catches a11y bridge failure, falls back to typeText
- OCR temp file UUID suffix: prevents collision on concurrent OCR calls

Infrastructure:
- CDP port DRY: unified to 9223 everywhere (was 9222 in some, 9223 in
  others — real mismatch causing connection failures)
- ESLint: Node.js + vitest globals, relaxed no-explicit-any
- Test infra: tsconfig.tests.json, vitest covers tests/, withAuth helper
  new smoke tests for auth-protected endpoints
- Install robustness: verify-install.js checks Node version + native deps
  with platform-specific fix guidance (addresses Dabbas install failure)

17 files modified, 2 new files. Build passes. 130/131 tests pass
(1 pre-existing credential test failure unrelated to these changes).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant