Security model
Cookie injection moves Camofox from “anonymous browsing” to “authenticated browsing.” Because cookies are sensitive credentials, the import endpoint requires API key authentication:- Disabled by default: If
CAMOFOX_API_KEYis not set, all cookie import requests return403 Forbidden - Bearer token authentication: Requests must include
Authorization: Bearer <CAMOFOX_API_KEY>header - Timing-safe comparison: The server uses constant-time comparison to prevent timing attacks
- Field sanitization: Only allowed Playwright cookie fields are accepted (name, value, domain, path, expires, httpOnly, secure, sameSite)
- Size limits: Maximum 500 cookies per request, 5MB file size limit
- Path traversal protection: Cookie file paths are resolved relative to
CAMOFOX_COOKIES_DIRand cannot escape that directory
Setup workflow
Generate a secret API key
Generate a cryptographically secure random key:This produces a 64-character hex string like:
Set the environment variable
The same key is used by both the OpenClaw plugin (to authenticate requests) and the Camofox server (to verify them). Since both run from the same environment, set it once:For Docker deployment:For Fly.io:
Why an environment variable? Plugin config in
openclaw.json is stored in plaintext, so secrets don’t belong there. Set CAMOFOX_API_KEY in your shell profile, systemd unit, Docker env, or Fly.io secrets.Export cookies from your browser
Install a browser extension that exports Netscape-format cookie files:
- Chrome: cookies.txt
- Firefox: cookies.txt
- Navigate to the site you want to authenticate (e.g., linkedin.com)
- Click the extension icon
- Export cookies for the current site
- Save the file (e.g.,
linkedin_cookies.txt)
Place the cookie file
Copy the exported file to Camofox’s cookie directory:The default directory is
~/.camofox/cookies/. Override with the CAMOFOX_COOKIES_DIR environment variable.Import cookies into your session
Using the OpenClaw plugin
Ask your agent to import cookies:Import my LinkedIn cookies from linkedin.txtThe agent calls
camofox_import_cookies → reads the file → POSTs to the server with the Bearer token → cookies are injected into the browser session.Using the standalone API
Read and parse the cookie file, then POST to the session endpoint:Cookies must be in Playwright’s cookie object format. Use the
lib/cookies.js module’s parseNetscapeCookieFile() function to convert Netscape format to Playwright format.How it works
The cookie import flow isolates file I/O, parsing, and network operations:File parsing
Thelib/cookies.js module parses Netscape-format cookie files:
#HttpOnly_ prefix for HttpOnly cookies. The parser:
- Strips UTF-8 BOM if present
- Skips comments (lines starting with
#except#HttpOnly_) - Parses tab-separated fields:
domain,flag,path,secure,expires,name,value - Converts to Playwright cookie objects with required fields
Server validation
The server endpoint (server.js:102-168) validates:
- API key: Bearer token must match
CAMOFOX_API_KEYusing timing-safe comparison - Request structure:
cookiesfield must be an array - Cookie count: Maximum 500 cookies per request
- Cookie objects: Each must have
name,value, anddomainfields - Field allowlist: Only
name,value,domain,path,expires,httpOnly,secure,sameSiteare preserved
400 Bad Request with details.
API reference
POST /sessions/:userId/cookies
Inject cookies into a user’s browser context. Headers:Environment variables
| Variable | Description | Default |
|---|---|---|
CAMOFOX_API_KEY | API key for cookie import (disabled if unset) | - |
CAMOFOX_COOKIES_DIR | Directory for cookie files | ~/.camofox/cookies |
Common issues
403 Forbidden
Cause:CAMOFOX_API_KEY is not set or the Bearer token is incorrect.
Fix: Set the environment variable before starting the server:
Cookies not applied
Cause: Cookie domain mismatch or expired cookies. Fix: Ensure the cookiedomain matches the site you’re visiting. LinkedIn cookies typically use .linkedin.com (note the leading dot for subdomain matching).
Path traversal error
Cause: Attempting to read a file outsideCAMOFOX_COOKIES_DIR.
Fix: Cookie file paths must be relative paths within the cookies directory. No ../ or absolute paths allowed.