Skip to content

fix(cli): open only the server's sign-in links and print sessions safely - #174

Merged
kalaspuff merged 2 commits into
mainfrom
fctl/105-cli-hardening
Oct 21, 2026
Merged

kalaspuff merged 2 commits into
mainfrom
fctl/105-cli-hardening

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Two things the CLI took on trust, from a review of fctl:

  • fctl login opened whatever sign-in link the server sent. A server someone was talked into signing in to could start a device sign-in at another instance, app.fctl.sh say, and send them that instance's link, with the code filled in and their machine's name on it; one click on Approve there gave that server a token for their account. fctl login now stops when the link is on another site than the server it signs in to (loopback addresses count as one site, for the dev stack, whose web app and API use different ports) and says how to sign in there instead:

    error: http://127.0.0.1:9999 asks you to approve this sign-in on another site (https://app.fctl.sh), which would sign you in there for it. To sign in to https://app.fctl.sh, run `fctl login https://app.fctl.sh`.
    
  • Session output reached the terminal as it came. fctl attach, fctl logs and fctl show printed agents' text, setup scripts' and dependencies' output and pull request links with any escape sequences in them, which could move the cursor to rewrite what was on screen, set the title or, in some terminals, the clipboard. They now print without the control characters terminals act on, save newlines, tabs and color codes.

Verification. Unit tests for both (same_site, terminal_safe). Against cargo xtask dev, fctl login http://127.0.0.1:8787 still signs in through the device page on localhost, and against a stand-in server that relays app.fctl.sh's link it stops with the error above. fctl logs prints transcripts with their colors as before. cargo clippy and cargo test pass for the workspace.

Other pull requests from the same review: #171 (control plane and web app), #172 (Lima sandboxes), #173 (Docker sandboxes and host files).

Made in fctl session https://app.fctl.sh/s/ses_01M5FGE9QB2HQVK1S59KEC4TYY

fctl-sh Bot added 2 commits October 21, 2026 16:19
fctl login opened, and printed, whatever link the server sent to approve
the device. A server someone was talked into signing in to could start a
sign-in at another instance, app.fctl.sh say, and send them its link, with
the code filled in and their machine's name on it: one click on Approve
there gave that server a token for their account. fctl login now stops
when the link is on another site (loopback addresses count as one, for
the dev stack) and says how to sign in there instead.
fctl attach, fctl logs and fctl show printed what a session said as it
came: an agent's text, a setup script's or a dependency's output, a pull
request's link. Escape sequences in it reached the terminal, which could
move the cursor to rewrite what was on screen, set its title or, in some
terminals, the clipboard. They now print without the control characters
terminals act on, save newlines, tabs and color codes.
@fctl-sh
fctl-sh Bot requested a review from kalaspuff as a code owner October 21, 2026 16:25
kalaspuff pushed a commit that referenced this pull request Oct 21, 2026
…171)

A security review of the control plane and the web app found ways into
workspaces and accounts that their rules don't allow. Each commit fixes
one; together they close them.

**Workspaces people left or were never in**

- **Open sockets kept their access.** Session viewer and dashboard feed
WebSockets kept the identity and role they opened with. Someone removed
from a workspace, whose project role or share went, who signed out or
was disabled kept reading a session's transcript live and could still
message and interrupt its agent; their feed kept sending session
summaries and runners. SessionObject now checks a viewer's token and
role again in D1 on its pings (at most once a minute) and before every
message and interrupt, and closes it with 4403 once access is gone;
FleetObject does the same for feeds. A socket that stops pinging closes
after five minutes and reconnects through the Worker. The web app takes
the role from `session` frames, so a changed role shows.
- **Runners that no longer serve a workspace kept its sessions.** A
runner taken out of a workspace, or whose owner left it, was demoted or
disabled, kept running the sessions it had there, with fresh GitHub
tokens and Claude credentials, their messages and files: FleetObject
only checked that the session was assigned to it, which a host that
ignores a stop keeps true. Credential requests, uplinks, file downloads
and screenshot uploads now also take that the runner serves the
session's workspace now (`spec::runner_serves`); FleetObject stops its
sessions in workspaces it no longer serves, closes its uplinks to them
and forgets it as their sandbox's home. Disabling a runner or replacing
its token closes its sessions' uplinks too, and a runner's report that a
session ended counts only for its own sessions.
- **The account export ignored workspaces.** It streamed the transcript
of every session the person had started, including those of workspaces
they had left or been removed from. It now takes the workspaces open to
them, as the API does, and leaves out the IP addresses of other people's
requests that concerned them.
- **Uplinks could put words in people's mouths.** SessionObject stored
people's messages, interrupts and status changes that came over an
uplink, which only the control plane makes; no agent or host ever sent
them. They are now dropped there.
- **Project owners could be demoted by being added again.** `POST
/projects/{id}/members` for an existing member replaced their role
without the checks a role change makes, so a maintainer could demote an
owner, the last one too.

