Repository navigation
fix(intercept): treat curl's attached body values as mutating - #687
Open
shuhuNB515 wants to merge 1 commit into
Open
shuhuNB515 wants to merge 1 commit into
shuhuNB515 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
StatefulTargetGuardenforces 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.ClassifyHTTPActiondecides whether aBashcommand mutates from the command text, and its body-flag list required a separator after-d,-Fand-T:curl takes a short option's value fully attached, with no separator at all, so these are real mutations that matched nothing:
curl -dfoo=1 http://host/aPOST /a body=b'foo=1'curl -T/tmp/up.txt http://host/bPUT /b body=b'x'curl -Ffile=@/tmp/up.txt http://host/cPOST /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,
CheckStatefulTooldid not refuse them for a missing baseline, andRecordStatefulReadOnlythen 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
curlAttachedBodyRematches the letter directly after the dash, scoped to acurlinvocation:\bcurl\b[^;&|]*\s-[dFT].d,FandTcarry 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.txtcontains ad), which is why the letter right after the dash is what is checked.curlbecausewget -Tis a timeout, not an upload.-D(dump headers),-f,-o,-b,-w,-H ... -I, andwget -T 10 --spiderall still classify as read-only, and the spaced formcurl -T shell.phpstill works (the old\bcurl\b...\s-T(?:\s|$)clause is folded into this one).curl -sSd...).Tests
TestClassifyHTTPActionAttachedShortOptionValuespins the four mutating attached forms plus nine read-only shapes that must not regress, including-D-and-Dheaders.txt(the case-sensitivity trap:Dis notd) andwget -T 10.TestStatefulGuardRefusesAttachedValueUploadWithoutBaselineasserts 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
mainbefore the fix:Local validation on top of
becc47a:go test -p 1 ./...— passgo test -race ./intercept/ -count=1— passgo build ./...,go vet ./...,gofmt -l— cleanA CHANGELOG entry is included under
### Fixed.