From d1616e40235eb1dc02e0491787226f12b605c8d6 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Mon, 26 Oct 2026 11:06:53 -0500 Subject: [PATCH 1/2] fix(cold-store-reaper): keep R2 secret out of curl argv via stdin config (#983) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _curl_fetch passed --user : in argv, exposing the R2 secret in the local process list for up to the 900s fallback timeout — the pattern #948/#970 removed from push-fleet-feed.sh. Feed curl its config on stdin instead (--config - + subprocess input=): credentials stay in memory, never in argv or on disk, and curl --aws-sigv4 signing, one-attempt semantics and byte-count verification are unchanged. TestS3CurlFallback gains a subprocess.run-stub test asserting neither credential appears in any argv element — the guard for cold_store.py. All 5 TestS3CurlFallback tests pass. --- pkgs/cold-store-reaper/cold_store.py | 22 +++++++++---- .../tests/test_cold_store.py | 33 +++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/pkgs/cold-store-reaper/cold_store.py b/pkgs/cold-store-reaper/cold_store.py index ec730bccd7..be720d66b0 100755 --- a/pkgs/cold-store-reaper/cold_store.py +++ b/pkgs/cold-store-reaper/cold_store.py @@ -1526,9 +1526,11 @@ def _s3_get_via_curl( def _curl_fetch(self, url: str, access: str, secret: str) -> bytes: """GET `url` with curl, which does its own SigV4 signing (--aws-sigv4) and reads the proxy from the environment itself. - Credentials travel in argv — the local process list sees them, - as with any credentialed CLI — but they are scrubbed from every - error this raises, and nothing here is logged. + Credentials travel in a curl config fed on stdin (--config -), + never in argv — the local process list must not see them (the + --user argv form was issue #983, the pattern #948/#970 removed + from push-fleet-feed.sh) — and never on disk. They are scrubbed + from every error this raises, and nothing here is logged. """ argv = [ self.curl, @@ -1536,13 +1538,21 @@ def _curl_fetch(self, url: str, access: str, secret: str) -> bytes: "--fail", "--aws-sigv4", "aws:amz:auto:s3", - "--user", - f"{access}:{secret}", + "--config", + "-", url, ] + config = ( + 'user = "' + + f"{access}:{secret}".replace("\\", "\\\\").replace('"', '\\"') + + '"\n' + ).encode() try: proc = subprocess.run( - argv, capture_output=True, timeout=S3_CURL_TIMEOUT_SECONDS + argv, + input=config, + capture_output=True, + timeout=S3_CURL_TIMEOUT_SECONDS, ) except FileNotFoundError: raise ColdStoreError( diff --git a/pkgs/cold-store-reaper/tests/test_cold_store.py b/pkgs/cold-store-reaper/tests/test_cold_store.py index e25ced19e8..942d6c921f 100644 --- a/pkgs/cold-store-reaper/tests/test_cold_store.py +++ b/pkgs/cold-store-reaper/tests/test_cold_store.py @@ -1352,6 +1352,39 @@ def test_curl_never_invoked_on_urllib_happy_path(self): self.assertEqual(calls, []) self.assertEqual(result["sha256"], hashlib.sha256(body).hexdigest()) + def test_curl_fetch_keeps_credentials_out_of_argv(self): + """The spawned curl argv must never carry the credentials + (issue #983): _curl_fetch feeds curl its config on stdin + (--config -) instead of passing --user in argv, where the + local process list would see the secret for up to the 900s + fallback timeout. This test is the guard for cold_store.py in + the spirit of push-fleet-feed.guard.sh (#948/#970).""" + seen = {} + + def fake_run(argv, **kwargs): + seen["argv"] = argv + seen["kwargs"] = kwargs + return subprocess.CompletedProcess( + argv, 0, stdout=b"payload", stderr=b"" + ) + + with mock.patch.object(cold_store.subprocess, "run", fake_run): + body = self.store._curl_fetch( + "https://store.example/supabase-backups/some/key", + "test-access-key", + "test-secret-key", + ) + self.assertEqual(body, b"payload") + argv = seen["argv"] + self.assertNotIn("--user", argv) + for element in argv: + self.assertNotIn("test-access-key", element) + self.assertNotIn("test-secret-key", element) + # the credential arrives on stdin as a curl config instead + config = seen["kwargs"]["input"].decode() + self.assertIn('user = "test-access-key:test-secret-key"', config) + self.assertEqual(argv[argv.index("--config") + 1], "-") + def test_fallback_sizes_via_head_when_caller_gives_none(self): key = self._persistent_truncation() patcher, calls = self._stub_curl(self.BODY) From b136c03c970094f10fd1bdf8ca4f127b4785f0a1 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Mon, 26 Oct 2026 11:09:01 -0500 Subject: [PATCH 2/2] style(cold-store-reaper): ruff format the argv guard test (#983) --- pkgs/cold-store-reaper/tests/test_cold_store.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/cold-store-reaper/tests/test_cold_store.py b/pkgs/cold-store-reaper/tests/test_cold_store.py index 942d6c921f..c450be6f53 100644 --- a/pkgs/cold-store-reaper/tests/test_cold_store.py +++ b/pkgs/cold-store-reaper/tests/test_cold_store.py @@ -1364,9 +1364,7 @@ def test_curl_fetch_keeps_credentials_out_of_argv(self): def fake_run(argv, **kwargs): seen["argv"] = argv seen["kwargs"] = kwargs - return subprocess.CompletedProcess( - argv, 0, stdout=b"payload", stderr=b"" - ) + return subprocess.CompletedProcess(argv, 0, stdout=b"payload", stderr=b"") with mock.patch.object(cold_store.subprocess, "run", fake_run): body = self.store._curl_fetch(