**Ways into an account**

- Linking a Google account, setting a first password and connecting an
invitation's address each add a way to sign in, and any session or
token, however old, could do them. They now take a browser sign-in from
the last 15 minutes, as adding a passkey does. Connecting an address
mattered most: it then gets the account's password reset links, so an
invitation for one's own address, forwarded to someone signed in and
connected with a click, let its sender reset their password. The
invitation page now says whoever has the address can reset the password.
- People are emailed (when email is set up) when a Google account or an
address is connected, when their password changes, when an admin makes a
reset link for them and when a reset link is used: an instance admin's
reset link sets a member's password, and with it reaches their
workspaces, and nothing told the member.
- Sign-in redirects (`?next=`, Google's `return_to`) took
`/\evil.example` and `/<tab>/evil.example` as paths of the app; browsers
read them as other sites (`fctl_domain::validate::is_app_path`,
`appPath` in the web app).
- `POST /auth/logout` cleared the session cookie for anyone, a page of
another site too; it now does only for a signed-in request, which passed
the origin check.
- Only the primary instance owner enables and disables admins, but
adding an allowlist entry re-enabled a disabled admin, and removing one
disabled admins it alone admitted. Both are now the owner's.

**Hardening**

- Attached files keep their type only when the app shows or plays them
(PNG, JPEG, GIF, WebP, MP4, WebM, QuickTime); the rest are served as
`application/octet-stream`, so no upload can pass for a script of the
app's origin.
- A session's Remote Control link is kept only when it is an https page
of claude.ai (or claude.com): `fctl open --claude` handed it to
`open`/`xdg-open`, which on a Mac also start the app or file at a path.

**What a person should decide.** Instance admins see the link of every
instance invitation they make, also when it is emailed, so an admin can
sign up as an invited address that has no account yet and join the
workspaces that invited it. Hiding the link when the email went out
would close that on instances that send email, at the cost of the "you
can also send them this link" option; I left it as it is.
docs/security.md says instance admins don't see inside workspaces they
aren't in, which reset links (now announced to the person) and this
soften.

**Verification.** `cargo xtask check --quick` passes. End to end on
`cargo xtask dev`, with scripts driving the API and sockets as a second
member and as admins: on `main` a removed member's open socket stays up
and their message reaches the agent, their export still holds the
workspace's transcripts, a disabled member's feed stays open, a session
keeps running on a runner taken out of its workspace, a maintainer
demotes an owner by adding them again and an admin brings back an admin
the owner disabled; on this branch each of those is refused or closed
(4403 on the sockets within a minute, at once on a message), the session
stops with "Its runner no longer runs this workspace's sessions" and
resumes once the runner is back. Unit tests cover the app path check
(Rust and web).

## Screenshots

At 579b52b, light theme, 1280 px wide, with the dev stack's data. The
invitation page, signed in, when the invitation's address can be
connected: it now says what connecting gives whoever has the address.
The settings page after a Google link that didn't come from a recent
sign-in, which `main` answers with a generic error.

| Before | After |
|---|---|
| ![Before: the invitation page's connect
card](https://app.fctl.sh/api/v1/published/0ART3A5A1xqQKwynGmJO87fayE9PiDEVha1KcLiuCgc/before-invite.png)
| ![After: the connect card says whoever has the address can reset the
account's
password](https://app.fctl.sh/api/v1/published/Fj4C8RWJdTZSzQ91Bl70S8roKzfPUWjwqnNIa7luyrh/after-invite.png)
|
| ![Before: settings say "That did not work. Try
again."](https://app.fctl.sh/api/v1/published/5diT6CF6ZBbuP5wrkuy7bXf4r5xi9HRSyQl138Ht86r/before-google.png)
| ![After: settings say linking Google takes a sign-in from the last 15
minutes](https://app.fctl.sh/api/v1/published/3EYKcZnqms0FnqaXcKAbMqJIAGQ1zx169GKck0vk9D7/after-google.png)
|

Other pull requests from the same review: #172 (Lima sandboxes saw the
host's home directory), #173 (Docker sandboxes reached each other; host
files), #174 (fctl login and terminal output).

app.fctl.sh's privacy policy changes with it (the new emails, and what
the export holds): hyperstructure/fctl-site#35.

Made in fctl session
https://app.fctl.sh/s/ses_01M5FGE9QB2HQVK1S59KEC4TYY

---------

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
kalaspuff pushed a commit that referenced this pull request Oct 21, 2026
Lima's templates give every VM the home directory of whoever runs
`limactl`, read only, and a `/tmp/lima` that every VM writes to, and
forward a VM's ports to the host's loopback. fctl made its `fctl-base`
VM from `template://debian-12` and cloned each session's VM from it
without changing any of that. So anything a session ran (an agent that a
web page talked into it, a dependency's install script) could read
`~/.config/fctl/host-token`, the runner token, which gets the
credentials of every session of every workspace the runner serves, the
CLI's token in `credentials.toml`, SSH keys, and the disks of other
sessions' VMs, and could reach services other sessions ran.

- The base VM and every session's VM now get no mounts and no port
forwards (`ISOLATED` in `crates/fctl-host/src/driver/lima.rs`, the rule
Lima's own template documents for forwarding nothing). The agent comes
in with `limactl copy` and runs through `limactl shell`, over SSH, which
these don't touch.
- A stopped VM cloned by an earlier version loses its mounts (`limactl
edit --set`) before it boots again for a resume; if that fails, the host
replaces it with a new clone, and the session starts a new conversation
on its branch, as when its sandbox is gone.
- `limactl` takes only the last `--set` it is given (cobra's string
flag), so the VM's size, which came in two, now comes in one expression
with the rest: the CPU limit of Lima sandboxes never applied before.
- docs/security.md says what owners of Lima hosts that ran 0.14.1 or
earlier should do: remove the runner and install the host again, sign
the CLI in again and revoke its old tokens, and replace other keys kept
in that home directory.

**Verification.** With Lima 1.2.1's `limactl` (in a scratch `LIMA_HOME`;
this sandbox runs no VMs), on the configurations it writes: a stock
`template://debian-12` instance mounts the home directory and
`/tmp/lima`; `create --set`, `clone --set` and `edit --set` with this
expression leave no mounts and an ignore-all port forward rule, and
`clone` applies the CPUs and memory too, which two `--set` flags didn't
(only the last applied). A unit test pins the expression. `cargo clippy`
and `cargo test` pass for the workspace. Booting a VM wasn't possible
here, so the first Lima session after this deserves a look.

Other pull requests from the same review: #171 (control plane and web
app), #173 (Docker sandboxes and host files), #174 (fctl login and
terminal output).

Made in fctl session
https://app.fctl.sh/s/ses_01M5FGE9QB2HQVK1S59KEC4TYY

---------

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
kalaspuff pushed a commit that referenced this pull request Oct 21, 2026
…er (#173)

Hosts run sessions of every workspace their runner serves side by side,
and what runs in a sandbox is untrusted. A review of the host found four
ways it reached further than it should, beside Lima's mounts (#172).

- **Docker sandboxes reached each other.** They ran on Docker's default
bridge, where containers reach each other, so a session reached whatever
another session on the host served (a dev server, a database), which may
be another workspace's. New Docker sandboxes now join `fctl-sandboxes`,
a bridge with inter-container traffic off
(`com.docker.network.bridge.enable_icc=false`) that the host makes the
first time. A runtime that can't make it (Podman may not) starts
sandboxes as before, and the host's log says so. Existing stopped
sandboxes keep their network until they're removed
(`keep_stopped_hours`).
- **Token files were readable by other users for a moment.**
`host-token` and the CLI's `credentials.toml` were written, then
restricted to their owner. They're now created that way.
- **A sandbox could exhaust the host's memory.** The host read a frame
from the agent's link whole before checking its size; a line without an
end grew until the host was killed, with every session on the runner.
Frames now stop at the largest allowed.
- **`fctl host image build` used a predictable directory in /tmp.** On a
machine others use, someone could make `/tmp/fctl-image-<pid>` first and
put sources of their own in it. The sources now go into a new directory
with a random name that only the user can open.

docs/security.md now says what each driver keeps apart on the network:
Docker Desktop's and OrbStack's containers still reach the host's
loopback (`host.docker.internal`), and Apple's `container` VMs share its
network.

**Verification.** Unit tests with the stand-in `docker` CLI: Docker
sandboxes are made with `--network fctl-sandboxes`, the network once,
with inter-container traffic off; a runtime that can't make networks
still starts sandboxes; Apple's driver passes no network. Token files
are 0600 even over a looser leftover; image source directories are new
and 0700. `cargo clippy` and `cargo test` pass for the workspace. There
is no Docker in this sandbox, so the network itself wasn't tried on a
real daemon: the commands are Docker's documented ones, and a failure
falls back to the old behavior rather than failing sessions.

Other pull requests from the same review: #171 (control plane and web
app), #172 (Lima sandboxes), #174 (fctl login and terminal output).

Made in fctl session
https://app.fctl.sh/s/ses_01M5FGE9QB2HQVK1S59KEC4TYY

---------

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
@kalaspuff
kalaspuff merged commit 4587b27 into main Oct 21, 2026
5 of 6 checks passed
@kalaspuff
kalaspuff deleted the fctl/105-cli-hardening branch October 21, 2026 16:54
kalaspuff pushed a commit that referenced this pull request Oct 30, 2026
## Summary

Session titles reached people's terminals as the server had them. `fctl
sessions`, `fctl show`, the header of `fctl attach` and `fctl run`, and
the host commands' lists printed them raw, and the titles the control
plane makes itself skipped the control-character check that titles
people set get: one made from a prompt's first line, from a Linear
ticket's title, a schedule's prompt or a reviewed pull request's title.
So a project editor, the author of a pull request a review agent
reviews, or whoever writes a Linear ticket that someone delegates could
put escape sequences in a title that, when another member listed
sessions, set their clipboard (in terminals that allow OSC 52), rewrote
their screen, set the window's title or planted links.

- Titles fctl makes leave out control characters and those that turn
text around (`fctl_domain::naming::plain`), as names already did.
- The CLI prints titles, descriptions, branches, names, models and what
`fctl login` shows (the instance's name, the code, the link, who signed
in) through `style::plain`, one line without any control characters, and
error messages through `terminal_safe`, as transcripts already were
(#174). Titles stored before this print clean too.

Verified against `cargo xtask dev`: a session started with a prompt that
begins with an OSC 52 sequence gets a title without it, and with a raw
escape sequence put into a stored title, `fctl sessions` and `fctl show`
print it without any escape or bell character. New unit tests cover the
domain's titles, review titles and the CLI's `plain`; `cargo xtask check
--quick` passes.

## Stacked pull requests

Based on the one before it in this security pass's stack:

- #357

[fctl session](https://app.fctl.sh/s/ses_01M677K9YMM5WPZBTAR2KKXMSZ)

<!-- FCTL_REVIEW_SUMMARY -->
---

> [!NOTE]
> **Low risk.** It only changes how titles and names are cleaned or
printed, in the CLI and in the titles the control plane derives, with no
stored-data or protocol change.
>
> **What it does.** Titles the control plane derives from prompts,
Linear tickets, schedules and reviewed pull requests now drop control
characters and characters that reverse text, so escape sequences in them
can no longer act on a terminal. The CLI also prints titles,
descriptions, branches, names, models, login details and error messages
through `style::plain` or `terminal_safe`, now including the `fctl run`
confirmation line and `fctl edit` output, so titles stored before this
print clean too.
>
> <sub>[fctl
review](https://app.fctl.sh/s/ses_01M67D4F4EMHJE3VPD7BTC633H)'s first
look at
[`10587ed`](10587ed)
· 8 files, +114 −25 · [Review agent
settings](https://app.fctl.sh/p/fctl?tab=reviews)</sub>

<!-- /FCTL_REVIEW_SUMMARY -->

---------

Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant