Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/scripts/npm_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
entries = archive.infolist()
require(len(entries) == len({x.filename for x in entries}), "duplicate wheel entry")
for entry in entries:
require(entry.orig_filename == entry.filename, "noncanonical wheel filename")

Check warning on line 159 in .github/scripts/npm_package.py

View workflow job for this annotation

GitHub Actions / Ripr Rust Small on GitHub Hosted

ripr note static_unknown

Inspect the producer-owned review finding. Suggested test%3A Inspect the producer-owned review finding.
path = PurePosixPath(entry.filename)
require(not path.is_absolute() and ".." not in path.parts and "\\" not in entry.filename, "unsafe wheel path")
require(not stat.S_ISLNK(entry.external_attr >> 16), "wheel symlink")
Expand Down Expand Up @@ -320,6 +321,7 @@
require(sum(entry.file_size for entry in entries) <= 60_000_000, "oversized artifact content")
files = {}
for entry in entries:
require(entry.orig_filename == entry.filename, "noncanonical artifact filename")

Check warning on line 324 in .github/scripts/npm_package.py

View workflow job for this annotation

GitHub Actions / Ripr Rust Small on GitHub Hosted

ripr note static_unknown

Inspect the producer-owned review finding. Suggested test%3A Inspect the producer-owned review finding.
path = PurePosixPath(entry.filename)
require(entry.filename and not path.is_absolute() and ".." not in path.parts and "\\" not in entry.filename and str(path) == entry.filename.rstrip("/"), "unsafe artifact path")
mode = entry.external_attr >> 16
Expand Down
36 changes: 35 additions & 1 deletion .github/scripts/test_npm_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ def zip_bytes(files, link=None, no_exec=False):
with zipfile.ZipFile(out, "w") as archive:
for name, data in files.items():
entry = zipfile.ZipInfo(name)
entry.external_attr = (0o100755 if name.endswith("/ripr") and not no_exec else 0o100644) << 16
# Preserve the wire name: ZipInfo normalizes backslashes on Windows
# and truncates NUL suffixes before a malformed fixture is written.
entry.filename = name
logical_name = name.split("\x00", 1)[0].replace("\\", "/")
entry.external_attr = (0o100755 if logical_name.endswith("/ripr") and not no_exec else 0o100644) << 16
if name == link:
entry.external_attr = 0o120755 << 16
archive.writestr(entry, data)
Expand Down Expand Up @@ -490,6 +494,36 @@ def test_zip_digest_traversal_links_duplicates_and_unbounded_entries_fail(self):
with self.assertRaises(ValueError):
PACKAGE.read_qualification_zip(data, "sha256:" + PACKAGE.digest(data))

def test_artifact_zip_rejects_wire_names_normalized_by_zipinfo(self):
for separator in ("/", "\\"):
for name in ("a\\b", "consumer.json\x00suffix"):
data = zip_bytes({name: b"{}"})
with self.subTest(separator=separator, name=name):
# Exercise both reader behaviors on every host. Native
# Windows execution also reaches its real normalization.
with mock.patch.object(zipfile.os, "sep", separator):
with zipfile.ZipFile(io.BytesIO(data)) as archive:
self.assertEqual(archive.infolist()[0].orig_filename, name)
with self.assertRaises(ValueError):
PACKAGE.read_qualification_zip(data, "sha256:" + PACKAGE.digest(data))

def test_wheel_zip_rejects_wire_alias_of_expected_member(self):
pin, files = wheel_fixture()
native = next(name for name in files if name.endswith("/scripts/ripr"))
for separator in ("/", "\\"):
for alias in (native.replace("/", "\\"), native + "\x00suffix"):
malformed = dict(files)
malformed[alias] = malformed.pop(native)
data = zip_bytes(malformed)
expected = dict(pin, wheel_sha256=PACKAGE.digest(data))
with self.subTest(separator=separator, alias=alias):
with mock.patch.object(zipfile.os, "sep", separator):
with zipfile.ZipFile(io.BytesIO(data)) as archive:
entry = next(item for item in archive.infolist() if item.orig_filename == alias)
self.assertTrue(entry.external_attr >> 16 & 0o111)
with self.assertRaises(ValueError):
PACKAGE.inspect_wheel(data, expected)

def proof(self):
rows = [dict(route=route, probes=1, findings=1, follow_up_finding="probe:fixture")
for route in ("local", "global", "npm-exec", "npx")]
Expand Down
3 changes: 3 additions & 0 deletions docs/specs/RIPR-SPEC-0180-npm-native-bootstrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ relabelled or used as a fallback. Version authority remains Cargo. Packaging com
fields. Package creation fails on an uncommitted tracked tree, wrong input
bytes, unsupported metadata, unsafe archive entries, stale RECORD, missing
notices, or tarball identity/mode/provenance drift.
ZIP member names must retain their literal wire identity: backslashes and NUL
suffixes cannot be normalized into an otherwise expected artifact or wheel member.
This refusal applies on both Unix and Windows readers before member bytes are read.

Native execution and qualification retain explicit denominators. Each selected
client must independently install the actual tarball project-locally, globally,
Expand Down
Loading