Skip to content

fix(security): harden browser API auth, token comparisons, and hook tokens#14197

Open
leecarollyn-gif wants to merge 2 commits intoopenclaw:mainfrom
leecarollyn-gif:main
Open

fix(security): harden browser API auth, token comparisons, and hook tokens#14197
leecarollyn-gif wants to merge 2 commits intoopenclaw:mainfrom
leecarollyn-gif:main

Conversation

@leecarollyn-gif
Copy link

@leecarollyn-gif leecarollyn-gif commented Feb 11, 2026

Summary

  • Extract safeEqual() to shared utility (src/security/safe-equal.ts) for constant-time string comparison, replacing the local copy in gateway/auth.ts
  • Fix 7 timing-unsafe token comparisons across gateway hooks, device/node pairing, bridge server, and extension relay using the shared safeEqual
  • Add Bearer token auth + Host header validation to browser control API — secure by default with auto-generated token; opt-out via browser.auth.enabled: false
  • Add hooks.allowQueryToken config flag to control query-string token acceptance (default true for backward compat, with Deprecation header and migration path to false)
  • Add security guardrails to AGENTS.md — document safeEqual usage, browser auth config, hook token security, and DNS rebinding protection patterns

Based on a Codex CLI security audit that identified three categories of vulnerability:

  1. Unauthenticated browser control API with ~30+ mutation endpoints (Medium)
  2. Hook auth token accepted via query string leaking in logs/referrers (Medium)
  3. Non-constant-time token comparisons in 7 locations (Low)

Test plan

  • pnpm build passes
  • pnpm check passes (type-check + lint + format)
  • All 169 browser tests pass (28 test files)
  • All hooks tests pass (5/5)
  • All device/node pairing tests pass
  • New safeEqual unit tests pass (5/5)
  • Existing browser test mocks updated with auth: { enabled: false }
  • AGENTS.md guardrails added for future contributors

🤖 Generated with Claude Code

Greptile Overview

Greptile Summary

This PR strengthens several auth-related surfaces:

  • Introduces a shared safeEqual() helper for timing-safe string comparisons and replaces direct === token checks across gateway hooks, pairing flows, browser bridge/relay, and gateway auth.
  • Secures the browser control API by default with Bearer token auth (auto-generated token unless configured) and adds Host header validation to reduce DNS rebinding exposure.
  • Adds hooks.allowQueryToken to control whether hook tokens are accepted via query string, with deprecation messaging to encourage moving to header-based auth.

Overall, the changes align with existing gateway auth patterns and tighten local control surfaces, but there is a correctness bug in the new browser Host validation (see comment).

Confidence Score: 3/5

  • This PR is close to safe to merge but has a loopback Host validation bug that can break legitimate IPv6 local access to the browser control API.
  • Most changes are localized and add security hardening with minimal behavioral impact, but the new Host header allowlist in the browser server will incorrectly reject standard bracketed IPv6 hosts with ports (e.g. [::1]:<port>), which can cause 403s for valid requests until fixed.
  • src/browser/server.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

…okens

- Extract safeEqual() to shared src/security/safe-equal.ts utility
- Replace 7 timing-unsafe token comparisons with constant-time safeEqual
  (gateway hooks, device pairing, node pairing, bridge server, extension relay)
- Add Bearer token auth + Host header validation to browser control API
  (secure by default with auto-generated token, opt-out via browser.auth.enabled)
- Add hooks.allowQueryToken config flag to control query-string token acceptance
  (default: true for backward compat, deprecation path to false)

Based on Codex security audit findings.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@openclaw-barnacle openclaw-barnacle bot added gateway Gateway runtime agents Agent runtime and tooling labels Feb 11, 2026
Add guidelines for timing-safe token comparison (safeEqual), browser
control API auth, hook token security, and DNS rebinding protection.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

20 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +30 to +33
// Host header validation (DNS rebinding protection)
app.use((req, res, next) => {
const host = (req.headers.host ?? "").replace(/:\d+$/, "").toLowerCase();
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

IPv6 Host parsing bug

(req.headers.host ?? "").replace(/:\d+$/, "") won’t strip the port for bracketed IPv6 hosts (e.g. Host: [::1]:18789), so host becomes "[::1]:18789" and the allowlist check will always 403. This breaks legitimate loopback requests on IPv6. Consider parsing bracketed IPv6 + optional port (or reusing the existing getHostName() helper from src/gateway/auth.ts) before comparing against the allowlist.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/browser/server.ts
Line: 30:33

Comment:
**IPv6 Host parsing bug**

`(req.headers.host ?? "").replace(/:\d+$/, "")` won’t strip the port for bracketed IPv6 hosts (e.g. `Host: [::1]:18789`), so `host` becomes `"[::1]:18789"` and the allowlist check will always 403. This breaks legitimate loopback requests on IPv6. Consider parsing bracketed IPv6 + optional port (or reusing the existing `getHostName()` helper from `src/gateway/auth.ts`) before comparing against the allowlist.

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments