feat: audit hardening — unpack scanning, SARIF/JSON/Markdown output#330
Open
danielmeppiel wants to merge 7 commits intomainfrom
Open
feat: audit hardening — unpack scanning, SARIF/JSON/Markdown output#330danielmeppiel wants to merge 7 commits intomainfrom
danielmeppiel wants to merge 7 commits intomainfrom
Conversation
Replace all apm audit --ci commands in docs with apm audit (which works today via exit codes 0/1/2). All remaining --ci references are now explicitly marked as planned/not yet available. Files updated: - integrations/ci-cd.md - integrations/github-rulesets.md - enterprise/governance.md - enterprise/making-the-case.md - enterprise/adoption-playbook.md - reference/lockfile-spec.md Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Scan bundle files for hidden Unicode characters after extraction but before deployment, matching the install command's pattern. - Add security_warnings/security_critical fields to UnpackResult - Add force parameter to unpack_bundle() for audit override - Add --force flag to unpack_cmd CLI command - Display security warnings/critical counts in CLI output - Block deployment on critical findings unless --force is used - Skip symlinks and handle binary files gracefully Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add machine-readable output formats to the standalone apm audit command: - --format/-f: text (default), json (machine-readable), sarif (GitHub Code Scanning) - --output/-o: write to file with auto-detection from extension (.sarif, .json) - New security/audit_report.py module for SARIF 2.1.0 and JSON serialization - ScanFinding maps 1:1 to SARIF fields (relative paths only, no content snippets) - Incompatible with --strip/--dry-run (validated with error message) - 16 new tests covering JSON, SARIF, format detection, and file writing Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- security.md: add apm unpack to scanning coverage, document SARIF output - ci-cd.md: add SARIF golden path workflow for Code Scanning integration - gh-aw.md: add Content Scanning section explaining audit in gh-aw context - CHANGELOG.md: add unpack scanning, SARIF output, and --ci doc fix entries Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens APM’s security posture by extending hidden-Unicode content scanning to apm unpack (pre-deploy) and by adding machine-readable apm audit outputs (JSON + SARIF) for CI and GitHub Code Scanning, alongside documentation updates to reflect current vs planned audit capabilities.
Changes:
- Add hidden-Unicode scanning gate to
apm unpack, with--forceoverride and result counters. - Add
apm audit --format {text,json,sarif}and--outputfor CI-friendly JSON/SARIF reporting. - Align docs and changelog around
apm auditbehavior and the planned (not yet available)apm audit --ci.
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Bumps editable package version to 0.8.0. |
| src/apm_cli/bundle/unpacker.py | Adds post-extract, pre-deploy content scanning and exposes counts on UnpackResult. |
| src/apm_cli/commands/pack.py | Adds apm unpack --force plumbing and user-facing warnings on forced/warning deploys. |
| src/apm_cli/commands/audit.py | Adds --format/--output, auto-detection, and routes to text vs JSON/SARIF output paths. |
| src/apm_cli/security/audit_report.py | Implements JSON + SARIF (2.1.0) serialization utilities. |
| tests/unit/test_unpack_security.py | New unit tests for unpack scanning behavior (clean/warn/critical/force/binary/symlink). |
| tests/unit/test_audit_report.py | New unit tests covering JSON/SARIF serialization, format detection, and writing. |
| docs/src/content/docs/reference/lockfile-spec.md | Updates CI guidance to reflect apm audit --ci as planned. |
| docs/src/content/docs/reference/cli-commands.md | Documents apm audit -f/--format and -o/--output. |
| docs/src/content/docs/integrations/github-rulesets.md | Reframes CI gating around current apm audit exit codes; marks --ci as planned. |
| docs/src/content/docs/integrations/gh-aw.md | Adds content scanning section and SARIF workflow example. |
| docs/src/content/docs/integrations/ci-cd.md | Adds SARIF “golden path” workflow and planned-note re: --ci. |
| docs/src/content/docs/enterprise/security.md | Documents unpack scanning + SARIF/JSON output usage. |
| docs/src/content/docs/enterprise/making-the-case.md | Updates messaging from planned --ci to current apm audit gating. |
| docs/src/content/docs/enterprise/governance.md | Updates CI enforcement section and adds SARIF upload example. |
| docs/src/content/docs/enterprise/adoption-playbook.md | Updates CI step to audit content issues with apm audit. |
| CHANGELOG.md | Adds Unreleased entries for unpack scanning + audit reporting + doc drift fix. |
Comment on lines
+145
to
+155
| for rel_path in unique_files: | ||
| source_file = source_dir / rel_path | ||
| if source_file.is_file() and not source_file.is_symlink(): | ||
| findings = scanner.scan_file(source_file) | ||
| if findings: | ||
| all_findings[rel_path] = findings | ||
|
|
||
| if all_findings: | ||
| flat = [f for ff in all_findings.values() for f in ff] | ||
| has_critical, counts = scanner.classify(flat) | ||
| security_critical = counts.get("critical", 0) |
Comment on lines
+167
to
+171
| f"Affected files:\n" + "\n".join(affected) + "\n\n" | ||
| "Next steps:\n" | ||
| " - Run: apm audit --file <file> to see details\n" | ||
| " - Run: apm unpack --force to deploy anyway " | ||
| "(not recommended)\n\n" |
Comment on lines
+47
to
+57
| items = [] | ||
| for finding in all_findings: | ||
| items.append({ | ||
| "severity": finding.severity, | ||
| "file": finding.file, | ||
| "line": finding.line, | ||
| "column": finding.column, | ||
| "codepoint": finding.codepoint, | ||
| "category": finding.category, | ||
| "description": finding.description, | ||
| }) |
- Fix type annotation for deployed_files helper (dict[str, Union[str, bytes]]) - Use relative link in gh-aw docs for content scanning reference - Add try/except guard for symlink creation in tests (platform compat) - Add PR numbers and markdown format to CHANGELOG entries - Fix error message to not reference temp path in unpacker Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add findings_to_markdown() for GFM output () - Wire markdown into audit.py --format choices + auto-detect .md - Fix symlink bypass in unpack: skip symlinks during deploy - Fix absolute paths in SARIF/JSON: normalize to relative - Fix format validation order: resolve effective_format before check - Fix detect_format_from_extension default: text instead of sarif Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…docs (#330) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #329
Strengthens
apm auditwith content scanning duringapm unpack, machine-readable SARIF/JSON/Markdown output, and documentation alignment.Changes
Content scanning for
apm unpackBundles are now scanned for hidden Unicode characters after extraction, before deployment — matching the
apm installpattern. Critical findings block deployment unless--forceis used.security_warnings/security_criticalfields onUnpackResult--forceflag onunpackcommand (audit override)apm audit --format sarif/json/markdown --outputMachine-readable output for CI artifact capture, GitHub Code Scanning, and step summaries:
--format/-f:text(default),json,sarif,markdown--output/-o: write to file, auto-detects format from extension (.sarif, .json, .md)src/apm_cli/security/audit_report.py— SARIF 2.1.0 + JSON + Markdown serialization--strip/--dry-run(validated with error, including auto-detected formats)PR review fixes
detect_format_from_extension()to default totextfor unknown extensionsDocumentation
apm audit --cidrift — 18+ references across 6 doc files now correctly mark--cias plannedapm-action (PR #14)
runAuditReport()now also writes markdown step summary wrapped in<details>to$GITHUB_STEP_SUMMARYCI golden path