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
10 changes: 7 additions & 3 deletions release/scripts/check-advisory-baselines.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,16 @@ def syft_artifacts(report: Any) -> dict[str, dict[str, Any]]:
return indexed


def validate_image_path(value: Any, field: str) -> str:
def validate_image_path(value: Any, field: str, *, allow_root: bool = False) -> str:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the required DCO sign-off

The reviewed commit contains no Signed-off-by trailer, so it violates the repository's requirement that every commit use git commit -s and will be rejected by DCO enforcement. Recreate or squash this commit with a valid sign-off before merging.

AGENTS.md reference: AGENTS.md:L272-L275

Useful? React with 👍 / 👎.

if (
not isinstance(value, str)
or not value.startswith("/")
or value == "/"
or (value == "/" and not allow_root)
or "\x00" in value
or any(part in {"", ".", ".."} for part in value.split("/")[1:])
or (
value != "/"
and any(part in {"", ".", ".."} for part in value.split("/")[1:])
)
):
fail(f"{field} must be a normalized absolute image path")
return value
Expand All @@ -501,6 +504,7 @@ def syft_files(report: Any) -> tuple[frozenset[str], tuple[tuple[str, str], ...]
path = validate_image_path(
location.get("path") if isinstance(location, dict) else None,
"syft file location path",
allow_root=True,
)
if path in paths:
fail(f"syft report contains duplicate file path: {path}")
Expand Down
36 changes: 36 additions & 0 deletions release/scripts/test_check_advisory_baselines.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,42 @@ def finding(self, **kwargs):
grype, syft = self.reports(**kwargs)
return self.module.normalize_grype(grype, self.SUBJECT, syft).findings[0]

def test_syft_root_directory_is_valid_file_evidence(self):
grype, syft = self.reports()
syft["files"].append(
{
"id": "file-root",
"location": {"path": "/", "layerID": self.BASE_LAYER_1},
"metadata": {"type": "Directory"},
}
)

normalized = self.module.normalize_grype(grype, self.SUBJECT, syft)

self.assertIn("/", normalized.findings[0].syft_file_paths)

def test_reviewed_assertion_path_cannot_target_root(self):
with self.assertRaises(SystemExit):
self.module.validate_image_path("/", "reviewed assertion path")

def test_syft_file_paths_reject_unsafe_or_unnormalized_values(self):
for path in (
"app/service",
"/app//service",
"/app/service/",
"/app/./service",
"/app/../service",
"/app/\x00service",
):
with self.subTest(path=repr(path)):
with self.assertRaises(SystemExit):
self.module.syft_files({"files": [{"location": {"path": path}}]})

def test_syft_file_paths_reject_duplicates_including_root(self):
root_entry = {"location": {"path": "/"}}
with self.assertRaises(SystemExit):
self.module.syft_files({"files": [root_entry, copy.deepcopy(root_entry)]})

def with_digest(self, definition):
definition["definition_digest"] = self.module.definition_digest(definition)
return definition
Expand Down