Repository navigation
fix: encode SARIF artifact URIs per RFC 3986 and route batch progress to stderr - #789
dajiaohuang wants to merge 5 commits into
Conversation
… to stderr - Fix NVIDIA#757: Encode file paths in SARIF artifactLocation.uri using urllib.parse.quote to handle special characters (spaces, unicode, etc.) per RFC 3986 - Fix NVIDIA#753: Route all batch scanner progress, header, and status messages to stderr so JSON/markdown output on stdout remains machine-parseable Signed-off-by: dajiaohuang <dajiaohuang@bytedance.com>
yashrajp22
left a comment
There was a problem hiding this comment.
Two paths in these fixes still need attention: batch diagnostics with Rich installed, and SARIF notification locations. Regular/suppressed finding URI encoding and the plain stderr path work.
Verified this commit with fresh BASE/HEAD wheels, source/install identity checks, 48 sample scans, 12 focused SARIF scans, stream/exit probes, and selected existing SARIF/batch tests. Existing tests: BASE 178 passed per mode; HEAD 177 passed and 1 failed per mode. The failure expects the old plain-output error stream and needs its assertion updated.
One BASE/source Markdown batch invocation recorded a worker timeout; I have not attributed it to this PR or claimed complete batch parity. These offline checks do not establish live-provider behavior or global detection accuracy.
| f"{len(skill_dirs)} skill(s) in [dim]{display(root)}[/dim]" | ||
| f" ([cyan]{args.workers} workers[/cyan]{pool_note})\n" | ||
| f" ([cyan]{args.workers} workers[/cyan]{pool_note})\n", | ||
| file=sys.stderr, |
There was a problem hiding this comment.
Could you make _print honor file=sys.stderr when Rich is available? Its Rich branch drops the file argument and uses the stdout-backed Console. With the normal Rich dependency installed, I reproduced --format json emitting the banner/progress before the JSON with empty stderr, so json.loads(stdout) still fails; Markdown has the same prefix. Please route diagnostics through a stderr-backed console and cover both Rich/plain branches. The existing plain-error test also needs to read stderr.
There was a problem hiding this comment.
Both findings were addressed. _print now derives progress_file from the format and passes any explicit file through to a stderr-backed Console, so the Rich and plain branches agree; the tests assert the banner and WARNING lines on stderr and parse stdout as JSON or Markdown for all three formats.
The notification path also uses the shared encoder now: notification_from_exception calls _sarif_uri(path), the same helper the artifact locations use. A malformed broken#old.zip reports as broken%23old.zip.
I also rebased onto current main, which independently landed the same RFC 3986 encoding, and kept one encoder in _sarif_uri instead of two. While resolving that I fixed a further regression: raw_file_path was stripped of every leading slash before the unscoped branch ran, so an absolute artifact (/tmp/a b.py) was emitted as relative and disagreed with the notification helper. The leading slash is now stripped only when joining beneath a source identity; unscoped paths keep their own form. Regression tests cover the unscoped absolute path, agreement between finding and notification URIs, and the scoped relative form.
Local: pytest tests/nodes/test_sarif_rules_and_empty_findings.py tests/nodes/test_report.py tests/unit/test_sarif.py 267 passed, 1 skipped. ruff check src/ tests/ and ruff format --check src/ tests/ clean.
| occurrence = occurrence or {} | ||
| file_path = str(occurrence.get("file", finding.file)).replace("\\", "/").lstrip("/") | ||
| raw_file_path = str(occurrence.get("file", finding.file)).replace("\\", "/").lstrip("/") | ||
| file_path = quote(raw_file_path, safe="/") |
There was a problem hiding this comment.
Could you apply this encoding to invocation notification locations too? _build_sarif.notification_from_exception still constructs SarifArtifactLocation(uri=path) directly. Scanning a malformed file named broken#old.zip produces error/warning notifications whose URI is still broken#old.zip, so SARIF consumers treat old.zip as a fragment instead of part of the filename. I reproduced this from source and the installed wheel; regular finding URIs are correctly encoded. Please use the same path-normalization/encoding policy for notification locations.
There was a problem hiding this comment.
notification_from_exception now calls the same _sarif_uri helper the artifact locations use, so notification paths get the same policy. broken#old.zip reports as broken%23old.zip.
The helper keeps / and ! literal: ! is an RFC 3986 sub-delim, and this codebase uses !/ as its archive-member separator (outer.zip!/nested.zip), so encoding it to %21 would break the paths the ledger and docs rely on. #, ?, spaces and non-ASCII are all percent-encoded.
Covered by test_report_sarif_encodes_exception_notification_paths and test_sarif_notification_uri_preserves_literal_filename, which exercise both ledger_exceptions and scope_exclusions.
Local: 267 passed, 1 skipped across the SARIF and report test files; ruff check and ruff format --check clean.
Signed-off-by: dajiaohuang <mikewushuwen@outlook.com>
|
Addressed both requested paths. |
Signed-off-by: dajiaohuang <mikewushuwen@outlook.com>
|
Updated the nested archive inspection-limit regression to assert the percent-encoded URI in the SARIF notification location, while retaining the raw display-path assertion for terminal, JSON and Markdown. This addresses the sole unit-test failure in run 37672509169. Validation: 7 relevant report tests passed; Ruff check src/ tests/ passed; formatting check for the changed test passed. The full test suite and live-provider integration tests were not rerun locally. Current-head CI and re-review remain pending. |
rng1995
left a comment
There was a problem hiding this comment.
[SkillSpector Review]
Value and readiness
Both previous review findings are implemented: Rich now honors stderr for diagnostics, notification paths share percent-encoding, and regression coverage includes Rich/plain JSON/Markdown streams and notification locations. Reviewed head 725cc6a20cf743152368354eb8b42628751dc02b.
Material findings
One new location regression remains at src/skillspector/nodes/report.py:206-214. raw_file_path strips every leading slash before the no-source-identity branch calls _sarif_uri. A finding with file='/tmp/a b.py' and no provenance now emits 'tmp/a%20b.py', changing an absolute artifact path into a relative one; previously that branch retained the original path. The notification helper still preserves the slash, so the two locations also disagree. Strip the leading slash only when joining beneath a source identity, and pass the unstripped normalized path through _sarif_uri otherwise. Add an unscoped absolute-path regression.
PIC tradeoffs
Encoded file paths should preserve their reference semantics; source-scoped findings can continue using their existing relative namespace.
Verification and gaps
Read all four changed files, pinned SARIF/batch context, the previous review and both inline threads/replies. The prior Rich-stream and notification findings are resolved in code, though their conversations remain unresolved in the snapshot. All six hosted checks succeeded. The absolute-path consequence above follows directly from the lstrip call and URI branch; no PR code was executed.
Signed-off-by: dajiaohuang <mikewushuwen@outlook.com>
raw_file_path stripped every leading slash before the no-source-identity branch called _sarif_uri, so a finding for an absolute file was emitted as a relative URI (tmp/a%20b.py) while the notification helper preserved the slash. Strip the leading slash only when joining beneath a source identity and pass the unstripped path through _sarif_uri otherwise. Add regression tests for the unscoped absolute path, its agreement with notification locations, and the scoped relative form. Signed-off-by: dajiaohuang <mikewushuwen@outlook.com>
a2ccec0 to
8c1bbdb
Compare
|
Both previous findings implemented; the new location regression you raised is fixed at The regression: Regression tests added (
The earlier two findings also remain covered: Rich and plain branches both route diagnostics to stderr with
|
Summary
Two minimal fixes:
Fix SARIF artifact URIs do not encode literal filename characters #757: Encode file paths in SARIF
artifactLocation.uriusingurllib.parse.quoteto handle special characters (spaces, unicode, etc.) per RFC 3986. This ensures SARIF consumers correctly parse artifact URIs that contain reserved or non-ASCII characters.Fix Batch scanner mixes progress messages into JSON stdout #753: Route all batch scanner progress, header, and status messages to stderr so JSON/markdown output on stdout remains machine-parseable. Previously, progress lines like
[1/10] skill-name → 80/100 HIGH (2 issues)were printed to stdout, corrupting piped JSON output.Testing
src/skillspector/nodes/report.py: Addedurllib.parse.quoteimport + URI encoding in_sarif_artifact_locationcontrib/batch_scan/batch_scan.py: Addedfile=sys.stderrto all progress/status_printcallsSigned-off-by: dajiaohuang dajiaohuang@bytedance.com