Repository navigation
Add CURLTask(_:allowing:) to run a command without the flags that touch the machine - #430
Merged
Merged
Conversation
…ch the machine CURLTask.Capabilities (.localFiles, .disabledTLSVerification, .proxy, .dnsOverrides, .all) says what a command may do. A flag that needs a capability the task was not given throws CURLParsingError.unsupportedFlag while the command is parsed, before a file is opened. CURLTask(_:) allows everything. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #430 +/- ##
==========================================
+ Coverage 94.63% 94.76% +0.13%
==========================================
Files 464 464
Lines 19367 19387 +20
==========================================
+ Hits 18327 18372 +45
+ Misses 1040 1015 -25 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.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.
What
CURLTask(_:allowing:): a curl command from a source you do not control can run with none of the flags that touch the machine or weaken the connection. (Audit E17.) Additive:CURLTask(_:)allows everything, as it always did.CURLTask.Capabilitiesis anOptionSet:.localFiles-F name=@path(relative paths too, which resolve against the working directory),--cacert,--cert/-E,--key.disabledTLSVerification-k/--insecure.proxy-x/--proxy.dnsOverrides--resolve.allCURLTask(_:)allowsA flag that needs a capability the task was not given throws
CURLParsingError(.unsupportedFlag, token: <the flag>). It happens in the loop over the tokens ofCURLCommandParser.parseCommand, so before any file is opened and before the session or the request is built.Decisions
.unsupportedFlag, no new case inCURLParsingError.Context. A new case would be source-breaking for anyone who switches over it withoutdefault, and this change is meant to be purely additive. The cost: the context does not tell "not in the subset" from "not allowed here"; the token is the flag in both. Its documentation says so.-F name=@pathis a local file, a relative path included.-F name=value, a field of plain text, needs nothing.-o/--outputand the other flags that only shape curl's output stay accepted and ignored, with no capability: they do not touch the request, the response or this machine.CURLTask.untrusted(_:).allowing: []says the same, and the set can grow with the library without a second spelling.Tests
CURLTaskCapabilitiesTests(10 tests):[], and the error carries that flag as the token;.proxydoes not allow-k,.localFilesdoes not allow--resolve, and so on);.allallows everything at once;parseCommand(_:)withoutallowing:allows everything;[]still allows a plain request (method, headers, a body,-u,-L,--compressed,-s,-o) and a form of plain fields;-F file=@/nonexistent/...is never opened: with.localFilesthe same command fails opening the file with an error that is not aCURLParsingError, with[]it is refused first;CURLTask(_:allowing: [])throws before any network I/O;.allis their union.Checked by turning every
requireinto a no-op: the refusal tests, the two "other flags" tests, the never-opened one and the task one fail (51 issues).macOS full suite and the URLSession-only build pass locally.
swift format lint --strictis clean on the CURL sources and tests.🤖 Generated with Claude Code