mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix(terminal-dev-loop): address branch review findings
Security: - Reject same-site and cross-site state-changing requests on cookie-authenticated routes unless the origin is trusted - Drop Manager and ocm_preview Set-Cookie headers from preview responses - Show and hash the full executable content of .ocm/project.json at trust time - Restrict action URLs to http(s) and refuse symlinked repo config paths - Keep the preview start redirect on the gateway origin Lifecycle: - Stop terminals in OpenCode workspace siblings when a repo is deleted - Report preview as unavailable instead of crashing when the gateway port cannot be bound Performance: - Skip branch lookups when validating terminal and project-config directories - Stop the /proc scan once all listening sockets are mapped and pause port polling while a preview is open - Close slow WebSocket clients with 1013 so they reconnect with replay - Lazy-load the xterm terminal view and skip unchanged resize requests - Request uncompressed responses from preview targets Cleanup: - Share one repo directory resolver, trusted-origins parser, cookie prefix, WebSocket frame forwarder, header filter, icon map and dialog-param helper - Remove unused props, options and exports Docs: update terminal, preview, project actions, sandboxing, internal API and environment pages
This commit is contained in:
1 parent
16b91ccf02
commit
c60a9b35f2
72 files changed
+2039
-596
No files matched your search
@@ -10,7 +10,7 @@ Complete reference for all configuration options.
|
||||
| `ADMIN_EMAIL` | Pre-configured admin email | - |
|
||||
| `ADMIN_PASSWORD` | Pre-configured admin password | - |
|
||||
| `ADMIN_PASSWORD_RESET` | Set to `true` to reset admin password | `false` |
|
||||
| `AUTH_TRUSTED_ORIGINS` | Comma-separated list of trusted origins (frontend + backend) | `http://localhost:5173,http://localhost:5003` |
|
||||
| `AUTH_TRUSTED_ORIGINS` | Comma-separated list of trusted origins (frontend + backend). Browser requests that change state from another site (`Sec-Fetch-Site: same-site` or `cross-site`) are rejected unless their `Origin` is listed here. Never list the preview gateway origin. | `http://localhost:5173,http://localhost:5003` |
|
||||
| `AUTH_SECURE_COOKIES` | Use secure cookies (HTTPS only) | Runtime: `true` in prod, `false` in dev; Compose: `false` unless set |
|
||||
|
||||
## OAuth Providers
|
||||
@@ -82,8 +82,8 @@ The preview gateway serves dev servers through an authenticated, separate origin
|
||||
|
||||
| Variable | Description | Default |
|
||||
|----------|-------------|---------|
|
||||
| `PREVIEW_PORT` | Port for the preview gateway. Set to `0` to disable preview entirely. | `5004` |
|
||||
| `PREVIEW_PUBLIC_URL` | Same-site HTTPS origin that proxies the preview gateway. Set this when the Manager is served over HTTPS or behind a reverse proxy, where mixed content and third-party cookies otherwise block the preview iframe. | empty |
|
||||
| `PREVIEW_PORT` | Port for the preview gateway. Set to `0` to disable preview entirely. If the port is already in use, the Manager starts anyway, logs a warning and reports preview as unavailable. | `5004` |
|
||||
| `PREVIEW_PUBLIC_URL` | Same-site HTTPS origin that proxies the preview gateway; do not add it to `AUTH_TRUSTED_ORIGINS`. Set this when the Manager is served over HTTPS or behind a reverse proxy, where mixed content and third-party cookies otherwise block the preview iframe. | empty |
|
||||
|
||||
## Database
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ POST /repos/*/schedules/*/runs/*/cancel
|
||||
**Deliberately not allow-listed:**
|
||||
|
||||
- `POST /notifications/send` — use the `send_notification` action instead.
|
||||
- `GET /git-credentials/gh-env` — returns the GitHub CLI environment (`GH_TOKEN`, `GITHUB_TOKEN`) for the OpenCode host process; it must not be readable by the agent.
|
||||
- `GET /git-credentials/gh-env` — returns the shell environment for a working directory (`GH_TOKEN`, `GITHUB_TOKEN`, and the `GIT_AUTHOR_*` / `GIT_COMMITTER_*` identity when the repo has an assigned identity) for the OpenCode host process; it must not be readable by the agent.
|
||||
- `POST /sandbox/shell` — the sandbox planner's internal route that resolves and pins the shell for a `shell` call; exposing it would let the agent drive shell planning directly.
|
||||
- `/repos/*/mirror/*` — the repo mirror protocol that the `ocm` CLI uses to sync entire repositories; it can create, replace, patch, or delete whole repos, so it stays reserved for the CLI.
|
||||
|
||||
|
||||
@@ -6,19 +6,21 @@ The Preview panel lists the loopback ports that are currently listening, then pr
|
||||
|
||||
## Port List
|
||||
|
||||
Open **Preview** from the desktop sidebar tool list or the **More** drawer. The panel lists every listening loopback port on the host, with its port number, process command, and working directory. Ports inside the selected repository or workspace directory are badged **this repo** and sorted first.
|
||||
Open **Preview** from the desktop sidebar tool list or the **More** drawer, including in the Assistant workspace. The panel lists every listening loopback port on the host, with its port number and process command. On Linux hosts (including the Docker image) it also shows each process's working directory, and ports inside the selected repository or workspace directory are badged **this repo** and sorted first. On macOS the working directory is not available, so no port is badged. Other platforms list no ports.
|
||||
|
||||
The list excludes reserved ports — the Manager port (`PORT`, default 5003), the OpenCode server port (default 5551) and the preview gateway port itself — and only includes ports at or above 1024.
|
||||
The list excludes reserved ports — the Manager port (`PORT`, default 5003), the OpenCode server port (default 5551) and the preview gateway port itself — and only includes ports at or above 1024. Any other listening loopback port can be previewed; there is no per-port allow-list. This grants nothing an authenticated user does not already have, because the [Terminal](terminal.md) can reach the same ports.
|
||||
|
||||
Selecting a port creates a preview session and renders the target in a sandboxed iframe. Selecting a different port starts a new session for it.
|
||||
While the port list is shown it refreshes every 2 seconds. It stops refreshing while a preview is open.
|
||||
|
||||
When preview is disabled the panel shows **Preview is disabled (PREVIEW_PORT=0)**.
|
||||
Selecting a port creates a preview session and renders the target in an iframe on the gateway origin. The iframe keeps that origin (`allow-same-origin`) so dev servers can use cookies and storage; isolation from the Manager comes from the separate origin, not from an opaque sandbox. Selecting a different port starts a new session for it.
|
||||
|
||||
When preview is unavailable — `PREVIEW_PORT=0`, or the gateway could not listen on its port — the panel shows **Preview is unavailable**.
|
||||
|
||||
If the requested port is not listening yet, the panel shows **Waiting for port N…** and refetches the list every 2 seconds for up to 60 seconds, then shows an error with a **Retry** button.
|
||||
|
||||
## Gateway
|
||||
|
||||
The preview gateway listens on `PREVIEW_PORT` (default 5004) on its own origin. It is a separate origin from the Manager on purpose: preview content is untrusted and must not share the Manager origin. Setting `PREVIEW_PORT=0` disables the gateway.
|
||||
The preview gateway listens on `PREVIEW_PORT` (default 5004) on its own origin. It is a separate origin from the Manager on purpose: preview content is untrusted and must not share the Manager origin. Setting `PREVIEW_PORT=0` disables the gateway. If the port is already in use, the Manager still starts, logs a warning, and reports preview as unavailable.
|
||||
|
||||
Access requires an authenticated preview session:
|
||||
|
||||
@@ -26,10 +28,16 @@ Access requires an authenticated preview session:
|
||||
2. The browser navigates to `/__ocm_preview/start?token=…&path=…` on the gateway origin.
|
||||
3. The gateway consumes the token (it expires after 60 seconds and cannot be reused) and sets an `ocm_preview` session cookie.
|
||||
|
||||
Requests then carry the cookie. Manager auth cookies are stripped before proxying, because host-scoped cookies are shared across ports; the preview target never sees them.
|
||||
Requests then carry the cookie. Manager auth cookies are stripped before proxying, because host-scoped cookies are shared across ports; the preview target never sees them. In the other direction, any `Set-Cookie` from the preview target that names a Manager auth cookie or `ocm_preview` is dropped, so preview content cannot overwrite the Manager session. The start `path` must stay on the gateway origin; anything else redirects to `/`.
|
||||
|
||||
The gateway asks the target for uncompressed responses. When you use the preview remotely, put a compressing reverse proxy in front of it.
|
||||
|
||||
The gateway also proxies **WebSocket upgrades** on the same origin, so dev-server HMR works through the panel.
|
||||
|
||||
### Isolation level
|
||||
|
||||
A gateway on another port of the same host — or a `PREVIEW_PUBLIC_URL` on a subdomain of the Manager's domain — is a different origin but the **same site** as the Manager, so the browser still sends the Manager's `SameSite=Lax` session cookie with requests from preview content. The Manager therefore rejects state-changing API requests (`POST`, `PUT`, `PATCH`, `DELETE`) whose `Sec-Fetch-Site` is `same-site` or `cross-site` unless their `Origin` is listed in `AUTH_TRUSTED_ORIGINS`. Never add the preview gateway origin to `AUTH_TRUSTED_ORIGINS`.
|
||||
|
||||
A browser can hold one preview target per gateway origin at a time: the `ocm_preview` cookie names a single session. Opening a different port replaces the current target.
|
||||
|
||||
## Opening Previews
|
||||
@@ -54,7 +62,7 @@ By default the panel builds the gateway origin as `${location.protocol}//${locat
|
||||
- **Mixed content** — an `https://` page cannot embed an `http://` preview.
|
||||
- **Third-party cookies** — the `ocm_preview` cookie is blocked in a cross-site iframe.
|
||||
|
||||
Set `PREVIEW_PUBLIC_URL` to a same-site HTTPS origin that proxies the preview gateway, for example `https://preview.example.com`. The panel then builds preview URLs from that origin instead. As a fallback, **Open in new tab** opens the preview as a top-level page, where the session cookie is first-party.
|
||||
Set `PREVIEW_PUBLIC_URL` to a same-site HTTPS origin that proxies the preview gateway, for example `https://preview.example.com`. Do not add it to `AUTH_TRUSTED_ORIGINS` (see [Isolation level](#isolation-level)). The panel then builds preview URLs from that origin instead. As a fallback, **Open in new tab** opens the preview as a top-level page, where the session cookie is first-party.
|
||||
|
||||
## Related
|
||||
|
||||
|
||||
@@ -72,7 +72,12 @@ Actions defined in the repository file never run until trusted (see [Trust](#tru
|
||||
|
||||
- `version` is required and must be `1`.
|
||||
- `projectActions` and `setupWorktree` are optional. Up to 50 actions and 20 setup commands are allowed.
|
||||
- A repository action whose `id` matches a personal action is ignored, and the dialog reports a warning, so personal actions always win.
|
||||
- An action `url` must start with `http://` or `https://`.
|
||||
- A repository action whose `id` matches a personal action is not listed or run, and the dialog reports a warning, so personal actions always win. It is still part of the file's trusted content (see [Trust](#trust)).
|
||||
- `.ocm` and `.ocm/project.json` must be regular files and directories. A symbolic link at either path is reported as an invalid file and is never written through.
|
||||
- The file is read from the selected repository or workspace directory, so each worktree can carry its own version. Trust is stored once per project, so trusting the file in one worktree does not trust a different version of it in another.
|
||||
|
||||
Project actions are not available in the Assistant workspace.
|
||||
|
||||
## Moving Actions and Setup Commands
|
||||
|
||||
@@ -87,8 +92,9 @@ Moves are transactional: if the file write or the settings update fails, the fil
|
||||
|
||||
Commands in `.ocm/project.json` run on your machine, so the Manager does not run them until you trust the file:
|
||||
|
||||
- Trust is a hash of the file's **executable content only**: each action's `id`, `command` and `url`, plus the setup commands. Changing an action's name, icon, or `autoOpenUrl` does not affect trust; changing a command, URL, or setup command does.
|
||||
- Trusting requires echoing the exact hash shown, so a file cannot be swapped between review and trust.
|
||||
- Trust covers everything in the file that can run or open: each action's `id`, `name`, `command`, `url` and `autoOpenUrl` (including actions hidden because a personal action has the same `id`), plus every setup command. Changing any of these resets trust; changing an icon does not.
|
||||
- Both trust prompts — **Trust these commands** in the dialog and **Trust and run** in the header menu — list every action and setup command that trusting covers, not only the one you clicked.
|
||||
- Trusting requires echoing the exact hash of the content shown, so a file cannot be swapped between review and trust.
|
||||
- Untrusted repository commands never run — not from the header menu, and not as worktree setup commands.
|
||||
- The dialog shows the untrusted commands and a **Trust these commands** button. Attempting to run an untrusted action prompts for trust first.
|
||||
- Moving an item into the file auto-trusts it, because the user authored it.
|
||||
|
||||
@@ -18,7 +18,7 @@ The microVM sees repositories through bind mounts at the same paths used by the
|
||||
| WebUI `!command` shell mode (`POST /api/session/:sessionID/shell`) | Yes; it spawns through the same `Shell.create` path as the `shell` tool, so it is planned and routed into the microVM. It is not badged in the UI because the surface fires no `tool.execute.after` hook |
|
||||
| Shell API (`POST /api/shell`) | Yes; it spawns through the same `Shell.create` path as the `shell` tool. It is not badged in the UI because the surface fires no `tool.execute.after` hook |
|
||||
| Slash-command shell templates (`` !`cmd` ``, `POST /api/session/:sessionID/command`) | No; OpenCode expands each interpolation itself with the configured shell, directly on the host and outside `Shell.create`, so the `create.before` hook never sees it |
|
||||
| PTY terminals (`POST /api/pty`, `POST /api/pty/:ptyID/connect`), including the Manager Terminal panel and project action terminals | No; normal OpenCode behavior, with the user's configured shell. Manager terminals and project actions receive the repo-scoped GitHub token and assigned commit identity env through `CredentialProvider.getShellEnv` at creation |
|
||||
| PTY terminals (`POST /api/pty`, `POST /api/pty/:ptyID/connect`), including the Manager Terminal panel and project action terminals | No; normal OpenCode behavior, with the user's configured shell. Manager terminals and project actions receive the repo-scoped GitHub token env, and the commit identity env when the repo has an assigned identity, through `CredentialProvider.getShellEnv` at creation |
|
||||
| OpenCode file tools | No; while enforcement is on they are denied the global configuration directory (see [Mounts and Secrets](#mounts-and-secrets)) |
|
||||
| Manager-side git operations | No |
|
||||
| Plugins and custom tools | No; normal OpenCode behavior |
|
||||
@@ -49,7 +49,7 @@ Configured extensions execute with OpenCode's normal host-process privileges. Th
|
||||
|
||||
WebUI `!command` shell mode and the shell API (`POST /api/shell`) **are** sandboxed: both spawn through the same `Shell.create` path as the `shell` tool, so they are planned and routed into the microVM.
|
||||
|
||||
PTY terminals follow OpenCode's normal host-process behavior during enforcement and use the user's configured shell. This includes the Manager [Terminal panel](terminal.md) and [project actions](project-actions.md): they run as OpenCode PTYs on the host, receive the repo-scoped GitHub token and assigned commit identity env through `CredentialProvider.getShellEnv` at creation, and still bypass the sandbox shell hook. Slash-command shell templates are not sandboxed either: when a command template contains a `` !`cmd` `` interpolation, OpenCode resolves the configured shell and runs the command directly on the host before the resulting prompt is sent, without going through `Shell.create` or its `create.before` hook. That interpolation is trusted configuration outside the agent `shell` isolation boundary.
|
||||
PTY terminals follow OpenCode's normal host-process behavior during enforcement and use the user's configured shell. This includes the Manager [Terminal panel](terminal.md) and [project actions](project-actions.md): they run as OpenCode PTYs on the host, receive the repo-scoped GitHub token env, and the commit identity env when the repo has an assigned identity, through `CredentialProvider.getShellEnv` at creation, and still bypass the sandbox shell hook. Slash-command shell templates are not sandboxed either: when a command template contains a `` !`cmd` `` interpolation, OpenCode resolves the configured shell and runs the command directly on the host before the resulting prompt is sent, without going through `Shell.create` or its `create.before` hook. That interpolation is trusted configuration outside the agent `shell` isolation boundary.
|
||||
|
||||
There is no fallback to a host shell in the `Shell.create` path: the shim refuses to run without a pinned sandbox working directory, so a spawn whose plan, shim, or lock is unavailable is refused instead of running on the host.
|
||||
|
||||
|
||||
@@ -39,8 +39,10 @@ Terminals run as OpenCode PTYs on the host, using the user's configured shell. T
|
||||
|
||||
Each terminal receives environment resolved for its directory:
|
||||
|
||||
- the repository's GitHub token environment, so `git` and `gh` authenticate as the repo's credentials;
|
||||
- the assigned git commit identity, so commits made in the terminal use the repo's configured author.
|
||||
- the repository's GitHub token environment (`GH_TOKEN`, `GITHUB_TOKEN`), so `gh` authenticates with the repo's GitHub credential;
|
||||
- the repository's assigned git commit identity, when one is assigned, so commits made in the terminal use that author.
|
||||
|
||||
`git` itself authenticates with the same credentials as the OpenCode server process, which the Manager configures from its saved git credentials.
|
||||
|
||||
## Related
|
||||
|
||||
|
||||
Reference in new issue
Block a user