mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-05 22:23:55 +08:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d785c7d951 | ||
|
|
b2d9299089 | ||
|
|
d177511983 | ||
|
|
2eadb08779 | ||
|
|
19adbb1ec7 | ||
|
|
fa8f7696ca | ||
|
|
7c83ea36c4 | ||
|
|
490b4e6831 |
@@ -6,6 +6,10 @@ All notable changes to this project are documented in this file. The format is b
|
||||
|
||||
### Security
|
||||
|
||||
- **Argv deny and ask rules no longer pass a command they cannot read.** An argv deny or ask rule answered "no match", and the call ran without review, when the program word was an ANSI-C string, a glob, a brace expansion or a variable (`$'nmap'`, `/usr/bin/nm?p`, `n{m,}ap`, `"$T"`), when a `sh -c` or `eval` payload was built at run time, when a shell read its script from a here-string, a here-document, a process substitution or a pipe (`bash <<< 'nmap x'`, `echo 'nmap x' | sh`), when payloads nested more than three levels deep, and for shells and program runners the matcher did not know (`ash`, `mksh`, `rbash`, `posh`, `yash`, `csh`, `tcsh`, `su -c`, `runuser`, `script -c`, `unshare`, `setpriv`, `nsenter`, `systemd-run`, `firejail`, `catchsegv`, `pkexec`). ANSI-C strings are now decoded, literal text fed to a shell on stdin (here-string, here-document, `echo`, `printf` or `cat <<EOF` into a pipe or process substitution, `source <(...)`, `/dev/stdin`) is parsed as a nested command line, and the new shells and runners are unwrapped. When a part of the line that may run the program is only known when it runs (such a program word, a payload or a script produced by another command as in `curl ... | bash`, nesting past the limit, a word built at run time where the rule names an argument, a shell option the matcher does not know), the rule now counts as a possible match: an ask rule asks as configured, and a deny rule asks for an approval that times out to deny, because denying outright would also refuse every ordinary `"$TOOL" ...` call with no way to let it through. A possible match keeps its rule's place in the priority order, and a later rule that denies still decides. A program word whose last path component is fixed text (`"$HOME/bin/curl"`, `~/bin/curl`) is matched by that name. Unknown options on a known wrapper were tried both ways recursively, so `nohup` with a few dozen unknown options took seconds per rule; each position is now walked once and a rule's walk is bounded, and reaching a bound counts as a possible match. Script files (`bash script.sh`, `sh < file`) are still not read.
|
||||
- **The sandbox images build from a digest-pinned Debian base.** `Dockerfile.runner`, `Dockerfile.worker` and `Dockerfile.egress-proxy` built their runtime stage from the bare `debian:bookworm-slim` tag, so a rebuild used whatever the tag pointed to that day for the runner (which holds the Docker socket), the worker and the egress proxy. They now use `debian:bookworm-slim@sha256:e67eeead...`, the multi-architecture index the panel `Dockerfile` already pins, which Dependabot keeps current, and a test fails when any `FROM` in the repository's Dockerfiles lacks a digest. The GHCR compose file pins `postgres:16-alpine` to the digest `docker-compose.yml` already uses. The API-recon skill's checklist and harvest script ask for `npm ci --ignore-scripts` against the shipped lockfile instead of `npm install`. The Debian package repositories the images install from are still live, not a frozen snapshot.
|
||||
- **The image ships Playwright builds with Chromium 159.** The Dockerfile installed `playwright@1.64.1`, whose Chromium 156.0.8078.4 the shared browser runs, and `@playwright/mcp@0.0.83` and `@playwright/cli@0.1.22`, which bundle Chromium 155.0.8059.12. Both are older than 157.0.8103.50, the release that fixes CVE-2026-125350, a renderer use-after-free exploited in the wild. The pins move to `playwright@1.65.1`, `@playwright/mcp@0.0.86` and `@playwright/cli@0.1.25`, which all bundle Chromium 159.0.8154.6 (Playwright revision 1255), and a test refuses a Dockerfile pin older than the first release of each package with a fixed Chromium. The `playwright-cli` skill installs the same `@playwright/cli` version, and its test-generation guide installs `@playwright/test@1.65.1` instead of running `npm init playwright@latest`; a test keeps the Playwright versions named in skills equal to the Dockerfile pins. Known limitation, unchanged: on Linux these browsers still run with `--no-sandbox`. The image has no setuid sandbox helper and Docker's default seccomp profile gives the executor no user namespaces, so a renderer exploit is contained only by the container and the executor uid; the README now states this next to the shared browser.
|
||||
- **Pausing or deleting a task in local mode stops only that task's processes.** With the sandbox off and the executor uid drop on, `Engine.Pause` and `Engine.BeginDelete` sent SIGTERM and then SIGKILL to every process running as the executor uid and never looked at the task directory. Every task runs as that uid, so pausing one task (from the UI, the API, the chat bridge or the Auto agent's `pause_task`) also killed the agents of every other running task, the shared browser, and any process of that uid on the host, even one the server never started. The kill switch now selects a process only when the server started it (escaped daemons are reparented to the server, which is a child subreaper) and its subtree belongs to the task: walking down from the server, the first process that names a task decides for everything below it, through the new `ARTEX_EXEC_TASK` variable that the planner and the worker put in the environment of their Bash, or else through a working directory under `tasks/<id>`. A process group is signalled as a whole only when every live member belongs to the task. With the privilege drop off the same scoping replaces the old rule, which killed every descendant in another process group, so it crossed tasks too. Behaviour change: a process that was reparented to the server, left the task directory and cleared `ARTEX_EXEC_TASK` (for example `cd /; env -i setsid daemon`) is no longer killed by Pause; stdio MCP servers, which start outside the task directory, are left to the end of the agent run, which closes them. Sandbox mode is unchanged.
|
||||
- **Markdown images no longer load from other origins.** Finding reports, task reports and transcripts render Markdown written by the agent from target content, and an image in it was fetched by the operator's browser as soon as the view opened: `` sent whatever the URL carried to an outside host, outside the sandbox egress controls. The Markdown renderer now loads only same-origin images under `/api/` and `/uploads/` (relative paths, or absolute URLs on the console's own origin, checked after dot segments are resolved; protocol-relative URLs, backslashes and encoded slashes are refused) and shows any other image as its alt text and URL, linked when it is an `http(s)` URL, so nothing is fetched until the operator clicks. The Content-Security-Policy sent with every response, console included, adds `img-src 'self' data: blob:`, which also covers images outside Markdown. Behaviour change: images embedded from external hosts in reports and notes, and company logos set to an external URL, no longer display.
|
||||
- **Transcripts and noa archives are owner-only, and Norma's Grep no longer installs ripgrep.** Norma writes `<data>/transcripts` and the noa compression archives under `<data>/noa` with 0755 directories and 0644 files, so any other uid on the host, the executor that runs the agent's commands included, could read every conversation (prompts, model output, tool results). At startup every directory in these two trees, the top ones included, now keeps at most its owner bits (0700) and every regular file at most owner read and write (0600); a narrower mode is never widened, and a missing top directory is created 0700. As for the key directory, nothing is changed by path: the trees are walked under an `os.Root` at the data directory, each entry is checked without following symlinks and changed through the descriptor that was checked, and a symlink (`transcripts` or `noa` themselves included), a hard-linked file or any other non-regular entry is refused and left as it is. A refusal or a failed mode change fails the start like a key directory that cannot be locked down: the error joins the isolation self-test, and only `ARTEX_ALLOW_UNISOLATED=1` (or `-dev-insecure-no-isolation`) starts anyway. Only the server reads these trees: the sandbox and Kubernetes workers mount only their task directory, the executor's shells and file tools work inside run directories, and archive export and the workspace file manager read them as the server. Files Norma writes later are still 0644 but sit under 0700 directories. Norma's Grep ran an unpinned `npm install -g @vscode/ripgrep` (install scripts enabled) when `rg` was missing; `NORMA_RIPGREP_NO_INSTALL` is now always set to `1` at startup, so no value, an empty one included, lets a Norma Grep install a package at run time (ARTEX's own Grep never starts ripgrep). Behaviour change: archiving the data directory as a non-root host user (`scripts/backup.sh --with-data`, which already asks for root) cannot read these two trees, and a data directory the server cannot change (for example an NFS export with root squashing, or a tree owned by another uid) fails the start until it is fixed or the opt-out is set.
|
||||
- **Saved LLM profiles and run-time completions go through the model URL guard.** The connection test refused a `base_url` or proxy on a loopback, private or instance-metadata address, but saving a profile accepted it, and every completion of a task, chat or Agent bound to that profile was sent there with the profile's stored API key. Saving a profile (`POST /api/llm/profiles`) and the legacy `POST /api/llm` now refuse what the connection test refuses, and every completion provider the server builds validates the proxy and each request URL before sending, checks every connection on the address it dials (so a name that later resolves to a refused address is still refused), validates redirects and keeps them on the configured origin. The existing allowances are unchanged: an exact `host:port` listed in `ARTEX_LLM_PRIVATE_ENDPOINTS` (for example Ollama or vLLM on the host or the Docker network) is accepted at save and at run time, and an Ollama profile on the built-in default `http://127.0.0.1:11434/v1` (an empty base URL) keeps working without it. Behaviour change: a stored profile, or an `ARTEX_LLM_*` environment config, whose endpoint or proxy points at a loopback, LAN or Docker-network address not listed in `ARTEX_LLM_PRIVATE_ENDPOINTS` stops working (each request fails with the guard's refusal) until its `host:port` is added there; a SOCKS5 proxy on a profile is refused, as the connection test already refused it; and a profile host that does not resolve cannot be saved.
|
||||
|
||||
+7
-5
@@ -269,13 +269,15 @@ RUN set -eux; \
|
||||
# @playwright/cli: provides playwright-cli, verified with --help right after install.
|
||||
# Then install playwright (browser management) and preinstall chromium plus its system
|
||||
# dependencies via --with-deps. @playwright/mcp and @playwright/cli bundle their own
|
||||
# playwright-core, which expects a different Chromium build than
|
||||
# playwright-core, which can expect a different Chromium build than
|
||||
# playwright@PLAYWRIGHT_VERSION installs, so that build is installed as well (second
|
||||
# install line); without it neither can launch a browser. All three packages are
|
||||
# pinned; upgrade deliberately.
|
||||
ARG PLAYWRIGHT_MCP_VERSION=0.0.83
|
||||
ARG PLAYWRIGHT_CLI_VERSION=0.1.22
|
||||
ARG PLAYWRIGHT_VERSION=1.64.1
|
||||
# pinned; upgrade deliberately. Each pin must bundle Chromium 157.0.8103.50 or later
|
||||
# (the pins below all bundle 159.0.8154.6, Playwright revision 1255), and
|
||||
# server/playwright_pins_test.go refuses older ones.
|
||||
ARG PLAYWRIGHT_MCP_VERSION=0.0.86
|
||||
ARG PLAYWRIGHT_CLI_VERSION=0.1.25
|
||||
ARG PLAYWRIGHT_VERSION=1.65.1
|
||||
# playwright-core's exports map hides cli.js from require.resolve, so run the
|
||||
# binary npm links for @playwright/mcp instead: it is the copy MCP actually
|
||||
# loads, and it installs the Chromium revision that copy expects.
|
||||
|
||||
@@ -9,7 +9,7 @@ ARG TARGETARCH
|
||||
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags="-s -w" \
|
||||
-o /out/artex-egress-proxy ./cmd/artex-egress-proxy
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
FROM debian:bookworm-slim@sha256:e67eeead736ff7bbe258ef088bff683635c561b1fcfefad0806c1df4ab49ce0e
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/* \
|
||||
&& groupadd -g 10001 exec && useradd -u 10001 -g 10001 -d /nonexistent -s /usr/sbin/nologin exec
|
||||
COPY --from=build /out/artex-egress-proxy /usr/local/bin/artex-egress-proxy
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath \
|
||||
-ldflags="-s -w -X main.version=${ARTEX_VERSION}" \
|
||||
-o /out/artex-runner ./cmd/artex-runner
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
FROM debian:bookworm-slim@sha256:e67eeead736ff7bbe258ef088bff683635c561b1fcfefad0806c1df4ab49ce0e
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl && rm -rf /var/lib/apt/lists/*
|
||||
COPY --from=build /out/artex-runner /usr/local/bin/artex-runner
|
||||
EXPOSE 8789
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ ARG TARGETOS=linux
|
||||
ARG TARGETARCH
|
||||
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags="-s -w" -o /out/artex-exec-wrap ./cmd/artex-exec-wrap
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
FROM debian:bookworm-slim@sha256:e67eeead736ff7bbe258ef088bff683635c561b1fcfefad0806c1df4ab49ce0e
|
||||
RUN set -eux; \
|
||||
apt-get update; \
|
||||
apt-get install -y --no-install-recommends \
|
||||
|
||||
@@ -259,6 +259,12 @@ worker remains confined to the intent it claimed.
|
||||
by same-UID agent processes while the run is active; the token is revoked immediately when the run
|
||||
ends, Chromium binds no TCP port on Unix, and the server CDP proxy enforces the operator hold and
|
||||
active lease on every HTTP request and WebSocket message so operator take-over cannot be bypassed.
|
||||
Known limitation: on Linux the shared browser, like Playwright MCP and `playwright-cli`, runs
|
||||
Chromium with `--no-sandbox`. The image has no setuid sandbox helper (setuid bits are stripped and
|
||||
the panel runs with `no-new-privileges`), and Docker's default seccomp profile gives the executor no
|
||||
user namespaces. A renderer exploit is therefore contained only by the container and the executor
|
||||
uid, which can read every task's transcripts and workspaces: open only pages you are prepared to
|
||||
expose to that, and keep the image current with Chromium security releases.
|
||||
- **Verified findings**: findings carry a POE level, a verification status and a note; a finding is
|
||||
`verified` only when a bound proof/response and verbatim evidence quotes support it. Gzip/deflate
|
||||
bodies are decoded before the quote check. The findings table supports bulk status updates, and
|
||||
|
||||
+2
-2
@@ -681,8 +681,8 @@ func (p *Planner) planOnce(ctx context.Context, taskID int64, as *db.AssetStore,
|
||||
DeepSeekSearchAPIKey: p.webSearch.DeepSeekAPIKey,
|
||||
DeepSeekSearchModel: p.webSearch.DeepSeekModel,
|
||||
WebSearchProxy: p.webSearch.Proxy,
|
||||
BashEnv: proxyEnv(p.proxyAddr, p.proxyCACert), // Bash subcommands go through the proxy + trust its CA by default
|
||||
WorkingDir: taskDir, // the main run directory <workDir>/tasks/<taskID>/main
|
||||
BashEnv: append(proxyEnv(p.proxyAddr, p.proxyCACert), taskEnv(taskID)), // Bash subcommands go through the proxy + trust its CA by default
|
||||
WorkingDir: taskDir, // the main run directory <workDir>/tasks/<taskID>/main
|
||||
ToolOutputDir: TaskToolOutputDir(p.workDir, taskID, taskDir),
|
||||
MaxTurns: p.turnCap(ctx), // 0 = unlimited; clamped by task turn budget and forced wrap-up cap
|
||||
MaxDuration: maxDur, // 0=unlimited; with a deadline = time remaining until it
|
||||
|
||||
+11
-1
@@ -268,6 +268,16 @@ func proxyEnv(proxyAddr, caCert string) []string {
|
||||
return env
|
||||
}
|
||||
|
||||
// ExecTaskEnv names the task in the environment of the Bash processes that an
|
||||
// agent run of the task starts. The local kill switch (server/killswitch_unix.go)
|
||||
// reads it to tell one task's processes from another's, since every task runs
|
||||
// as the same executor uid. It is not a secret and not a boundary: a process can
|
||||
// change it, for its own children only.
|
||||
const ExecTaskEnv = "ARTEX_EXEC_TASK"
|
||||
|
||||
// taskEnv returns the ExecTaskEnv entry for taskID.
|
||||
func taskEnv(taskID int64) string { return ExecTaskEnv + "=" + strconv.FormatInt(taskID, 10) }
|
||||
|
||||
// workerDefaultTmpl is the built-in EDITABLE body (section [A]) of the worker
|
||||
// system prompt, seeded into agent_prompts. The trafficTool block and the
|
||||
// intermediate artifact output rules are NOT here — they are code-owned and
|
||||
@@ -720,7 +730,7 @@ func (w *Worker) execute(ctx context.Context, name string, taskID int64, as *db.
|
||||
WebSearchProxy: w.webSearch.Proxy,
|
||||
// Bash subcommands' HTTP goes through the recording proxy + trusts its CA by
|
||||
// default (tools need no -x/-k).
|
||||
BashEnv: proxyEnv(w.proxyAddr, w.proxyCACert),
|
||||
BashEnv: append(proxyEnv(w.proxyAddr, w.proxyCACert), taskEnv(taskID)),
|
||||
WorkingDir: runDir,
|
||||
MaxTurns: w.turnCap(ctx), // 0 = unlimited (configurable in agent management); clamped by the intent budget
|
||||
// Wall-clock budget, judged at turn boundaries without interrupting mid-flight;
|
||||
|
||||
@@ -25,7 +25,7 @@ x-logging: &default-logging
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
image: postgres:16-alpine@sha256:f2f98726820d0342055351c6e9d36e705f5bfffb3dd53ff556325114b08afb6d
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER:-artex}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Please set POSTGRES_PASSWORD in .env}
|
||||
|
||||
+698
-146
File diff suppressed because it is too large
Load Diff
@@ -158,8 +158,6 @@ func TestArgvDenyAndAskCompoundAndWrapped(t *testing.T) {
|
||||
{"taskset pid mode", "taskset -p 1234"},
|
||||
{"chrt pid mode", "chrt -p 1234"},
|
||||
{"xargs -l echo nmap does not match nmap", "xargs -l echo nmap"},
|
||||
{"shell unknown option before -c", "bash --unknown-opt -c 'nmap -p 80 x'"},
|
||||
{"shell opaque option before -c", "bash $OPT -c 'nmap -p 80 x'"},
|
||||
{"shell script mode with -x", "bash -x nmap"},
|
||||
{"shell script file", "bash nmap"},
|
||||
{"shell -- before -c treats -c as script", "bash -- -c 'nmap -p 80 x'"},
|
||||
@@ -172,9 +170,6 @@ func TestArgvDenyAndAskCompoundAndWrapped(t *testing.T) {
|
||||
{"parallel :::+ separator", "parallel :::+ nmap"},
|
||||
{"chroot without command", "chroot /"},
|
||||
{"busybox list mode", "busybox --list"},
|
||||
{"eval opaque leading arg", "eval $CMD nmap"},
|
||||
{"opaque command token", "$CMD -p 80 x"},
|
||||
{"nested payload depth 4 exceeds limit", `bash -c "sh -c \"bash -c 'eval \\\"nmap -p 80 x\\\"'\""`},
|
||||
{"unparsable single quote", "nmap 'unterminated"},
|
||||
{"unparsable subst", "nmap $("},
|
||||
{"empty command", ""},
|
||||
@@ -190,6 +185,31 @@ func TestArgvDenyAndAskCompoundAndWrapped(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A program word, payload or option built at run time, or a payload nested
|
||||
// past the limit, may run nmap: the rule asks, and a deny rule's ask
|
||||
// times out to deny.
|
||||
nmapMayMatch := []struct {
|
||||
name string
|
||||
cmd string
|
||||
}{
|
||||
{"shell unknown option before -c", "bash --unknown-opt -c 'nmap -p 80 x'"},
|
||||
{"shell opaque option before -c", "bash $OPT -c 'nmap -p 80 x'"},
|
||||
{"eval opaque leading arg", "eval $CMD nmap"},
|
||||
{"opaque command token", "$CMD -p 80 x"},
|
||||
{"nested payload depth 4 exceeds limit", `bash -c "sh -c \"bash -c 'eval \\\"nmap -p 80 x\\\"'\""`},
|
||||
}
|
||||
|
||||
for _, action := range []string{"deny", "ask"} {
|
||||
for _, tc := range nmapMayMatch {
|
||||
t.Run(action+"/maymatch/"+tc.name, func(t *testing.T) {
|
||||
dec, ok := matchSingleArgvRule(action, `["nmap"]`, "Bash", bashInput(tc.cmd))
|
||||
if !ok || dec.Action != "ask" || (action == "deny" && dec.TimeoutAction != "deny") {
|
||||
t.Errorf("%s [\"nmap\"] on %q: got (%+v, %v), want an ask", action, tc.cmd, dec, ok)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Non-Bash tool never matches argv rules.
|
||||
if dec, ok := matchSingleArgvRule("deny", `["nmap"]`, "shell_open", bashInput("nmap -p 80 x")); ok {
|
||||
t.Errorf("non-Bash tool matched deny rule: %+v", dec)
|
||||
@@ -206,7 +226,7 @@ func TestArgvDenyMultiTokenAndPathRules(t *testing.T) {
|
||||
{"git config path qualified with flag", `["git","config"]`, "/usr/bin/git config --list", true},
|
||||
{"git config via command", `["git","config"]`, "command git config --list", true},
|
||||
{"git config via sudo", `["git","config"]`, "sudo git config user.name foo", true},
|
||||
{"git config opaque subcommand", `["git","config"]`, "git $SUB --list", false},
|
||||
{"git config opaque subcommand may match", `["git","config"]`, "git $SUB --list", true},
|
||||
{"git status does not match git config", `["git","config"]`, "git status", false},
|
||||
{"exact path rule matches exact path", `["/usr/bin/nmap"]`, "/usr/bin/nmap -p 80 x", true},
|
||||
{"exact path rule does not match bare name", `["/usr/bin/nmap"]`, "nmap -p 80 x", false},
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
package intercept
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Autumn-27/artex/db"
|
||||
)
|
||||
|
||||
// Every form below runs nmap, or may run it: a deny or ask argv rule on nmap
|
||||
// must not answer "no match".
|
||||
func TestArgvDenyAskRulesFailClosed(t *testing.T) {
|
||||
matched := []string{
|
||||
`$'nmap' -sV x.htb`,
|
||||
`$'\x6emap' -sV x.htb`,
|
||||
`bash -c $'nmap x.htb'`,
|
||||
`eval $'nmap x.htb'`,
|
||||
"bash <<'EOF'\nnmap x.htb\nEOF",
|
||||
"bash <<EOF\nnmap x.htb\nEOF",
|
||||
"bash <<-EOF\n\tnmap x.htb\n\tEOF",
|
||||
`bash <<< 'nmap x.htb'`,
|
||||
`bash -s <<< 'nmap x.htb'`,
|
||||
`echo 'nmap x.htb' | sh`,
|
||||
`echo nmap x.htb | sh -`,
|
||||
`printf 'nmap x.htb\n' | bash`,
|
||||
`printf '%s\n' 'nmap x.htb' | bash`,
|
||||
"cat <<'EOF' | bash\nnmap x.htb\nEOF",
|
||||
`sh < <(echo nmap x.htb)`,
|
||||
`bash <(echo nmap x.htb)`,
|
||||
`source <(echo 'nmap x.htb')`,
|
||||
`. /dev/stdin <<< 'nmap x.htb'`,
|
||||
`bash /dev/stdin <<< 'nmap x.htb'`,
|
||||
`echo 'nmap x.htb' | sudo bash`,
|
||||
`echo 'nmap x.htb' | (sh)`,
|
||||
`echo 'nmap x.htb' | { true; sh; }`,
|
||||
`echo 'nmap x.htb' | bash -c 'sh'`,
|
||||
`bash -c "bash <<< 'nmap x.htb'"`,
|
||||
`ash -c 'nmap x.htb'`,
|
||||
`mksh -c 'nmap x.htb'`,
|
||||
`rbash -c 'nmap x.htb'`,
|
||||
`busybox ash -c 'nmap x.htb'`,
|
||||
`su -c 'nmap x.htb'`,
|
||||
`su root -c 'nmap x.htb'`,
|
||||
`su -lc 'nmap x.htb' root`,
|
||||
`su --command='nmap x.htb'`,
|
||||
`echo 'nmap x.htb' | su`,
|
||||
`runuser -l kali -c 'nmap x.htb'`,
|
||||
`runuser -u kali -- nmap x.htb`,
|
||||
`script -qc 'nmap x.htb' /dev/null`,
|
||||
`unshare nmap x.htb`,
|
||||
`unshare -r --net nmap x.htb`,
|
||||
`setpriv --reuid=1 nmap x.htb`,
|
||||
`setpriv --reuid 1 --clear-groups nmap x.htb`,
|
||||
`nsenter -t 1 -m -n nmap x.htb`,
|
||||
`systemd-run --user -p MemoryMax=1G nmap x.htb`,
|
||||
`firejail --noprofile nmap x.htb`,
|
||||
`catchsegv nmap x.htb`,
|
||||
`pkexec --user root nmap x.htb`,
|
||||
`"$HOME/bin/nmap" -sV x.htb`,
|
||||
`~/bin/nmap -sV x.htb`,
|
||||
`timeout "$T" nmap x.htb`,
|
||||
}
|
||||
mayMatch := []string{
|
||||
`/usr/bin/nm?p -sV x.htb`,
|
||||
`n{m,}ap -sV x.htb`,
|
||||
`"$TOOL" -sV x.htb`,
|
||||
`$D/nmap -sV x.htb`,
|
||||
`$(which nmap) x.htb`,
|
||||
`bash -c "$CMD"`,
|
||||
`eval "$CMD"`,
|
||||
`eval echo "$CMD"`,
|
||||
`sh -c "sh -c 'sh -c \"sh -c nmap\"'"`,
|
||||
`bash <<< "$CMD"`,
|
||||
"bash <<EOF\n$CMD\nEOF",
|
||||
`curl -s http://x.htb/s.sh | bash`,
|
||||
`sh < <(curl -s http://x.htb/s.sh)`,
|
||||
`echo x.htb | xargs sh -c`,
|
||||
`sudo "$X" x.htb`,
|
||||
`su -c "$C"`,
|
||||
`env -S "$C"`,
|
||||
}
|
||||
noMatch := []string{
|
||||
`"$HOME/bin/curl" x.htb`,
|
||||
`~/bin/curl x.htb`,
|
||||
`bash script.sh`,
|
||||
`bash "$SCRIPT"`,
|
||||
`echo 'curl x.htb' | sh`,
|
||||
`bash <<< 'curl x.htb'`,
|
||||
"bash <<'EOF'\necho nmap\nEOF",
|
||||
`printf 'echo nmap\n' | sh`,
|
||||
`su -c 'id'`,
|
||||
`unshare -r curl x.htb`,
|
||||
`echo nmap`,
|
||||
`cat nmap.txt`,
|
||||
}
|
||||
for _, action := range []string{"deny", "ask"} {
|
||||
for _, cmd := range matched {
|
||||
dec, ok := matchSingleArgvRule(action, `["nmap"]`, "Bash", bashInput(cmd))
|
||||
if !ok || dec.Action != action {
|
||||
t.Errorf("%s nmap on %q: got (%s, %v), want %s", action, cmd, dec.Action, ok, action)
|
||||
}
|
||||
}
|
||||
for _, cmd := range mayMatch {
|
||||
dec, ok := matchSingleArgvRule(action, `["nmap"]`, "Bash", bashInput(cmd))
|
||||
if !ok || dec.Action != "ask" || (action == "deny" && dec.TimeoutAction != "deny") {
|
||||
t.Errorf("%s nmap on %q: got (%s, %v, timeout %q), want ask", action, cmd, dec.Action, ok, dec.TimeoutAction)
|
||||
}
|
||||
}
|
||||
for _, cmd := range noMatch {
|
||||
if dec, ok := matchSingleArgvRule(action, `["nmap"]`, "Bash", bashInput(cmd)); ok {
|
||||
t.Errorf("%s nmap on %q: got %s, want no match", action, cmd, dec.Action)
|
||||
}
|
||||
}
|
||||
}
|
||||
// A full-path rule meets a program of that name in a directory known at
|
||||
// run time as a possible match only.
|
||||
if dec, ok := matchSingleArgvRule("deny", `["/usr/bin/nmap"]`, "Bash", bashInput(`"$D"/nmap x.htb`)); !ok || dec.Action != "ask" {
|
||||
t.Errorf(`deny /usr/bin/nmap on "$D"/nmap: got (%s, %v), want ask`, dec.Action, ok)
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown options on a known wrapper are walked once per position, so the
|
||||
// walk stays linear; nested wrappers stay within the step bound.
|
||||
func TestArgvWrapperWalkIsBounded(t *testing.T) {
|
||||
cmds := []string{
|
||||
"nohup" + strings.Repeat(" -x", 48) + " nmap x.htb",
|
||||
strings.Repeat("nohup -x ", 40) + "nmap x.htb",
|
||||
"env" + strings.Repeat(" -Z", 48) + " nmap x.htb",
|
||||
}
|
||||
for _, cmd := range cmds {
|
||||
done := make(chan bool, 1)
|
||||
go func() {
|
||||
_, ok := matchSingleArgvRule("deny", `["nmap"]`, "Bash", bashInput(cmd))
|
||||
done <- ok
|
||||
}()
|
||||
select {
|
||||
case ok := <-done:
|
||||
if !ok {
|
||||
t.Errorf("deny nmap missed %.40q...", cmd)
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatalf("matching %.40q... took more than 5s", cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A possible match asks at its rule's place in the order: a later deny still
|
||||
// decides, a later allow does not.
|
||||
func TestArgvPossibleMatchOrder(t *testing.T) {
|
||||
ic := New(nil)
|
||||
ic.SetRulesForTest([]db.InterceptRule{
|
||||
{ID: 1, Name: "deny nmap", Enabled: true, Priority: 100, MatchTarget: "tool_input", MatchType: "argv", Pattern: `["nmap"]`, Action: "deny"},
|
||||
{ID: 2, Name: "allow curl", Enabled: true, Priority: 90, MatchTarget: "tool_input", MatchType: "string", Pattern: "curl ", Action: "allow"},
|
||||
{ID: 3, Name: "deny rm", Enabled: true, Priority: 80, MatchTarget: "tool_input", MatchType: "string", Pattern: "rm -rf", Action: "deny"},
|
||||
})
|
||||
dec, ok := ic.Match("Bash", bashInput(`"$T" x; curl -s http://x.htb/`))
|
||||
if !ok || dec.Action != "ask" || dec.RuleID != 1 || dec.TimeoutAction != "deny" {
|
||||
t.Errorf("possible nmap then allow curl: got (%+v, %v), want ask of rule 1", dec, ok)
|
||||
}
|
||||
dec, ok = ic.Match("Bash", bashInput(`"$T" x; rm -rf /tmp/x`))
|
||||
if !ok || dec.Action != "deny" || dec.RuleID != 3 {
|
||||
t.Errorf("possible nmap then rm -rf: got (%+v, %v), want deny of rule 3", dec, ok)
|
||||
}
|
||||
|
||||
// An ask rule keeps its own timeout policy.
|
||||
ic.SetRulesForTest([]db.InterceptRule{{ID: 4, Name: "ask nmap", Enabled: true, Priority: 100, MatchTarget: "tool_input",
|
||||
MatchType: "argv", Pattern: `["nmap"]`, Action: "ask", TimeoutEnabled: true, TimeoutSeconds: 30, TimeoutAction: "allow"}})
|
||||
dec, ok = ic.Match("Bash", bashInput(`"$T" x`))
|
||||
if !ok || dec.Action != "ask" || !dec.TimeoutEnabled || dec.TimeoutSeconds != 30 || dec.TimeoutAction != "allow" {
|
||||
t.Errorf("possible match of an ask rule: got (%+v, %v), want its timeout policy", dec, ok)
|
||||
}
|
||||
}
|
||||
+48
-2
@@ -710,13 +710,23 @@ func judgeActionLabel(action string) string {
|
||||
// Returns (Decision, true) for the first matching enabled rule, or
|
||||
// (Decision{}, false) if no rule matches. When the rules cannot be loaded it
|
||||
// returns a deny.
|
||||
//
|
||||
// A deny or ask argv rule that may match (argvPossible) asks, see
|
||||
// possibleArgvDecision; a later rule that matches still decides when it
|
||||
// denies, since a deny is stricter than that ask.
|
||||
func (i *Interceptor) Match(toolName string, input []byte) (Decision, bool) {
|
||||
rules, err := i.rules()
|
||||
if err != nil {
|
||||
return storeUnreadableDecision(), true
|
||||
}
|
||||
var possible *Decision
|
||||
for _, r := range rules {
|
||||
if ruleMatches(r, toolName, input) {
|
||||
m := ruleMatch(r, toolName, input)
|
||||
if m == argvPossible && possible == nil {
|
||||
d := possibleArgvDecision(r)
|
||||
possible = &d
|
||||
}
|
||||
if m == argvMatched && (possible == nil || r.Action == "deny") {
|
||||
msg := r.Message
|
||||
if msg == "" {
|
||||
msg = defaultMessage(r.Action, r.Name)
|
||||
@@ -733,9 +743,44 @@ func (i *Interceptor) Match(toolName string, input []byte) (Decision, bool) {
|
||||
}, true
|
||||
}
|
||||
}
|
||||
if possible != nil {
|
||||
return *possible, true
|
||||
}
|
||||
return Decision{}, false
|
||||
}
|
||||
|
||||
// possibleArgvDecision answers a deny or ask argv rule that may match: a part
|
||||
// of the command that may run the rule's program is only known when it runs.
|
||||
// An ask rule asks as configured. A deny rule asks too, and its approval
|
||||
// times out to deny: denying would also refuse every ordinary command whose
|
||||
// program is a variable or that pipes a download into a shell, with no way
|
||||
// for an operator to let one through, while the ask still runs nothing
|
||||
// without an operator's approval.
|
||||
func possibleArgvDecision(r compiledRule) Decision {
|
||||
d := persistenceDecision(r)
|
||||
if r.Action == "deny" {
|
||||
d.Action = "ask"
|
||||
d.TimeoutAction = "deny"
|
||||
}
|
||||
d.Message = "intercept rule [" + r.Name + "] may match this command: part of it is only known when it runs, manual approval required"
|
||||
return d
|
||||
}
|
||||
|
||||
// ruleMatch is ruleMatches, keeping apart a deny or ask argv rule that may
|
||||
// match from one that matches.
|
||||
func ruleMatch(r compiledRule, toolName string, input []byte) argvMatch {
|
||||
if !r.bad && r.MatchType == "argv" && (r.Action == "deny" || r.Action == "ask") {
|
||||
if r.MatchTarget != "tool_input" {
|
||||
return argvNoMatch
|
||||
}
|
||||
return argvCompoundMatch(r.argv, toolName, input)
|
||||
}
|
||||
if ruleMatches(r, toolName, input) {
|
||||
return argvMatched
|
||||
}
|
||||
return argvNoMatch
|
||||
}
|
||||
|
||||
// builtinRulePrefix marks the rules seeded by the platform (db.seedDefaultInterceptRules
|
||||
// and its v2/v3 migrations).
|
||||
const builtinRulePrefix = "[built-in]"
|
||||
@@ -813,7 +858,8 @@ func ruleMatches(r compiledRule, toolName string, input []byte) bool {
|
||||
// Allow rules stay strictly limited to a single simple command with
|
||||
// exact derived prefix and denylist enforcement. Deny and ask rules
|
||||
// walk every call in a compound Bash command, stripping known wrappers
|
||||
// and recursing into eval / shell -c payloads.
|
||||
// and recursing into eval / shell -c payloads. One that may match
|
||||
// counts as a match here; Match asks for it instead (ruleMatch).
|
||||
if r.Action == "allow" {
|
||||
if CheckArgvAllow(r.argv) != nil {
|
||||
return false
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package sandbox
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Every image the repository's Dockerfiles build from must be pinned by
|
||||
// digest (tag@sha256:...), so a rebuild runs the reviewed base and not
|
||||
// whatever the tag points to that day. Dependabot keeps the digests current.
|
||||
func TestDockerfileBaseImagesArePinnedByDigest(t *testing.T) {
|
||||
files, err := filepath.Glob(filepath.Join("..", "Dockerfile*"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
files = append(files, filepath.Join("..", "egress-guard", "Dockerfile"))
|
||||
for _, want := range []string{"Dockerfile", "Dockerfile.runner", "Dockerfile.worker", "Dockerfile.egress-proxy"} {
|
||||
found := false
|
||||
for _, f := range files {
|
||||
if filepath.Base(f) == want {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("%s not found next to the module root", want)
|
||||
}
|
||||
}
|
||||
digest := regexp.MustCompile(`^[^@\s]+:[^@\s]+@sha256:[0-9a-f]{64}$`)
|
||||
for _, f := range files {
|
||||
raw, err := os.ReadFile(f)
|
||||
if err != nil {
|
||||
t.Fatalf("read %s: %v", f, err)
|
||||
}
|
||||
stages := map[string]bool{}
|
||||
froms := 0
|
||||
for i, line := range strings.Split(strings.ReplaceAll(string(raw), "\r\n", "\n"), "\n") {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) == 0 || !strings.EqualFold(fields[0], "FROM") {
|
||||
continue
|
||||
}
|
||||
froms++
|
||||
args := fields[1:]
|
||||
for len(args) > 0 && strings.HasPrefix(args[0], "--") {
|
||||
args = args[1:]
|
||||
}
|
||||
if len(args) == 0 {
|
||||
t.Errorf("%s:%d: FROM without an image", f, i+1)
|
||||
continue
|
||||
}
|
||||
image := args[0]
|
||||
if !stages[strings.ToLower(image)] && image != "scratch" && !digest.MatchString(image) {
|
||||
t.Errorf("%s:%d: FROM %s is not pinned as tag@sha256:<digest>", f, i+1, image)
|
||||
}
|
||||
if len(args) >= 3 && strings.EqualFold(args[1], "AS") {
|
||||
stages[strings.ToLower(args[2])] = true
|
||||
}
|
||||
}
|
||||
if froms == 0 {
|
||||
t.Errorf("%s: no FROM line", f)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/Autumn-27/artex/agent"
|
||||
)
|
||||
|
||||
// Environment of the agent processes. When a process crosses from the server's
|
||||
@@ -23,8 +25,9 @@ import (
|
||||
// executorEnvNames are the server variables an agent process keeps: the search
|
||||
// path and locale, the temp directory, the non-interactive defaults Norma sets, the
|
||||
// proxy and CA trust variables the agents pass to their shells (agent.proxyEnv),
|
||||
// the browser location of the image (Dockerfile), and the shim's own non-secret
|
||||
// variables. HOME and XDG_CACHE_HOME are replaced by the executor's home.
|
||||
// the browser location of the image (Dockerfile), the shim's own non-secret
|
||||
// variables, and the task name the agents give their shells (agent.ExecTaskEnv).
|
||||
// HOME and XDG_CACHE_HOME are replaced by the executor's home.
|
||||
var executorEnvNames = nameSet(
|
||||
"PATH", "HOME", "XDG_CACHE_HOME",
|
||||
"LANG", "LANGUAGE", "TERM", "TZ", "TMPDIR",
|
||||
@@ -37,6 +40,7 @@ var executorEnvNames = nameSet(
|
||||
"SSL_CERT_FILE", "CURL_CA_BUNDLE", "REQUESTS_CA_BUNDLE", "GIT_SSL_CAINFO", "NODE_EXTRA_CA_CERTS",
|
||||
"PLAYWRIGHT_BROWSERS_PATH",
|
||||
envExecBash, envExecUID, envExecGID, envExecHome,
|
||||
agent.ExecTaskEnv,
|
||||
)
|
||||
|
||||
func nameSet(names ...string) map[string]bool {
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
//go:build linux
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Autumn-27/artex/agent"
|
||||
)
|
||||
|
||||
// TestSelectTaskProcsKeepsOtherTasks checks the task scoping of the local kill
|
||||
// switch on a fixed process table: every task runs as the executor uid, and
|
||||
// pausing task 1 must select task 1's processes only, never task 10's, a
|
||||
// process the server did not start, or a shared process such as the browser.
|
||||
func TestSelectTaskProcsKeepsOtherTasks(t *testing.T) {
|
||||
exe := []int{10001, 10001, 10001, 10001}
|
||||
root := []int{0, 0, 0, 0}
|
||||
procs := []procEntry{
|
||||
{pid: 100, ppid: 1, pgrp: 100, stat: "S", uids: root, cwd: "/data"}, // the server
|
||||
{pid: 200, ppid: 100, pgrp: 200, stat: "S", uids: exe, cwd: "/data/tasks/1/main"},
|
||||
{pid: 201, ppid: 200, pgrp: 200, stat: "S", uids: exe, cwd: "/tmp"}, // task 1 child that left the directory
|
||||
{pid: 202, ppid: 100, pgrp: 202, stat: "S", uids: exe, cwd: "/", task: "1"}, // task 1 daemon: setsid, reparented, cd /
|
||||
{pid: 203, ppid: 200, pgrp: 200, stat: "Z", uids: exe, cwd: "/data/tasks/1/main"}, // zombie
|
||||
{pid: 204, ppid: 100, pgrp: 204, stat: "S", uids: root, cwd: "/data/tasks/1/main"}, // server identity
|
||||
{pid: 300, ppid: 100, pgrp: 300, stat: "S", uids: exe, cwd: "/data/tasks/10/main"},
|
||||
{pid: 301, ppid: 300, pgrp: 300, stat: "S", uids: exe, cwd: "/data/tasks/1/i4"}, // task 10 child inside task 1's directory
|
||||
{pid: 302, ppid: 100, pgrp: 200, stat: "S", uids: exe, cwd: "/data/tasks/10/i2", task: "10"}, // task 10 process in task 1's group
|
||||
{pid: 303, ppid: 100, pgrp: 303, stat: "S", uids: exe, cwd: "/data/tasks/1/main", task: "10"}, // task 10 daemon inside task 1's directory
|
||||
{pid: 400, ppid: 1, pgrp: 400, stat: "S", uids: exe, cwd: "/data/tasks/1/main"}, // not started by the server
|
||||
{pid: 401, ppid: 1, pgrp: 401, stat: "S", uids: exe, cwd: "/tmp"},
|
||||
{pid: 500, ppid: 100, pgrp: 500, stat: "S", uids: exe, cwd: "/data"}, // shared browser
|
||||
}
|
||||
priv := ExecPrivilege{Enabled: true, UID: 10001, GID: 10001}
|
||||
cases := []struct {
|
||||
name string
|
||||
taskDir string
|
||||
priv ExecPrivilege
|
||||
pids, grps []int
|
||||
}{
|
||||
{"task1_executor", "/data/tasks/1", priv, []int{200, 201, 202}, []int{202}},
|
||||
{"task1_server_identity", "/data/tasks/1", ExecPrivilege{}, []int{200, 201, 202, 204}, []int{202, 204}},
|
||||
{"task10_executor", "/data/tasks/10", priv, []int{300, 301, 302, 303}, []int{300, 303}},
|
||||
{"no_task_dir", "", priv, nil, nil},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
pids, grps := selectTaskProcs(procs, 100, 100, tc.taskDir, tc.priv)
|
||||
slices.Sort(pids)
|
||||
slices.Sort(grps)
|
||||
if !slices.Equal(pids, tc.pids) || !slices.Equal(grps, tc.grps) {
|
||||
t.Fatalf("selectTaskProcs(%q) = pids %v groups %v, want pids %v groups %v", tc.taskDir, pids, grps, tc.pids, tc.grps)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// scopeFixture runs real processes for two tasks (1 and 10) and a neutral one
|
||||
// under a data directory, as the engine's agent runs would.
|
||||
type scopeFixture struct {
|
||||
dataDir string
|
||||
own []int // task 1
|
||||
others []int // task 10 and the neutral process
|
||||
}
|
||||
|
||||
func startScopeFixture(t *testing.T) *scopeFixture {
|
||||
t.Helper()
|
||||
enableLocalKillSubreaper() // as NewEngine does: escaped daemons stay our descendants
|
||||
f := &scopeFixture{dataDir: t.TempDir()}
|
||||
dirA := filepath.Join(f.dataDir, "tasks", "1", "main")
|
||||
dirB := filepath.Join(f.dataDir, "tasks", "10", "main")
|
||||
neutral := t.TempDir()
|
||||
for _, d := range []string{dirA, dirB} {
|
||||
if err := os.MkdirAll(d, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var all []int
|
||||
t.Cleanup(func() {
|
||||
for _, pid := range all {
|
||||
_ = syscall.Kill(pid, syscall.SIGKILL)
|
||||
}
|
||||
})
|
||||
start := func(dir, task, script string) int {
|
||||
cmd := exec.Command("sh", "-c", script)
|
||||
cmd.Dir = dir
|
||||
cmd.Env = os.Environ()
|
||||
if task != "" {
|
||||
cmd.Env = append(cmd.Env, agent.ExecTaskEnv+"="+task)
|
||||
}
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
if err := cmd.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
all = append(all, cmd.Process.Pid)
|
||||
go func() { _ = cmd.Wait() }()
|
||||
return cmd.Process.Pid
|
||||
}
|
||||
// startDaemon runs script, which writes the pid of a background process to a
|
||||
// file and exits, and returns that pid.
|
||||
startDaemon := func(dir, task, script string) int {
|
||||
pidFile := filepath.Join(t.TempDir(), "pid")
|
||||
start(dir, task, fmt.Sprintf(script, pidFile))
|
||||
pid := waitForPIDs(t, pidFile, 1, 5*time.Second)[0]
|
||||
all = append(all, pid)
|
||||
return pid
|
||||
}
|
||||
|
||||
// Task 1: a command in its run directory, a shell that left it with its child,
|
||||
// and a setsid daemon that left it after its parent exited.
|
||||
f.own = append(f.own, start(dirA, "", "exec sleep 300"))
|
||||
pidFile := filepath.Join(t.TempDir(), "pid")
|
||||
f.own = append(f.own, start(dirA, "1", fmt.Sprintf("cd /; sleep 300 & echo $! > %q; wait", pidFile)))
|
||||
f.own = append(f.own, waitForPIDs(t, pidFile, 1, 5*time.Second)[0])
|
||||
f.own = append(f.own, startDaemon(dirA, "1", "cd /; setsid sleep 300 </dev/null >/dev/null 2>&1 & echo $! > %q"))
|
||||
|
||||
// Task 10: a command in its run directory, one that moved into task 1's run
|
||||
// directory, and a daemon there. The neutral process stands for a process of
|
||||
// the server that belongs to no task (the shared browser, a chat session).
|
||||
f.others = append(f.others, start(dirB, "10", "exec sleep 300"))
|
||||
f.others = append(f.others, start(dirB, "10", fmt.Sprintf("cd %q; exec sleep 300", dirA)))
|
||||
f.others = append(f.others, startDaemon(dirB, "10", "cd "+strconv.Quote(dirA)+"; setsid sleep 300 </dev/null >/dev/null 2>&1 & echo $! > %q"))
|
||||
f.others = append(f.others, start(neutral, "", "exec sleep 300"))
|
||||
|
||||
time.Sleep(100 * time.Millisecond) // let the shells reach their cd and exec
|
||||
return f
|
||||
}
|
||||
|
||||
// TestFindLocalTaskPIDsSelectsOnlyItsTask runs real processes for two tasks and
|
||||
// a neutral process and checks that the scan for task 1 finds all of task 1's
|
||||
// processes and none of the others, with the privilege drop off and on.
|
||||
func TestFindLocalTaskPIDsSelectsOnlyItsTask(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
priv func(t *testing.T) ExecPrivilege
|
||||
}{
|
||||
{"server_identity", func(*testing.T) ExecPrivilege { return ExecPrivilege{} }},
|
||||
{"executor_uid", func(t *testing.T) ExecPrivilege {
|
||||
if os.Getuid() == 0 {
|
||||
t.Skip("needs a non-root uid to stand for the executor uid; TestSelectTaskProcsKeepsOtherTasks covers the uid filter")
|
||||
}
|
||||
return ExecPrivilege{Enabled: true, UID: uint32(os.Getuid()), GID: uint32(os.Getgid())}
|
||||
}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
priv := tc.priv(t)
|
||||
f := startScopeFixture(t)
|
||||
got := findLocalTaskPIDs(filepath.Join(f.dataDir, "tasks", "1"), priv)
|
||||
for _, pid := range f.own {
|
||||
if !slices.Contains(got, pid) {
|
||||
t.Errorf("task 1 process %d not selected (selected %v)", pid, got)
|
||||
}
|
||||
}
|
||||
for _, pid := range f.others {
|
||||
if slices.Contains(got, pid) {
|
||||
t.Errorf("process %d of another task or of no task selected for task 1 (selected %v)", pid, got)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestEnginePauseAndDeleteKillOnlyTheirTask pauses (and, separately, starts the
|
||||
// deletion of) task 1 through the engine and checks that task 1's processes die
|
||||
// while task 10's processes and the neutral process keep running.
|
||||
func TestEnginePauseAndDeleteKillOnlyTheirTask(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
stop func(e *Engine)
|
||||
}{
|
||||
{"pause", func(e *Engine) { e.Pause("1", agent.AbortPausedByUser) }},
|
||||
{"delete", func(e *Engine) { e.BeginDelete("1") }},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
f := startScopeFixture(t)
|
||||
e := NewEngine(nil)
|
||||
e.SetKillSwitchConfig(f.dataDir, ExecPrivilege{})
|
||||
tc.stop(e)
|
||||
assertAllPIDsDeadWithin(t, f.own, 5*time.Second)
|
||||
for _, pid := range f.others {
|
||||
if !pidAlive(pid) {
|
||||
t.Errorf("process %d of another task or of no task was killed by the %s of task 1", pid, tc.name)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
+135
-65
@@ -11,6 +11,8 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/Autumn-27/artex/agent"
|
||||
)
|
||||
|
||||
type procEntry struct {
|
||||
@@ -19,6 +21,8 @@ type procEntry struct {
|
||||
pgrp int
|
||||
stat string
|
||||
uids []int
|
||||
cwd string // working directory, "" when unreadable
|
||||
task string // value of agent.ExecTaskEnv in the start environment, or ""
|
||||
}
|
||||
|
||||
func readProcTable() []procEntry {
|
||||
@@ -58,6 +62,17 @@ func readProcTable() []procEntry {
|
||||
continue
|
||||
}
|
||||
pe := procEntry{pid: pid, ppid: ppid, pgrp: pgrp, stat: fields[0]}
|
||||
if cwd, err := os.Readlink(filepath.Join("/proc", name, "cwd")); err == nil {
|
||||
pe.cwd = cwd
|
||||
}
|
||||
if envRaw, err := os.ReadFile(filepath.Join("/proc", name, "environ")); err == nil {
|
||||
for _, kv := range strings.Split(string(envRaw), "\x00") {
|
||||
if v, ok := strings.CutPrefix(kv, agent.ExecTaskEnv+"="); ok {
|
||||
pe.task = v
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if statusRaw, err := os.ReadFile(filepath.Join("/proc", name, "status")); err == nil {
|
||||
for _, line := range strings.Split(string(statusRaw), "\n") {
|
||||
if strings.HasPrefix(line, "Uid:") {
|
||||
@@ -92,96 +107,145 @@ func (p procEntry) hasUID(uid int) bool {
|
||||
// Wait4 on direct children; process liveness checks ignore Z/X zombie states.
|
||||
func reapDirectChildren() {}
|
||||
|
||||
// findLocalTaskPIDs scans /proc without trusting any agent-writable state.
|
||||
// When priv.Enabled (isolated executor UID), every non-zombie process owning
|
||||
// priv.UID is returned (cannot be escaped via setsid, nohup, env -i, or double-fork).
|
||||
// When !priv.Enabled (dev/test mode with PR_SET_CHILD_SUBREAPER), every descendant
|
||||
// of os.Getpid() whose process group differs from os.Getpgrp() (covering Norma's
|
||||
// Setpgid shells, setsid/nohup children, and reparented double-fork daemons) is returned.
|
||||
// findLocalTaskPIDs returns the live processes of the task whose directory is
|
||||
// taskDir (see selectTaskProcs), read from /proc.
|
||||
func findLocalTaskPIDs(taskDir string, priv ExecPrivilege) []int {
|
||||
self := os.Getpid()
|
||||
selfPGID := syscall.Getpgrp()
|
||||
procs := readProcTable()
|
||||
if len(procs) == 0 {
|
||||
return nil
|
||||
}
|
||||
pids, _ := findLocalTaskProcs(taskDir, priv)
|
||||
return pids
|
||||
}
|
||||
|
||||
if priv.Enabled && priv.UID > 0 {
|
||||
var matched []int
|
||||
for _, p := range procs {
|
||||
if p.pid == self || p.isZombie() {
|
||||
continue
|
||||
}
|
||||
if p.hasUID(int(priv.UID)) {
|
||||
matched = append(matched, p.pid)
|
||||
}
|
||||
// findLocalTaskProcs is findLocalTaskPIDs plus the process groups that hold only
|
||||
// processes of the task, both taken from one /proc snapshot.
|
||||
func findLocalTaskProcs(taskDir string, priv ExecPrivilege) (pids, groups []int) {
|
||||
dir := resolveTaskDir(taskDir)
|
||||
if dir == "" {
|
||||
return nil, nil
|
||||
}
|
||||
return selectTaskProcs(readProcTable(), os.Getpid(), syscall.Getpgrp(), dir, priv)
|
||||
}
|
||||
|
||||
// resolveTaskDir returns taskDir as an absolute path with symlinks resolved, the
|
||||
// form the kernel reports in /proc/<pid>/cwd, or "" for no task directory.
|
||||
func resolveTaskDir(taskDir string) string {
|
||||
if strings.TrimSpace(taskDir) == "" {
|
||||
return ""
|
||||
}
|
||||
abs, err := filepath.Abs(taskDir)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if real, err := filepath.EvalSymlinks(abs); err == nil {
|
||||
return real
|
||||
}
|
||||
return abs
|
||||
}
|
||||
|
||||
// selectTaskProcs picks the processes of one task from a process table. In
|
||||
// local mode every task runs as the same executor uid, so the uid alone cannot
|
||||
// tell the tasks apart. Walking down from the server, the first process that
|
||||
// names a task decides the owner of its whole subtree: its agent.ExecTaskEnv
|
||||
// variable, which the planner and the worker put in the environment of every
|
||||
// Bash they start, or else the task directory that holds its working directory
|
||||
// (every agent run starts in tasks/<id>/main or tasks/<id>/i<N>). Descendants
|
||||
// keep that owner wherever they move: a child of task A that changes into task
|
||||
// B's directory stays A's. A process can only rename its own subtree this way,
|
||||
// never another task's. Only descendants of self, the server, are considered:
|
||||
// the engine makes the server a child subreaper, so a task process that escaped
|
||||
// with setsid, nohup or a double fork is reparented to it and stays in the
|
||||
// walk, and a process the server did not start is never selected. When priv is
|
||||
// enabled, only processes running as the executor uid are selected, as before.
|
||||
//
|
||||
// groups lists the process groups (other than selfPGID) whose every live member
|
||||
// is selected: signalling such a group reaches no process of another task, even
|
||||
// one that joined a group of this task.
|
||||
//
|
||||
// Known limit: a process that lost its task ancestor (reparented to the server
|
||||
// after setsid or a double fork), left the task directory and cleared the
|
||||
// variable (env -i) is not found: nothing it cannot change ties it to a task.
|
||||
func selectTaskProcs(procs []procEntry, self, selfPGID int, taskDir string, priv ExecPrivilege) (pids, groups []int) {
|
||||
if taskDir == "" {
|
||||
return nil, nil
|
||||
}
|
||||
taskID := filepath.Base(taskDir)
|
||||
tasksRoot := filepath.Dir(taskDir) + string(filepath.Separator)
|
||||
// taskOf returns the task a process names, or "".
|
||||
taskOf := func(p procEntry) string {
|
||||
if p.task != "" {
|
||||
return p.task
|
||||
}
|
||||
return matched
|
||||
rest, ok := strings.CutPrefix(p.cwd, tasksRoot)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
id, _, _ := strings.Cut(rest, string(filepath.Separator))
|
||||
return id
|
||||
}
|
||||
|
||||
children := make(map[int][]procEntry, len(procs))
|
||||
for _, p := range procs {
|
||||
children[p.ppid] = append(children[p.ppid], p)
|
||||
}
|
||||
|
||||
cleanTaskDir := ""
|
||||
if strings.TrimSpace(taskDir) != "" {
|
||||
if abs, err := filepath.Abs(taskDir); err == nil {
|
||||
cleanTaskDir = abs
|
||||
}
|
||||
}
|
||||
var matched []int
|
||||
selected := map[int]bool{}
|
||||
seen := map[int]bool{}
|
||||
var walk func(parent int, inheritedMatch bool)
|
||||
walk = func(parent int, inheritedMatch bool) {
|
||||
var walk func(parent int, owner string)
|
||||
walk = func(parent int, owner string) {
|
||||
for _, ch := range children[parent] {
|
||||
if ch.pid == self || seen[ch.pid] {
|
||||
continue
|
||||
}
|
||||
seen[ch.pid] = true
|
||||
inTask := inheritedMatch || ch.pgrp != selfPGID
|
||||
if !inTask && cleanTaskDir != "" {
|
||||
if cwd, err := os.Readlink(filepath.Join("/proc", strconv.Itoa(ch.pid), "cwd")); err == nil {
|
||||
if cwd == cleanTaskDir || strings.HasPrefix(cwd, cleanTaskDir+string(filepath.Separator)) {
|
||||
inTask = true
|
||||
}
|
||||
}
|
||||
own := owner
|
||||
if own == "" {
|
||||
own = taskOf(ch)
|
||||
}
|
||||
if inTask && !ch.isZombie() {
|
||||
matched = append(matched, ch.pid)
|
||||
if own == taskID && !ch.isZombie() && (!priv.Enabled || ch.hasUID(int(priv.UID))) {
|
||||
selected[ch.pid] = true
|
||||
pids = append(pids, ch.pid)
|
||||
}
|
||||
walk(ch.pid, inTask)
|
||||
walk(ch.pid, own)
|
||||
}
|
||||
}
|
||||
walk(self, false)
|
||||
return matched
|
||||
walk(self, "")
|
||||
|
||||
// A group is whole while every live member seen so far is selected.
|
||||
whole := map[int]bool{}
|
||||
for _, p := range procs {
|
||||
if p.pgrp <= 1 || p.pgrp == selfPGID || p.isZombie() {
|
||||
continue
|
||||
}
|
||||
if ok, known := whole[p.pgrp]; !known || ok {
|
||||
whole[p.pgrp] = selected[p.pid]
|
||||
}
|
||||
}
|
||||
added := map[int]bool{}
|
||||
for _, p := range procs {
|
||||
if selected[p.pid] && whole[p.pgrp] && !added[p.pgrp] {
|
||||
added[p.pgrp] = true
|
||||
groups = append(groups, p.pgrp)
|
||||
}
|
||||
}
|
||||
return pids, groups
|
||||
}
|
||||
|
||||
// KillLocalTaskProcesses terminates all live local processes belonging to a task
|
||||
// (including setsid, nohup, and nested double-fork daemons) using /proc directly
|
||||
// without trusting any agent-writable state. Sends SIGTERM, polls up to 2s, then
|
||||
// loops SIGKILL until none remain (well within the 5s pause SLA).
|
||||
// KillLocalTaskProcesses terminates the live local processes of one task
|
||||
// (including its setsid, nohup and nested double-fork daemons, see
|
||||
// selectTaskProcs) using /proc directly, and leaves the processes of other tasks
|
||||
// alone. Sends SIGTERM, polls up to 2s, then loops SIGKILL until none remain
|
||||
// (well within the 5s pause SLA).
|
||||
func KillLocalTaskProcesses(taskDir string, priv ExecPrivilege) error {
|
||||
if runtime.GOOS != "linux" {
|
||||
return nil
|
||||
}
|
||||
selfPGID := syscall.Getpgrp()
|
||||
// Sweep once immediately, and if nothing matched yet, wait briefly for
|
||||
// cancelExec to trigger child reparenting before declaring clean.
|
||||
pids := findLocalTaskPIDs(taskDir, priv)
|
||||
pids, groups := findLocalTaskProcs(taskDir, priv)
|
||||
if len(pids) == 0 {
|
||||
time.Sleep(40 * time.Millisecond)
|
||||
pids = findLocalTaskPIDs(taskDir, priv)
|
||||
pids, groups = findLocalTaskProcs(taskDir, priv)
|
||||
if len(pids) == 0 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
for _, pid := range pids {
|
||||
if pgid, err := syscall.Getpgid(pid); err == nil && pgid > 1 && pgid != selfPGID {
|
||||
_ = syscall.Kill(-pgid, syscall.SIGTERM)
|
||||
}
|
||||
_ = syscall.Kill(pid, syscall.SIGTERM)
|
||||
}
|
||||
signalTaskProcs(pids, groups, syscall.SIGTERM)
|
||||
|
||||
deadline := time.Now().Add(2 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
@@ -193,16 +257,11 @@ func KillLocalTaskProcesses(taskDir string, priv ExecPrivilege) error {
|
||||
}
|
||||
|
||||
for round := 0; round < 15; round++ {
|
||||
rem := findLocalTaskPIDs(taskDir, priv)
|
||||
rem, remGroups := findLocalTaskProcs(taskDir, priv)
|
||||
if len(rem) == 0 {
|
||||
return nil
|
||||
}
|
||||
for _, pid := range rem {
|
||||
if pgid, err := syscall.Getpgid(pid); err == nil && pgid > 1 && pgid != selfPGID {
|
||||
_ = syscall.Kill(-pgid, syscall.SIGKILL)
|
||||
}
|
||||
_ = syscall.Kill(pid, syscall.SIGKILL)
|
||||
}
|
||||
signalTaskProcs(rem, remGroups, syscall.SIGKILL)
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
reapDirectChildren()
|
||||
}
|
||||
@@ -211,3 +270,14 @@ func KillLocalTaskProcesses(taskDir string, priv ExecPrivilege) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// signalTaskProcs sends sig to each whole task process group, which also
|
||||
// reaches members forked since the scan, and to each selected process.
|
||||
func signalTaskProcs(pids, groups []int, sig syscall.Signal) {
|
||||
for _, pgid := range groups {
|
||||
_ = syscall.Kill(-pgid, sig)
|
||||
}
|
||||
for _, pid := range pids {
|
||||
_ = syscall.Kill(pid, sig)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The shared browser and the browser MCP run the Chromium builds that the
|
||||
// image's Playwright packages install, with --no-sandbox. Each package must
|
||||
// stay on a release that bundles Chromium 157.0.8103.50 or later. The
|
||||
// minimums are the first releases that do, read from each release's
|
||||
// playwright-core browsers.json:
|
||||
// - playwright 1.65.0: Chromium 158.0.8127.18 (1.64.1 ships 156.0.8078.4)
|
||||
// - @playwright/mcp 0.0.85: 158.0.8127.18 (0.0.84 ships 157.0.8103.15)
|
||||
// - @playwright/cli 0.1.24: 158.0.8127.18 (0.1.23 ships 157.0.8103.15)
|
||||
var playwrightMinimumPins = map[string]string{
|
||||
"PLAYWRIGHT_VERSION": "1.65.0",
|
||||
"PLAYWRIGHT_MCP_VERSION": "0.0.85",
|
||||
"PLAYWRIGHT_CLI_VERSION": "0.1.24",
|
||||
}
|
||||
|
||||
func dockerfilePlaywrightPins(t *testing.T) map[string]string {
|
||||
t.Helper()
|
||||
raw, err := os.ReadFile(filepath.Join("..", "Dockerfile"))
|
||||
if err != nil {
|
||||
t.Fatalf("read Dockerfile: %v", err)
|
||||
}
|
||||
pins := map[string]string{}
|
||||
re := regexp.MustCompile(`(?m)^ARG (PLAYWRIGHT(?:_MCP|_CLI)?_VERSION)=(\S+)\s*$`)
|
||||
for _, m := range re.FindAllStringSubmatch(string(raw), -1) {
|
||||
if prev, ok := pins[m[1]]; ok && prev != m[2] {
|
||||
t.Fatalf("Dockerfile declares %s twice: %s and %s", m[1], prev, m[2])
|
||||
}
|
||||
pins[m[1]] = m[2]
|
||||
}
|
||||
for name := range playwrightMinimumPins {
|
||||
if pins[name] == "" {
|
||||
t.Fatalf("Dockerfile has no ARG %s", name)
|
||||
}
|
||||
}
|
||||
return pins
|
||||
}
|
||||
|
||||
// parseReleaseVersion accepts only a plain MAJOR.MINOR.PATCH release: a
|
||||
// prerelease or a tag such as "latest" does not name reviewed bytes.
|
||||
func parseReleaseVersion(v string) ([3]int, bool) {
|
||||
var out [3]int
|
||||
parts := strings.Split(v, ".")
|
||||
if len(parts) != 3 {
|
||||
return out, false
|
||||
}
|
||||
for i, p := range parts {
|
||||
n, err := strconv.Atoi(p)
|
||||
if err != nil || n < 0 || strconv.Itoa(n) != p {
|
||||
return out, false
|
||||
}
|
||||
out[i] = n
|
||||
}
|
||||
return out, true
|
||||
}
|
||||
|
||||
func versionAtLeast(got, floor [3]int) bool {
|
||||
for i := range got {
|
||||
if got[i] != floor[i] {
|
||||
return got[i] > floor[i]
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func TestDockerfilePlaywrightPinsBundleFixedChromium(t *testing.T) {
|
||||
pins := dockerfilePlaywrightPins(t)
|
||||
for name, floor := range playwrightMinimumPins {
|
||||
got, ok := parseReleaseVersion(pins[name])
|
||||
if !ok {
|
||||
t.Errorf("Dockerfile ARG %s=%s is not an exact release version", name, pins[name])
|
||||
continue
|
||||
}
|
||||
want, _ := parseReleaseVersion(floor)
|
||||
if !versionAtLeast(got, want) {
|
||||
t.Errorf("Dockerfile ARG %s=%s bundles Chromium older than 157.0.8103.50; need %s or later", name, pins[name], floor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Skills that tell an agent to install a Playwright package must name the
|
||||
// version the image ships, never a floating tag.
|
||||
func TestSkillPlaywrightInstallsMatchDockerfilePins(t *testing.T) {
|
||||
pins := dockerfilePlaywrightPins(t)
|
||||
want := map[string]string{
|
||||
"@playwright/cli": pins["PLAYWRIGHT_CLI_VERSION"],
|
||||
"@playwright/mcp": pins["PLAYWRIGHT_MCP_VERSION"],
|
||||
"@playwright/test": pins["PLAYWRIGHT_VERSION"],
|
||||
"playwright": pins["PLAYWRIGHT_VERSION"],
|
||||
}
|
||||
re := regexp.MustCompile(`(@playwright/(?:cli|mcp|test)|playwright)@([0-9A-Za-z.\-]+)`)
|
||||
root := filepath.Join("..", "skills")
|
||||
seen := 0
|
||||
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() || filepath.Ext(path) != ".md" {
|
||||
return nil
|
||||
}
|
||||
raw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
text := string(raw)
|
||||
for _, m := range re.FindAllStringSubmatchIndex(text, -1) {
|
||||
pkg, ver := text[m[2]:m[3]], text[m[4]:m[5]]
|
||||
if pkg == "playwright" && m[2] > 0 {
|
||||
// Part of another name, such as create-playwright@ or a path.
|
||||
if c := text[m[2]-1]; c == '/' || c == '-' || c == '_' || c == '.' ||
|
||||
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') {
|
||||
continue
|
||||
}
|
||||
}
|
||||
seen++
|
||||
if ver != want[pkg] {
|
||||
t.Errorf("%s: %s@%s, want %s@%s (the Dockerfile pin)", path, pkg, ver, pkg, want[pkg])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("walk skills: %v", err)
|
||||
}
|
||||
if seen == 0 {
|
||||
t.Fatal("no Playwright install found in skills/; the playwright-cli skill should name its pinned version")
|
||||
}
|
||||
}
|
||||
@@ -301,7 +301,7 @@ When the server validates sessions step by step (signed cookies that cannot be f
|
||||
3. **Phase 1b**: path anchor window expansion + binding layer → `param_candidates.json` (section J)
|
||||
4. Reverse-engineer A1/A2/A3 → write a site-specific `config.json`
|
||||
5. **Read and adjust** `runtime_harvest.js` / `preload.js` before executing
|
||||
6. `runtimeMode=depth`: `npm install` → run the adjusted harvest script
|
||||
6. `runtimeMode=depth`: `npm ci --ignore-scripts` (installs the versions in `package-lock.json`) → run the adjusted harvest script
|
||||
7. `runtimeMode=coverage/both`: inject the adjusted preload at document-start → browser MCP dynamic enumeration + **parameter trigger matrix**
|
||||
8. Modules do not render → **section I permission-tree restoration** → patch stubs → rerun
|
||||
9. Multi-sample parameter diff + error-driven inference → `params_merged.json`
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* 2. interceptor gate-> rewrite the "unauthorized" code field to success
|
||||
* 3. content gate -> stub the menu/permission endpoint with a full-feature payload
|
||||
*
|
||||
* Requires puppeteer-core + a system Chromium. ( cd scripts && npm install )
|
||||
* Requires puppeteer-core + a system Chromium. ( cd scripts && npm ci --ignore-scripts )
|
||||
*
|
||||
* config.json schema (all fields optional except baseUrl):
|
||||
* {
|
||||
@@ -38,7 +38,7 @@ const path = require('path');
|
||||
|
||||
let puppeteer;
|
||||
try { puppeteer = require('puppeteer-core'); }
|
||||
catch (e) { console.error("[!] run `npm install` in the scripts/ dir first (needs puppeteer-core)"); process.exit(1); }
|
||||
catch (e) { console.error("[!] run `npm ci --ignore-scripts` in the scripts/ dir first (needs puppeteer-core)"); process.exit(1); }
|
||||
|
||||
function loadCfg(p) {
|
||||
const c = JSON.parse(fs.readFileSync(p, 'utf8'));
|
||||
|
||||
@@ -351,7 +351,7 @@ npx --no-install playwright --version
|
||||
When local version is available, use `npx playwright cli` in all commands. Otherwise, install `playwright-cli` as a global command at the version ARTEX ships (upgrade deliberately, after reviewing the release):
|
||||
|
||||
```bash
|
||||
npm install -g @playwright/cli@0.1.22
|
||||
npm install -g @playwright/cli@0.1.25
|
||||
```
|
||||
|
||||
## Example: Form submission
|
||||
|
||||
@@ -153,10 +153,11 @@ test -f playwright.config.ts || test -f playwright.config.js
|
||||
npx --no-install playwright --version
|
||||
```
|
||||
|
||||
If there is no Playwright install, bootstrap one and let the user pick the defaults:
|
||||
If there is no Playwright install, add the test runner at the version ARTEX ships (its Chromium is already installed in the image), then write a minimal `playwright.config.ts` with `testDir: './tests'`:
|
||||
|
||||
```bash
|
||||
npm init playwright@latest
|
||||
npm init -y
|
||||
npm install --save-dev --save-exact @playwright/test@1.65.1
|
||||
```
|
||||
|
||||
### 1.2 Prerequisite: seed test
|
||||
|
||||
Reference in New Issue
Block a user