Skip to content

fix(bridge): fail closed when no API token is set - #67

Open
KazKozDev wants to merge 1 commit into
mainfrom
fix/security-defaults
Open

KazKozDev wants to merge 1 commit into
mainfrom
fix/security-defaults

Conversation

@KazKozDev

Copy link
Copy Markdown
Owner

What this changes

The bridge no longer runs unauthenticated by default. Without WEBOPERATOR_API_TOKEN it uses a token in ~/.weboperator/bridge-token (mode 0600, created on first start). The MCP server, the agent client and the live scripts read the same file, so MCP setups keep working with no new config.

Why

WEBOPERATOR_ALLOW_UNAUTHENTICATED_BRIDGE was read as !== '0', so the bypass was on unless explicitly disabled. That is the opposite of docs/api.md. With no token, any local process, or any web page sending a text/plain POST to 127.0.0.1:8765 (a simple request, so no CORS preflight), could call browser_eval, cookies_get or weboperator_execute_goal against the user's logged-in browser.

  • Only WEBOPERATOR_ALLOW_UNAUTHENTICATED_BRIDGE=1 turns auth off now, for development.
  • Tokens are compared in constant time.
  • The file is written to a temp path and linked into place, so a bridge and an MCP server starting at the same time never read a half-written token.
  • install.sh creates the token and prints its path, not the secret.

Breaking for plain HTTP clients: curl or scripts against /v1/* must now send Authorization: Bearer $(cat ~/.weboperator/bridge-token).

How it was verified

  • ./scripts/check.sh passes locally (419 unit tests, bridge and MCP smoke)

  • bridge-smoke.mjs now starts a bridge with no token and no bypass. It checks:

    • authRequired: true;
    • a 401 on GET and on a text/plain POST;
    • that the token file has mode 0600 and that its token passes auth.

    Against the old bridge.js this test fails.

  • Loaded core/dist in Chrome and ran the affected flow by hand: not done. The installed native host needs install.sh re-run.

Checklist

  • One concern per PR — no unrelated refactors bundled in
  • Commit messages follow Conventional Commits
  • Docs updated (README, docs/api.md, docs/agent-protocol.md, docs/requirements.md, bridge README)
  • CHANGELOG.md updated under Unreleased

Security-sensitive areas

  • weboperator-bridge parsing, binding, or authentication

🤖 Generated with Claude Code

WEBOPERATOR_ALLOW_UNAUTHENTICATED_BRIDGE defaulted to on (`!== '0'`), so a
bridge started without WEBOPERATOR_API_TOKEN accepted every HTTP and socket
call — the opposite of docs/api.md. Any local process, or a web page posting
text/plain to 127.0.0.1:8765 (no CORS preflight), could drive the browser.

The bridge now falls back to ~/.weboperator/bridge-token (0600, created on
first start, linked into place atomically). mcp-server.js, agent-client.js
and the live scripts read the same file, so MCP setups need no new config.
Only WEBOPERATOR_ALLOW_UNAUTHENTICATED_BRIDGE=1 turns auth off. Token
comparison is constant-time. install.sh creates the token and prints its path.

bridge-smoke.mjs now starts a bridge with no token and no bypass and checks
401s (including a text/plain POST), the file's mode, and that the file token
passes auth. It fails on the old default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-22T10:19:52.555456Z
We couldn’t complete this review. Comment @codex review to try again.
a9d9fe1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Comment thread scripts/bridge-smoke.mjs
assert.equal(noPreflight.status, 401);
const tokenFile = path.join(defaultHome, '.weboperator', 'bridge-token');
assert.equal(statSync(tokenFile).mode & 0o777, 0o600);
const fileToken = readFileSync(tokenFile, 'utf8').trim();
Comment thread scripts/bridge-smoke.mjs
assert.equal(statSync(tokenFile).mode & 0o777, 0o600);
const fileToken = readFileSync(tokenFile, 'utf8').trim();
assert.match(fileToken, /^[0-9a-f]{64}$/);
const withFileToken = await fetch(`${unauthBase}/v1/browser/snapshot`, { headers: { authorization: `Bearer ${fileToken}` } });
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.

2 participants