Add Trivy security-audit workflow and report sorter; validate cgroup paths against embedded NUL#26
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a Python script to generate severity-sorted Markdown reports from Trivy JSON output and includes a new document tracking potential security vulnerabilities. Additionally, it hardens cgroup path validation in src/nxt_conf_validation.c by rejecting embedded NUL bytes and using snprintf, with a corresponding test case added. Review feedback suggests enhancing the Markdown escaping logic to handle backslashes and removing redundant severity normalization in the sorting process.
|
|
||
| def markdown_escape(value: Any) -> str: | ||
| text = "" if value is None else str(value) | ||
| return text.replace("|", "\\|").replace("\n", " ").replace("\r", " ") |
There was a problem hiding this comment.
The current escaping logic does not handle backslashes. In Markdown tables, a backslash preceding a pipe (\|) acts as an escape character for the pipe. If a field (such as a package title or version) ends with a backslash, it could inadvertently escape the table delimiter and break the report formatting. It is safer to escape backslashes first.
| return text.replace("|", "\\|").replace("\n", " ").replace("\r", " ") | |
| return text.replace("\\", "\\\\").replace("|", "\\|").replace("\n", " ").replace("\r", " ") |
|
|
||
|
|
||
| def vulnerability_sort_key(vulnerability: dict[str, Any]) -> tuple[Any, ...]: | ||
| severity = normalized_severity(vulnerability.get("Severity")) |
There was a problem hiding this comment.
The Severity field is already normalized in the collect_vulnerabilities function (line 101). Re-calling normalized_severity here is redundant and adds unnecessary overhead during the sorting process, especially for large reports.
| severity = normalized_severity(vulnerability.get("Severity")) | |
| severity = vulnerability.get("Severity", "UNKNOWN") |
Motivation
Description
.github/scripts/sort-trivy-results.pywhich parses Trivy JSON output, sorts vulnerabilities by severity and CVSS v3 score, renders a Markdown report, and can exit non-zero when a configured severity threshold is met..github/workflows/security-audit.ymlGitHub Action to run Trivy (JSON and SARIF), upload SARIF, generate the sorted Markdown report, append it to the step summary, and upload thesecurity-audit/artifact.docs/security-audit-findings.mddocumenting candidate findings from a manual review of the new audit/workflow and adjacent code paths.src/nxt_conf_validation.cfor cgroup paths by rejecting empty strings and embedded NUL bytes, replacing asprintfwithsnprintfto avoid unsafe formatting, and preserving the existing ".." path check.test/test_python_isolation.pyto include a test case that asserts a cgroup path containing an embedded NUL ('scope\0python') is treated as invalid.Testing
test/test_python_isolation.py::test_python_isolation_cgroup_invalidwas run and the new case for embedded NULs passed.Codex Task