Skip to content

fix(code-risk): treat Semgrep partial parse errors as warnings - #496

Closed
lucas-saldanha-werneck wants to merge 1 commit into
NVIDIA:mainfrom
lucas-saldanha-werneck:fix/semgrep-partial-parsing-463
Closed

lucas-saldanha-werneck wants to merge 1 commit into
NVIDIA:mainfrom
lucas-saldanha-werneck:fix/semgrep-partial-parsing-463

Conversation

@lucas-saldanha-werneck

Copy link
Copy Markdown
Contributor

Summary

Refs #463. Any nonempty Semgrep errors list made Code Risk Analysis mark Semgrep incomplete, and only the first three errors were shown, each cut at 100 characters.

Semgrep reports a file it could only parse in part as a PartialParsing error: level is warn, type is a list such as ["PartialParsing", [spans]], and the rest of the file is still scanned. A second public repro besides those in the issue: valid bash such as exec 3<>"/dev/tcp/127.0.0.1/$PORT" (accepted by bash -n and ShellCheck) triggers one with Semgrep 1.182.0; I reported the parser bug upstream at semgrep/semgrep#12084.

This change:

  • treats a PartialParsing error (string or list type) as a warning that names the file, relative to the skill, and the line and column; the scan stays complete and the success message says how many files were only partly parsed;
  • keeps the scan incomplete for every other error type, including errors without a type;
  • reports every error, not only three, and no longer truncates the message.

Whether an unparsed part of a file is acceptable is a judgment call, as the issue notes, so the warning says that Semgrep did not check that code. I used "Refs" because the issue's third point (documenting how to resolve parse errors) is only partly covered by a short note in docs/tier1-validation.mdx.

Verification

  • I am familiar with the Contributing Guidelines
  • Added or updated focused tests (tests/validators/test_security_validators.py; the shapes come from real Semgrep 1.182.0 output)
  • Updated documentation for user-visible changes
  • Ran make lint
  • Ran make test (30418 passed, 37 skipped, 4 failed: the 2 test_harbor_secure_docker_environment.py::test_sidecar_retains_* tests also fail on unmodified main, and the 2 tests/ci/test_run_tier1.py Ctrl-C tests pass when rerun alone)
  • Ran make build
  • Did not add credentials, private datasets, or proprietary benchmark content

Release Impact

  • No user-visible release note needed
  • Updated CHANGELOG.md

🤖 Generated with Claude Code

Any nonempty Semgrep "errors" list marked the scan incomplete, even when
Semgrep recovered from a parse error and scanned the rest of the file. Valid
bash such as exec 3<>"/dev/tcp/127.0.0.1/$PORT" makes Semgrep's bash parser
report a PartialParsing error, so such skills got an incomplete Code Risk
check.

A PartialParsing error (the type is a string or a list like
["PartialParsing", [spans]]) is now a warning naming the file and the
line/column, and no longer makes the scan incomplete. Every other error type
still does. All errors are reported, not only the first three truncated to 100
characters.

Refs NVIDIA#463

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01U8VQWLhJZuJqs6TK49GfjT
Signed-off-by: Lucas Saldanha Werneck <[email protected]>
@lucas-saldanha-werneck

Copy link
Copy Markdown
Contributor Author

Closing this in favor of #475, which addresses #463 first and keeps the stricter 'incomplete' outcome. Thanks for the clear fix there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant