Skip to content

gateway: an unset token is no token; refuse browsers from other sites - #629

Merged
FMXExpress merged 5 commits into
mainfrom
claude/pasclaw-desktop-plan-uapzcp
Nov 6, 2026
Merged

FMXExpress merged 5 commits into
mainfrom
claude/pasclaw-desktop-plan-uapzcp

Conversation

@FMXExpress

@FMXExpress FMXExpress commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Fixes two security reports. Both were confirmed in source and reproduced against a running gateway.

1. An unset ${PASCLAW_GATEWAY_TOKEN} was the token

The bug: digitalocean/config.template.json sets "token": "${PASCLAW_GATEWAY_TOKEN}". When the variable is unset, the config loader keeps the marker as literal text, and the gateway compared bearers against that text. The template is public, so the "password" was too.

request (before)
no token / a wrong token 401
Authorization: Bearer ${PASCLAW_GATEWAY_TOKEN} 200
?token=%24%7BPASCLAW_GATEWAY_TOKEN%7D 200
MCP read_file /etc/hostname with the literal returned the file

The startup log said the opposite: "no client token will match".

The fix: GetEffectiveGatewayToken returns '' for a marker whose variable is unset, which means no token.

  • This applies to the gateway token only. Other ${VAR} markers (provider keys and so on) behave as before.
  • The "misconfigured" auth state is gone. The log now reads bearer-token auth DISABLED -- gateway.token is ${PASCLAW_GATEWAY_TOKEN} and that env var is not set; ....
  • pasclaw attach and the gateway run file now use the same effective token as the gateway, so an env-only token works there too.

2. With no token, any web page could drive the local agent

The bug: with default settings (127.0.0.1, no token), nothing checked Origin or Host, and any request body was read as JSON.

  • Cross-site attack: a page on another site can POST text/plain with no CORS preflight. A planted memory fact and an MCP read_file both ran. The page can't read the answers, but /v1/chat drives the agent and its shell, and default permission rules don't ask before running it.
  • DNS rebinding attack: a page that re-points its domain at 127.0.0.1 is same-origin with the gateway. /v1/config was served to Host: attacker.example, so such a page can read every answer.

The fix: a token-less gateway refuses, with 403, the two things only such a page does, and nothing else:

  • an Origin from another site (another site, another port, null). The gateway's own pages, and pages under a domain name in gateway.allowed_hosts, are fine. This also refuses the --apps-port origin, so app code can't call the main API.
  • a Host that is a domain name other than localhost, *.localhost or a name in the new gateway.allowed_hosts. An IP address can't be rebound, so any IP Host is fine: 127.x, 0.0.0.0, ::, a LAN address.

