Security¶
A browser farm runs code it did not write: every page a test opens is untrusted, and so is every app uploaded to a device. This page says what Hearth protects, how, and what is left to you.
To report a vulnerability, see SECURITY.md.
Threat model¶
| Who | What we assume |
|---|---|
| Pages and apps under test | Hostile. They may try to escape the browser, read other sessions, or reach your internal network |
| Holders of an API key | Trusted with their team's sessions, recordings and apps; not with other teams'. They may send any launch option, capability or command |
| People with access to the cluster namespace | Trusted. They can read the key Secrets and the storage and Redis credentials |
| Device hosts | Trusted for the devices they report, not for other hosts' devices |
Each session in its own pod¶
- A browser pod serves exactly one session and is then deleted. Cookies, storage, downloads and
any compromise of the browser die with it. A pod that served a session can never register as
ready again (
409 used), so a tenant cannot keep a pod for the next session. - Browser pods hold no farm credentials. No Redis URL, no storage keys. The operator gives each
pod its own name and a random token (
HEARTH_POD_TOKEN); the pod uses it to talk to the gateway's/internal/node/*routes, which only let it register itself, heartbeat, and report and upload artifacts for the one session it was given. Code that escapes the browser can reach nothing beyond that session. - Browser pods run as a non-root user with a read-only root file system (writable
/tmpand/dev/shmonly), theRuntimeDefaultseccomp profile, all Linux capabilities dropped, no privilege escalation, no service account token and no service environment variables. - Each pod has its own CPU request and memory limit, so one heavy page cannot starve the others on the node.
Launch options and browser flags¶
Clients choose browser options, so the pod filters them:
- Playwright (
x-playwright-launch-options): onlyheadless,args,slowMo,timeout,proxy,ignoreDefaultArgs,firefoxUserPrefsandchromiumSandboxare kept. Options that pick a binary, set the environment or write elsewhere (executablePath,env,downloadsPath, ...) are dropped. - Selenium: the browser binary is always the pod's own (
/usr/bin/chromiumor/usr/bin/firefox-esr). Ingoog:chromeOptionsandmoz:firefoxOptionsonlybinary,args,prefs,excludeSwitches,mobileEmulation,perfLoggingPrefs,windowTypes,logandprofileare kept (soextensionsanddebuggerAddressare dropped). - For both, browser flags that run another program or open the browser to others are removed:
--renderer-cmd-prefix,--gpu-launcher,--utility-cmd-prefix,--browser-subprocess-path,--remote-debugging*,--remote-allow-origins,--user-data-dir,--ppapi-plugin-launcher,--plugin-launcher.
Network policies¶
The chart adds three NetworkPolicies: the first two only with browser.networkPolicy.enabled: true
(the default), the one for Redis and storage always. Your cluster's network plugin must enforce
NetworkPolicy for them to have any effect.
Browser pods
- In: only from gateway pods, on port 3000.
- Out: to gateway pods on port 8080, to cluster DNS, and to any address except
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,169.254.0.0/16(cloud metadata) and100.64.0.0/10. browser.networkPolicy.allowCIDRsadds private ranges the browsers may reach, for example a staging environment in your VPC. Keep that list narrow: any page a test opens can reach those ranges too.
Emulator pods
- In: only from gateway pods, on ports 4723 and 4724.
- Out: to gateway pods, DNS and public addresses, with the same private ranges blocked.
Redis and the bundled S3 store
- In: only from the gateway, the operator, the store itself and the bucket-creating Job.
The gateway and operator pods have no NetworkPolicy from the chart. Add your own if your cluster's defaults are open.
The gateway, the operator and Redis¶
- The gateway reaches a browser pod with a secret the pod made at start and registered. The pod
answers
404to any request without it, compared in constant time. - The bundled Redis requires a password, generated once into the Secret
<release>-redisand kept on upgrades. Only the gateway and operator get the Redis URL. - Gateway and operator containers run as non-root with a read-only root file system and no capabilities. The gateway mounts no service account token. The operator's Role is limited to its namespace: read the Hearth resources, update their status, create and delete pods, read Secrets.
API keys and the web UI¶
- The operator publishes only the SHA-256 of each key to Redis. The gateway hashes what a client sends and looks up the hash. Plain keys live only in Kubernetes Secrets.
- A key set in chart values must be at least 32 characters; the chart refuses to render otherwise.
- Every API route is scoped to the caller's team. Another team's session, artifact or app answers
404, the same as one that does not exist. - On WebDriver routes the key is checked before the request body is read.
- Web UI sign-in turns a key into an HttpOnly,
SameSite=Strictcookie that lasts 12 hours, markedSecurebehind HTTPS (X-Forwarded-Proto: https). The UI never stores the key. - Requests authenticated by that cookie that change something (any method but
GET) or open a WebSocket must come from the farm's own pages (Sec-Fetch-Site: same-origin, or a matchingOrigin); otherwise403 cross_origin. API keys in headers are not affected. - UI pages are served with a strict Content Security Policy (
default-src 'self',frame-ancestors 'none'),X-Frame-Options: DENY,X-Content-Type-Options: nosniffandReferrer-Policy: no-referrer. Artifacts are served withnosniffand aContent-Dispositionthat plays videos and images inline and downloads everything else. - Keys in URLs (
?token=,user:key@host) can end up in proxy and CI logs. Use headers where your client allows, and serve the farm over TLS.
Devices¶
- Agent tokens are scoped to a host. Each host gets its own token (Secret
<release>-agent-<host>, hashed in Redis). A heartbeat must name that host, every device id must start with<host>-, and every pool must be aDevicePoolof the right platform. The in-cluster token (cluster) reports hosts namedcluster-<pod>. Artifact uploads are accepted only for sessions on that host's devices. - The gateway calls only what it should. It refuses an
agentUrlthat is not http(s), or that points at loopback, link-local or a cloud metadata name. It never dials theappiumUrlan agent reports: Appium commands go to the agent, which forwards only W3C/sessioncommands of the device's running session to Appium on its own host. - Agents never get storage or Redis credentials. They download apps and upload artifacts through the gateway.
- Apps by reference, never by URL.
appium:appmust be ahearth:app:<sha256>of an app your team uploaded. Any other value is refused, so a device is never told to fetch from an address a client chose. The agent checks the download against the hash and unpacks iOS zips with path checks. - Capabilities and commands that reach the host are blocked. The farm drops capabilities that
name host resources, ports, binaries or other machines, flattens
appium:optionsso nested keys are checked too, and refuses commands that install apps, move files or run shell commands. The full lists are in Mobile devices. - Mac hosts are single-tenant. Simulators on one Mac share its user account, keychain and file system. An app on one simulator is not strongly isolated from the others. Give teams with different trust levels separate hosts, and use the Mac for nothing else.
- Allow the agent's port only from the cluster's egress addresses. See Device agents on hosts.
- Emulator pods are privileged to use
/dev/kvm. Run them on dedicated nodes with anodeSelector.
Take control¶
Anyone with a team's key can watch that team's running sessions and send mouse, keyboard and touch input to them. Treat recordings and live views as being as sensitive as the pages your tests open: test accounts, not real customer data.
Artifacts¶
Recordings show everything on the screen, including what tests type into forms; device logs may hold what apps log. Only the gateway holds storage credentials, and it serves an artifact only to the team that owns the session. Set a lifecycle rule on the bucket; see Artifacts.
Session ids¶
Commands on an existing W3C session (Selenium or Appium) may come without a key, because many clients only authenticate the new-session request. The session id is then the credential. Ids are 128-bit, and 74 of those bits are random. A key that is sent must still match the session's team. Keep session ids out of public CI logs.
Ending sessions¶
Every path that ends a session goes through one atomic Redis script, so a team's slot is freed exactly once. The paths are: the client closing, the Stop button, an idle or maximum-duration timeout, a pod or device going away, an agent restart, and an abandoned queue entry.