Skip to content

fix(companion): reject empty local token as auth bypass - #17

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-85ee
Draft

fix(companion): reject empty local token as auth bypass#17
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-85ee

Conversation

@cursor

@cursor cursor Bot commented Aug 21, 2026

Copy link
Copy Markdown

Bug and impact

WEBCHAIN_LOCAL_TOKEN="" (or localToken: "") was treated as a valid companion credential. ?? keeps empty strings, so a request with x-webchain-token: "" authenticated and could create browser sessions and run commands.

Trigger: set WEBCHAIN_LOCAL_TOKEN= (or pass localToken: "") and call POST /sessions with an empty x-webchain-token header. Missing headers still returned 401; the empty-to-empty match did not.

Root cause

Nullish coalescing does not fall through on "", so an empty env/option never reached the local-dev default and compared equal to an empty header.

Fix

Refuse to boot when the resolved token is empty or whitespace. Treat empty or whitespace headers as unauthenticated.

Tests

services/companion/src/server.test.ts covers empty header, empty/whitespace localToken, and empty WEBCHAIN_LOCAL_TOKEN. pnpm --filter @webchain/companion test and test:coverage passed (line coverage 94.66%, threshold 90).

Open in Web View Automation 

Nullish coalescing kept WEBCHAIN_LOCAL_TOKEN="" as a valid credential,
so an empty x-webchain-token header authenticated session and command routes.

Co-authored-by: esadrianno <esadrianno@gmail.com>
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