Python
fix(security): record attached --output= download paths for provenance
Shakti Prasad Mohapatra54936e7f101c
diff --git a/coworker/provenance.py b/coworker/provenance.pyindex 3d6a3234..0c495be6 100644--- a/coworker/provenance.py+++ b/coworker/provenance.py@@ -183,6 +183,12 @@ def _shell_download_paths(command: str) -> list[str]:probe = token.lower() if folded else tokenif probe in flags and i + 1 < len(argv):out.append(argv[i + 1])+ elif probe.startswith("--") and "=" in probe:+ # Long flags accept an attached value (`--output=FILE`); token comparison+ # alone missed those spellings, dropping the download from the record.+ flag, _, value = probe.partition("=")+ if flag in flags and value:+ out.append(value)if program == "curl" and "-O" in argv[1:]:# curl -O saves under the URL's own basename.for candidate in argv[1:]:diff --git a/tests/test_provenance.py b/tests/test_provenance.pyindex 9ecf4721..08264fb2 100644--- a/tests/test_provenance.py+++ b/tests/test_provenance.py@@ -100,6 +100,31 @@ def test_shell_fetchers_record_their_output_path(command, expected):)+ "command,expected",+ [+ ("curl --output=tool.sh https://x.io/a", ["tool.sh"]),+ ("curl --output=/tmp/payload.sh https://x.io/a", ["/tmp/payload.sh"]),+ ("wget --output-document=tool.sh https://x.io/a", ["tool.sh"]),+ ],+)+def test_attached_output_values_record_the_download(command, expected):+ # `--output=FILE` is the same flag as `--output FILE`; token comparison alone missed+ # the attached spelling, so the fetch-then-execute floor stayed down afterwards.+ assert prov.created_paths("run_shell", {"command": command}, None) == (+ expected,+ DOWNLOADED,+ )+++def test_attached_output_value_feeds_the_downloaded_match(files):+ files.record(+ "run_shell", {"command": "curl https://x/p --output=/tmp/ws/p.sh"}, None, step=1+ )+ match = files.match("run_shell", {"command": "sh /tmp/ws/p.sh"}, step=2)+ assert match is not None and match.downloaded++def test_curl_capital_o_does_not_swallow_the_url():# `-o FILE` and `-O` are different curl flags; folding their case would record the URL# itself as the downloaded file.