Skip to content

Conversation

Akindotcome
Copy link

This PR improves the SARIF formatter with the following changes:

  • Added partialFingerprints (primaryLocationLineHash) for stable deduplication across runs/refactors.
  • Included CWE tags and Bandit test IDs in tags for better rule categorization.
  • Set precision based on Bandit’s confidence levels (HIGH/MEDIUM/LOW → high/medium/low).
  • Ensured absolute Windows paths are preserved in artifactLocation.uri to match test expectations.
  • Added raw original_path property for clarity and debugging.

~ All unit tests in tests/unit/formatters/ pass.
~ Functional tests are unchanged by this PR.

This should make Bandit’s SARIF output more compliant and interoperable with tools that consume SARIF logs.

Closes #646
Related to #737

@Akindotcome
Copy link
Author

Hi, I am still hoping my PR gets reviewed

@Akindotcome
Copy link
Author

@sigmavirus24 , @ericwb , @lukehinds
Hi - friendly ping on this SARIF improvement PR.

It adds partialFingerprints, tags/precision, preserves Windows absolute paths, and unit tests/unit/formatters/ pass.

Could one of you kindly review when you have a moment?

Thanks

@Akindotcome Akindotcome force-pushed the feature/sarif-cwe-fingerprints branch from 15e97ad to 87da4ed Compare September 29, 2025 20:44
Copy link
Member

@sigmavirus24 sigmavirus24 left a comment

Choose a reason for hiding this comment

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

There's a lot of particularly bad LLM slop here. I was promised they were good at writing python because of how much python was out there. I feel lied to.

@Akindotcome
Copy link
Author

@sigmavirus24, @ericwb
Thank you for the thorough reviews and feedback. I appreciate the time and detail from everyone.

I’ll address the points you raised (docstring/reST fixes, variable naming consistency, removing the empty except, simplifying confidence/CWE handling, and trimming unnecessary comments) and push the updates immediately I have done the corrections. I’ll be available to iterate further if anything else comes up.

@gpotter2
Sorry for the misunderstanding here, I am only trying to contribute to meaningful open source projects and grow knowledge-wise as well. Thank you

Akindotcome and others added 2 commits October 5, 2025 17:46
…empty except; simplify CWE/precision mapping; trim comments; keep SARIF output unchanged
@Akindotcome
Copy link
Author

Updates:

  • Docstring: Converted to valid reStructuredText with pycon usage and truncated json example. Removed ineffective noqa.
  • Naming: Renamed iss -> issue in add_results() to minimize diffs.
  • Exceptions: Removed empty except; only add issue.fname when present.
  • Simplifications: _precision_from_confidence() uses a direct mapping; CWE extraction via issue_dict.get("issue_cwe", {}).get("id").
  • Comments/docstrings: Trimmed redundant comments; tightened helper docstrings.
  • Behavior: SARIF structure unchanged (rules/properties/partialFingerprints). to_uri() preserves absolute Windows paths.

Validation:

  • tests/unit/formatters/test_sarif.py passes locally. Other Windows-local failures are unrelated to this formatter PR and out of scope; CI on Linux/macOS should be unaffected.

Copy link
Member

@sigmavirus24 sigmavirus24 left a comment

Choose a reason for hiding this comment

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

There is still a lot wrong here.

Co-authored-by: Ian Stapleton Cordasco <[email protected]>
Copy link
Member

@sigmavirus24 sigmavirus24 left a comment

Choose a reason for hiding this comment

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

Import modules not classes or functions

import typing as t

@Akindotcome
Copy link
Author

@sigmavirus24
Hi, I am still hoping my PR gets reviewed

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.

Support for the SARIF (Static Analysis Results Interchange Format)

4 participants