Skip to content

fix(intercept): treat curl's attached body values as mutating - #687

Open
shuhuNB515 wants to merge 1 commit into
BaaRai:mainfrom
shuhuNB515:fix/stateful-guard-attached-curl-values
Open

shuhuNB515 wants to merge 1 commit into
BaaRai:mainfrom
shuhuNB515:fix/stateful-guard-attached-curl-values

Conversation

@shuhuNB515

Copy link
Copy Markdown
Contributor

Problem

StatefulTargetGuard enforces two invariants per task and host: a mutating HTTP call is refused until a read-only GET/HEAD baseline has completed, and only one intent holds the mutation lease. ClassifyHTTPAction decides whether a Bash command mutates from the command text, and its body-flag list required a separator after -d, -F and -T:

(?:^|\s)(?:-d|-F|...)(?:[\s=@'"{\\]|$)

curl takes a short option's value fully attached, with no separator at all, so these are real mutations that matched nothing:

command what curl 8.21.0 actually sent
curl -dfoo=1 http://host/a POST /a body=b'foo=1'
curl -T/tmp/up.txt http://host/b PUT /b body=b'x'
curl -Ffile=@/tmp/up.txt http://host/c POST /c (multipart)

(Measured by running each command against a local echo server with curl 8.21.0 on darwin.)

Because they were classified read-only, CheckStatefulTool did not refuse them for a missing baseline, and RecordStatefulReadOnly then stored the mutation itself as the host's read-only baseline. That is a fail-open on a safety invariant: the first (actually mutating) request on a host both skipped the gate and poisoned the baseline for everything that followed.

Behavior

  • New curlAttachedBodyRe matches the letter directly after the dash, scoped to a curl invocation: \bcurl\b[^;&|]*\s-[dFT].
  • Among curl's short flags only d, F and T carry a body, and each is the only flag with that letter, so the match is unambiguous. Matching the value instead of the flag would false-positive (-Dheaders.txt contains a d), which is why the letter right after the dash is what is checked.
  • Scoped to curl because wget -T is a timeout, not an upload.
  • Read-only flags are unaffected: -D (dump headers), -f, -o, -b, -w, -H ... -I, and wget -T 10 --spider all still classify as read-only, and the spaced form curl -T shell.php still works (the old \bcurl\b...\s-T(?:\s|$) clause is folded into this one).
  • Not covered, and unchanged by this PR: a body flag inside a multi-letter cluster (curl -sSd...).

Tests

  • TestClassifyHTTPActionAttachedShortOptionValues pins the four mutating attached forms plus nine read-only shapes that must not regress, including -D- and -Dheaders.txt (the case-sensitivity trap: D is not d) and wget -T 10.
  • TestStatefulGuardRefusesAttachedValueUploadWithoutBaseline asserts the end-to-end consequence: curl -Tshell.php https://target.lab.local/upload/ is refused for a missing baseline and is not recorded as the baseline.

Both new tests fail on main before the fix:

--- FAIL: TestClassifyHTTPActionAttachedShortOptionValues
    curl -dfoo=1 ...: mutating = false, want true
    curl -Tshell.php ...: mutating = false, want true
    curl -Ffile=@payload.txt ...: mutating = false, want true
--- FAIL: TestStatefulGuardRefusesAttachedValueUploadWithoutBaseline
    attached-value upload was allowed with no baseline

Local validation on top of becc47a:

  • go test -p 1 ./... — pass
  • go test -race ./intercept/ -count=1 — pass
  • go build ./..., go vet ./..., gofmt -l — clean

A CHANGELOG entry is included under ### Fixed.

ClassifyHTTPAction required a separator after -d, -F and -T, but curl takes
the option value fully attached: -dfoo=1 posts a form body, -Tshell.php puts
a file and -Ffile=@payload sends a multipart body (verified against curl
8.21.0). Those commands were classified read-only, so the stateful target
guard skipped the pre-mutation baseline gate and RecordStatefulReadOnly
stored the mutation itself as the host's read-only baseline, leaving later
mutations on the host unguarded.

Match the letter directly after the dash, scoped to curl: among curl's short
flags only d, F and T carry a body, and each is the only flag with that
letter, so -D (dump headers), -f and -o stay read-only and wget's -T timeout
is not affected. A body flag inside a multi-letter cluster (-sSd...) is still
not detected, unchanged by this commit.

Co-authored-by: Copilot App <223556219+Copilot@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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant