Conversation
Addresses five security issues identified in code audit:
1. Daemon Bearer-Token Authentication
- Generate crypto.randomBytes(32) token at startup
- Write to ~/.opencli/daemon.token (mode 0o600)
- Require Authorization: Bearer <token> on all non-/ping endpoints
- Constant-time comparison prevents timing side-channels
- daemon-client.ts lazily reads & caches token; auto-refreshes on 401
- Token file deleted on daemon shutdown
2. Extension ID Pinning (optional hardening)
- New OPENCLI_EXTENSION_ID env var for strict WebSocket origin check
- Rejects any chrome-extension:// origin that doesn't match the pin
3. HttpOnly Cookie Warning + Redaction
- OPENCLI_VERBOSE=1 emits warning when httpOnly cookies are returned
- OPENCLI_REDACT_COOKIES=1 or getCookies({ redact: true }) replaces
httpOnly and sensitive-named cookie values with '[REDACTED]'
- New isSensitiveCookieName() / redactCookies() helpers in types.ts
4. CDP Endpoint Localhost Enforcement
- assertLocalhostEndpoint() blocks non-loopback OPENCLI_CDP_ENDPOINT
- Override with OPENCLI_CDP_ALLOW_REMOTE=1 for advanced use cases
5. Pipeline fetch credentials:"include" risk comment
- Documents CSRF risk and required URL trust requirement
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Astro-Han
left a comment
There was a problem hiding this comment.
Security hardening looks well thought out — token lifecycle (generate → 0o600 write → constant-time verify → cleanup on shutdown), 401 retry in daemon-client, and CDP localhost guard all make sense. Test coverage is good too.
Two observations:
-
The xiaohongshu blob-URL video download fix is a separate concern from the security changes. Might be cleaner as its own PR so each can be reviewed/reverted independently.
-
isSensitiveCookieNameuses substring matching (lower.includes(s)), which casts a wide net — e.g. a cookie namedauthenticate_preferencewould match onauth. For security redaction that's probably the right tradeoff (better to over-redact), but a brief comment noting the intentional broad matching would help future readers.
|
Another concrete risk here: That means callers can get a seemingly successful connection even though no target session was established, and the first real browser command fails later with a much less obvious error. I think target attach failure should still reject Another issue in the auth hardening path: So a daemon that starts with an in-memory token but fails to persist the file becomes unusable to the CLI: every |
Description
Related issue:
Type of Change
Checklist
Documentation (if adding/modifying an adapter)
docs/adapters/(if new adapter)docs/adapters/index.mdtable (if new adapter)docs/.vitepress/config.mts(if new adapter)README.md/README.zh-CN.mdwhen command discoverability changedCliErrorsubclasses instead of rawErrorScreenshots / Output