One narrow extra rule covers the relay surface. GET /v1/relay/poll hands out a job, and an <img> or no-cors fetch carries no Origin. So without the relay token, /v1/relay/* answers only the gateway's own pages (Sec-Fetch-Site: same-origin) and non-browsers. On the default loopback gateway, that keeps other sites, and app code on the apps port, from draining the queue (see the live run for why only there).

What's unaffected: CLI tools, SDKs, MCP clients, relay workers by IP, the web UI, the desktop and app iframes. The same goes for the exempt routes (/, /desktop, health, version, /webhooks/*), the relay surface when it presents its token, and any gateway with a token (the token is the gate).

The check: LocalRequestRefusal in PasClaw.Gateway.Auth (pure). PUT and DELETE reach it too, through OnCommandOther. Refusals log one warning per 10 seconds; the rest go to the debug log with a count.

Breaking for one setup: a token-less gateway reached by a domain name (a reverse proxy, a LAN name, a remote pasclaw relay --gateway-url http://name:8088) now gets 403 until that name is added to gateway.allowed_hosts, or a token is set. The 403 message and the docs say which. Reaching it by IP works as before.

Together

A Docker or DigitalOcean deploy without the token now has no token. Requests through the app's domain get 403 with a message saying to set PASCLAW_GATEWAY_TOKEN; health checks still pass. Before, the same deploy was an agent open to anyone who sent the template's text.

What remains: a client that reaches the port directly can send any Host. A token-less gateway reachable over the network is therefore open to whoever reaches it.

  • The startup log and the serve banner now say so for a non-loopback bind: the gateway listens on 0.0.0.0, so /v1/* and /mcp -- shell and files included -- answer ANY client that can reach it.
  • docker/README.md and make -C digitalocean run publish on 127.0.0.1.
  • .env.example no longer carries a placeholder token that everyone can read.

Review fixes (second and third commits)

The first version also refused every Sec-Fetch-Site: cross-site request and any Host that was an IP other than loopback. Both broke real setups (desktop iframes, 0.0.0.0, relay workers by IP) and added little, so they're gone. These commits also fix:

  • the startup wording on non-loopback binds;
  • the proxy that rewrites Host;
  • attach and the run file using the raw config token;
  • log flooding from repeated refusals;
  • relay jobs drained by app code on the apps port;
  • the live test hanging on a busy port.

Tests

  • gateway_token_tests:
    • an unset marker is no token;
    • 37 LocalRequestRefusal cases: IPs, 0.0.0.0, LAN, IPv6, *.localhost, look-alike names, opaque and other-port origins, the proxy rewrite, default ports;
    • IsIPLiteral, and the startup wording by bind address.
  • make test-gateway-local-only: two live gateways, 23 checks end to end.
    • With the unset marker: cross-site POST 403, Origin: null 403, apps port 403, rebound name 403, relay drain from another site or the apps port 403. Iframe navigation 200, Host: 0.0.0.0 200, LAN IP 200, proxy rewrite 200, allowed name 200, relay from its own page or with its token 200, preflight 204. Nothing planted, and one warning for the burst.
    • With a real token: the marker's text gets 401, and the real token works from anywhere.
    • curl calls time out after 10 s, and the script checks that the gateways it started are the ones answering.
  • Revert-checked: 23 checks, each undoing one piece, and every one fails a test. The first run also showed that some code did nothing once any IP address passes: the 127.x/0.0.0.0 names in the loopback list and the bind address as an allowed name. Both were removed. It also showed the default-port case had no test, so it got one.
  • Checked by hand: a 0.0.0.0 bind prints the "ANY client" line, and the run file records the env token's hash.
  • make test passes on FPC 3.2.2 at the second commit and again with the fifth (head).
  • Delphi: not compiled with Delphi (dcc64 is not available in this environment).

Live run (relay, real browser)

The gateway ran on 0.0.0.0 with --apps-port, a relay provider, and permissions rules that ask before shell_exec (with echo safe* allowed). The model was played through the relay by a worker that connected by LAN IP. Headless Chromium drove the desktop and the web UI.

result
pasclaw agent --attach: ask answered in the desktop Allow once ran it; the allow-listed command didn't ask; Deny didn't run it (file not created); Allow for this session asked once
Desktop Ask → build_app → app opened in the desktop (at 0.0.0.0) app renders; its saved state survives a reload; no refusals
Main web UI chat tool call and reply shown
MCP client by LAN IP initialize, tools/list, tools/call
Browser relay worker on another origin with the relay token status 200, poll stream opens; refused without it
Attack page on another origin (text/plain POSTs, read, <img> relay poll) POSTs 403, read blocked, nothing planted, no job reached the model
App code on the apps origin (CSP bypassed to reach the gateway) POST 403
DNS rebinding (Chromium maps rebind.test to 127.0.0.1) the page loads; every /v1/* call 403, including a same-origin read of /v1/config
With PASCLAW_GATEWAY_TOKEN the relay worker and the desktop work with the token; attach with an env-only token works and the run file records its hash; the attack page gets 401
serve banner 0.0.0.0 says ANY client; 127.0.0.1 says this machine

Two things the run turned up:

  • Fixed, a doc gap: Chromium sends Sec-Fetch-Site only to localhost, 127.x and https. So the relay rule covers the default loopback gateway, but an <img> aimed at http://0.0.0.0 or a LAN address carries no header. Such a gateway is open to its network anyway. The comment and docs now say so (fourth commit).

  • Fixed, an older bug (fifth commit): with --apps-port, the apps origin and the one allowed frame parent were fixed at startup from --addr. A desktop opened under any other name (for example localhost when --addr is 0.0.0.0) showed no app windows, because the browser blocked the frame by CSP. Both now follow the request's Host:

    • /v1/desktop/config answers with the apps port under the desktop's own name;
    • the apps listener's frame-ancestors names the desktop's port under the app's name;
    • the --addr forms remain the fallback when there is no Host, and SiblingOrigin admits only host[:port] characters, so a Host can't inject a CSP directive.

    Live in Chromium, the desktop opened as localhost, 127.0.0.1, 0.0.0.0 and the LAN IP shows the app with its saved state, and a page on another origin still can't frame it. New desktop_routes_tests cases cover this; four revert checks each fail a test.

Docs: docs/gateway.md, docs/security.md, docs/configuration.md (gateway.allowed_hosts), docs/providers-relay.md, docs/desktop.md (apps origin), docker/README.md, digitalocean/.do/app.yaml.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U

Two reports, both confirmed and reproduced.

An unset ${PASCLAW_GATEWAY_TOKEN} was the token. The DigitalOcean
template sets "token": "${PASCLAW_GATEWAY_TOKEN}", the config loader
keeps a marker whose variable is unset as its literal text, and the
gateway compared bearers against it -- so anyone who sent that public
string had the API, shell and files included (the startup log said "no
client token will match"). GetEffectiveGatewayToken now returns '' for
an unset marker: no token. Only the gateway token; other ${VAR} markers
are unchanged.

With no token, a web page could drive the agent. Nothing checked Origin
or Host, and any body is read as JSON, so a page on another site could
POST text/plain (no preflight) and run tools, and a page that rebound its
name to 127.0.0.1 could read the answers too. A token-less gateway now
refuses, with 403, a Host that is not localhost / *.localhost / 127.x /
::1 (or gateway.allowed_hosts, or a specific bind address), an Origin
that is not its own -- the --apps-port origin included -- and
Sec-Fetch-Site: cross-site. Local clients, SDKs, MCP clients and the
gateway's own pages send none of that. Exempt: the token-exempt routes,
and the relay surface when it presents the relay token. With a token
set nothing changes: the token is the gate.

Together: a Docker or DO deploy without the token answers only localhost
names, so requests through the app's domain get 403 rather than an open
agent. The Docker and local DO examples publish on 127.0.0.1, and
.env.example no longer carries a placeholder token everyone can read.

make test-gateway-local-only drives it through two live gateways.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T17:38:07.453233Z dbe48bb 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dbe48bb0b0

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1856 to +1860
if (GetEffectiveGatewayToken(FCfg) = '') and
not IsExemptRoute(ARequest.Command, Doc) and
not RelayTokenAuthorises(Doc,
ARequest.RawHeaders.Values['Authorization'],
ARequest.Params.Values['token']) then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Allow sandboxed app assets through the browser guard

With the default token-less gateway, this guard also rejects legitimate assets requested by desktop app frames. desktop.html creates those frames with sandbox="allow-scripts allow-forms", giving them opaque origins; their subresource requests consequently carry Sec-Fetch-Site: cross-site under the Fetch Metadata algorithm. /apps/<project>/pasclaw.js is neither an exempt route nor relay-authorized, so it now receives 403. Built-in apps in PasClaw.Suite.pas, including Notes, explicitly load that script and depend on its pasclaw API, so they lose their read/write functionality even though the iframe document loads successfully. Preserve access to the app asset surface without exempting the privileged API.

Useful? React with 👍 / 👎.

The token-less guard now checks exactly the two attacks and nothing else:
an Origin from another site, and a Host that is a domain name other than
localhost or a gateway.allowed_hosts entry (DNS rebinding). Any IP Host
passes, since an IP address cannot be rebound. That covers 0.0.0.0, LAN
addresses, and relay workers by IP.

- Drop the general Sec-Fetch-Site rule; it refused app iframes when the
  desktop was opened under another local name. Only /v1/relay/* without
  the relay token still refuses cross-site, so an <img> cannot drain
  relay jobs.
- Accept an Origin under an allowed domain name, so a reverse proxy that
  rewrites Host to 127.0.0.1 works. Other ports of localhost or an IP
  stay refused (the apps origin).
- The startup log and the serve banner say who a token-less gateway is
  open to, by bind address: on 0.0.0.0 or a LAN address, any client that
  reaches it, shell included.
- attach and the gateway run file use the effective token (env or
  config), not the raw config field.
- Refusals log one warning per 10 seconds; the rest go to debug.
- Remove ListenerAllowedHosts and the 127.x / ::1 branches of the
  localhost check, which did nothing once IP Hosts pass.
- The live test has curl timeouts and checks that its own gateways
  answer. Unit and live cases are updated, plus docs (gateway, security,
  configuration, providers-relay).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
The relay rule refused only Sec-Fetch-Site: cross-site, but app code on
the --apps-port origin is same-site (same host, another port). It could
still claim relay jobs with a no-cors GET of /v1/relay/poll. Without the
relay token, the relay surface now answers only the gateway's own pages
(same-origin) and non-browsers. Real workers present the relay token or
send no Sec-Fetch-Site. The live test covers the same-site drain and the
gateway's own page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
Found in a live browser run: Chromium sends Sec-Fetch-Site only to
trustworthy URLs (localhost, 127.x, https). An <img> aimed at
http://0.0.0.0 or a LAN address carries neither Origin nor
Sec-Fetch-Site, so the relay rule covers the default loopback gateway
only. A token-less gateway on another address is open to its network
anyway. The comment and docs now say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
With --apps-port, both the apps origin the desktop frames and the one
frame parent the apps listener allows were fixed at startup from
--addr. A desktop opened under any other name showed no apps. For
example, localhost against --addr 127.0.0.1, or anything against --addr
0.0.0.0. The browser blocked the frame by CSP frame-ancestors. From
another machine, --addr 0.0.0.0 also sent the iframe to the viewer's own
0.0.0.0.

Both now follow the request's Host:
- /v1/desktop/config answers with the apps port under the name the
  desktop used.
- The apps listener names the desktop's port under the name the app was
  asked for.
- The --addr forms remain the fallback for a request with no usable Host.
- SiblingOrigin accepts only host[:port] characters, so a Host cannot
  inject a CSP directive.
- A page on any other origin still cannot frame apps.

Tests cover desktop config by name, the CSP parent by Host with the
no-Host fallback, and SiblingOrigin's edge cases. Four revert checks
each fail a test. Live in Chromium, a desktop opened as localhost,
127.0.0.1, 0.0.0.0 and a LAN IP shows the app with its saved state, and
a foreign page that frames it is refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
@FMXExpress
FMXExpress merged commit bf423d2 into main Nov 6, 2026
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