Skip to content

fix(report): parse line ranges and multi-site locations in SAST and secret scanning - #129

Closed
Mr45401 wants to merge 1 commit into
secfoo-com:mainfrom
Mr45401:fix/sast-parse-multi-range-locations
Closed

Mr45401 wants to merge 1 commit into
secfoo-com:mainfrom
Mr45401:fix/sast-parse-multi-range-locations

Conversation

@Mr45401

@Mr45401 Mr45401 commented Nov 15, 2026

Copy link
Copy Markdown

Closes #112

What does this change, and why?

parse_location() in secfoo.report.sast previously matched only a single file:line span and fell back to returning the entire raw cell as location_file with location_line=None whenever a cell contained a line range (config/env/all.js:8-9), bare line continuations (app/data/user-dao.js:25, :61), backticks, or comma/semicolon-separated multi-file spans. That produced percent-encoded non-file SARIF artifactLocation.uri values, split cross-run fingerprints between :8-9 and :8, and skipped hash_code_region() and stack language inference (affecting 15 of 18 findings in examples/sample-output/nodegoat/).

This PR:

  • Adds parse_locations() (plus locations_to_dicts(), locations_from_raw(), and format_location_site()) in src/secfoo/report/sast.py to parse path:line, path:start-end (including en/em-dash ranges), path:line,line, bare :line continuations inheriting the previous file path, backticked variants, and comma/semicolon-separated lists into (path, start_line, end_line) tuples, while preserving parse_location() returning (first_path, str(first_start) | None) for primary-path fingerprinting and hash_code_region().
  • Applies the same parser in src/secfoo/report/secret_scanning.py.
  • Persists the full site list in a new locations JSON column on sast_findings and secret_findings (included in JSONL exports and stripped by --no-locations), and migrates pre-existing SQLite stores in RunRepository._migrate() by backfilling locations and normalizing location_file/location_line on older rows.
  • Updates src/secfoo/report/sarif.py to emit one locations[] entry per site with region.startLine and region.endLine (when end_line > start_line), falling back cleanly to location_file/location_line when locations is absent.
  • Renders every parsed site across the SAST and Secret Scanning finding detail pages (and secfoo findings show), updates fuzz/fuzz_parsers.py, and refreshes examples/sample-output/nodegoat/findings.jsonl and findings.sarif.

Testing

  • pytest tests passes
  • ruff check . passes
  • Added/updated tests for the behavior change (unit tests for all #112 strings and edge cases, Hypothesis property tests in tests/test_property_parsers.py, NodeGoat SARIF URI/schema validation, SQLite store migration tests, and SAST/Secret Scanning dashboard route tests)

…ecret scanning

`parse_location()` previously matched only a single `file:line` span and
returned line ranges (`config/env/all.js:8-9`), bare line continuations
(`app/data/user-dao.js:25, :61`), and multi-file cells whole as
`location_file` with `location_line=None`. That produced percent-encoded
non-file SARIF URIs, split cross-run fingerprints between `:8-9` and `:8`,
and skipped `hash_code_region()` and stack language detection.

- Add `parse_locations()` (plus `locations_to_dicts`, `locations_from_raw`,
  and `format_location_site`) in `report/sast.py` to parse `path:line`,
  `path:start-end`, `path:line,line`, bare `:line` continuations inheriting
  the previous path, backticked spans, and comma/semicolon lists into
  `(path, start_line, end_line)` tuples; keep `parse_location()` returning
  the primary site's `(path, str(start_line))` for fingerprinting and
  code-region hashing, and reuse the same parser in `report/secret_scanning.py`.
- Persist the full site list in a `locations` JSON column on `sast_findings`
  and `secret_findings` (included in JSONL exports and stripped under
  `--no-locations`), and migrate pre-existing stores by backfilling
  `locations` and normalizing `location_file`/`location_line` on old rows.
- Emit one SARIF `locations[]` entry per site with `region.startLine` and
  `region.endLine` when a range is present, render every site on SAST and
  secret-scanning finding detail pages, and refresh the NodeGoat sample
  `findings.jsonl` and `findings.sarif` outputs.

Closes secfoo-com#112

Signed-off-by: Mr45401 <185895283+Mr45401@users.noreply.github.com>
@Mr45401
Mr45401 requested a review from vsn411 as a code owner November 15, 2026 18:47
@vsn411

vsn411 commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Closing this without merging.

The parser, the SARIF output, and the detail pages are right, and new scans will keep a stable identity. The migration does not. It rewrites location_file to the clean path and leaves fingerprint hashed from the old whole-cell path. The next scan misses rekey_open_sast_fingerprint(), inserts a new row, and closes the old one. Any review status on that row stays behind.

This is ready to accept once the migration sets fingerprint to the new primary-path hash, with a rule for two old rows that collapse onto the same CWE and path. Secret findings need the same update.

#112 stays open.

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.

Bug: line ranges and multi-file locations become bogus file paths (breaks fingerprints and SARIF locations)

2 participants