Skip to content

fix(report): parse ranged and multi-site locations into real paths (#112) - #183

Merged
vsn411 merged 3 commits into
secfoo-com:mainfrom
aaas72:fix/112-multi-locations
Nov 21, 2026
Merged

vsn411 merged 3 commits into
secfoo-com:mainfrom
aaas72:fix/112-multi-locations

Conversation

@aaas72

@aaas72 aaas72 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Closes #112

What was wrong

parse_location() only understood file:line. A ranged or multi-site Location cell was stored whole as the file name, with no line. 5 of the 12 SAST findings in the NodeGoat sample hit this, and so did 3 of its 6 secret findings.

What changed

  • Parser (report/sast.py): parse_locations() returns every (path, start_line, end_line). It handles path:line, path:start-end (hyphen or en/em dash), path:line:col, backticked sites and comma/semicolon lists. A bare :61 or 61 reuses the previous path, and pieces with no letter or digit (a trailing …) are dropped. A reversed or one-line range keeps only its start line. parse_location() keeps its signature and returns the first site.
  • Storage: a new locations JSON column on sast_findings and secret_findings. location_file/location_line and the fingerprint use the first site, so all.js:8-9 and all.js:8 are the same finding. Opening an existing store re-derives locations for older rows and sets location_file/location_line to their first site, so the dashboard and the incremental-scan file scope see a real path. Only NULL rows are touched, so a second open does nothing.
  • Rekey on upgrade: rows stored before this change have a fingerprint built from the whole cell. pre_112_fingerprint() recomputes that key, and runner.py rekeys the open row the next time the finding is reported (same mechanism as the legacy region-hash rekey, now also for secret_findings). Without this, every multi-site finding would show as closed + new after the upgrade.
  • SARIF: one locations[] entry per site, with region.endLine for a real range. Records without locations fall back to location_file/location_line as before.
  • JSONL: locations is exported as a list, not a JSON string. --no-locations drops it.
  • Secret scanning uses the same parser. Its dashboard already shows the raw cell, so nothing changed there.
  • Dashboard: the SAST finding detail page lists every site (server.js:135-137 · app/views/layout.html:75).
  • Docs: docs/REFERENCE.md describes the locations field and the SARIF behaviour.

Done-when checklist

  • The four strings from the issue parse as expected (test_issue_examples_parse_into_every_site).
  • Hypothesis property test: parse_locations never returns a path containing ,, ;, a backtick or a trailing :range. A second property round-trips generated lists.
  • The SARIF built from the NodeGoat sample reports validates against the 2.1.0 schema, and every result has a real per-file uri (no encoded , : ; space or backtick). F12, the example in the issue, now gives three locations: server.js 78-102, app/routes/session.js 116 and app/routes/error.js 10-12.
  • A migration test opens a store without the column and checks that locations is re-derived for old SAST and secret rows.
  • Lifecycle tests: a SAST row and the sample's secret rows stored under the pre-Bug: line ranges and multi-file locations become bogus file paths (breaks fingerprints and SARIF locations) #112 key stay the same open rows (same id, same first_seen_at) after the next run.

One existing test (test_parse_location_strips_backticks_from_a_multi_location_cell) asserted the old behaviour, so I updated it to the first-site result.

I left examples/sample-output/nodegoat/findings.sarif and findings.jsonl untouched because the README presents them as an unedited run. I can regenerate them in this PR or a follow-up if you prefer.

Testing

pytest: 1957 passed. The 4 failures are the Mermaid architecture-page tests, which also fail on main without secfoo vendor mermaid. ruff check adds no new findings on the changed files.

parse_location() only understood `file:line`, so a ranged or multi-site
Location cell ("server.js:78-102, app/routes/session.js:116") became the
file name with no line. SARIF got a URI GitHub cannot attach to a file,
the fingerprint changed between `all.js:8-9` and `all.js:8`, and no code
region hash was computed for those rows.

- parse_locations() returns every (path, start_line, end_line) for
  `path:line`, `path:start-end`, `path:line:col`, backticked sites and
  comma/semicolon lists; a bare `:61` reuses the previous path.
  parse_location() returns the first site.
- New `locations` JSON column on sast_findings and secret_findings;
  location_file/location_line and the fingerprint use the first site.
  Opening an existing store re-derives `locations` (and fixes
  location_file/location_line) for older rows.
- Open rows keyed on the whole cell are rekeyed on the next run, so the
  upgrade does not show those findings as closed + new.
- SARIF: one locations[] entry per site, with region.endLine for ranges.
  JSONL export carries `locations` as a list; --no-locations drops it.
- The SAST finding detail page lists every site.

Closes secfoo-com#112
@aaas72
aaas72 requested a review from vsn411 as a code owner November 21, 2026 00:40
pre_112_fingerprint() skipped any cell the pre-secfoo-com#112 regex matched, but
that regex also matched "app/db.py, app/cli.py" (and "; " lists, and
"a.py, b.py:12"), storing the whole list as one path. The new parser
keys those on app/db.py, so after an upgrade the open finding showed as
closed + new. Compare the old stored path with today's first path
instead (pre_112_path), for SAST and secret scanning alike.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vsn411

vsn411 commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

This is a really thorough piece of work. The upgrade rekey, the backfill that only touches NULL rows, the SARIF endLine handling and the NodeGoat-based tests are all spot on. Thank you.

I pushed one follow-up commit (4d254ef) to your branch for a case in the rekey. pre_112_fingerprint() skipped any cell the pre-#112 regex matched, but that regex also matched unbackticked lists such as app/db.py, app/cli.py, app/db.py; app/cli.py and app/db.py, app/cli.py:12, storing the whole list as one path. The new parser keys those on app/db.py, so after an upgrade the open finding would have shown as closed and new. The commit adds pre_112_path(), which compares the path the old parser stored with today's first path, and both skills use it. It also adds a parametrized test for those three shapes.

On the sample files: leaving examples/sample-output/nodegoat/ untouched was the right call. A follow-up PR that regenerates them would be welcome.

@vsn411
vsn411 merged commit 7ffc138 into secfoo-com:main Nov 21, 2026
13 checks passed
@github-actions

Copy link
Copy Markdown

Leaderboard update

aaas72 now has 12 points (rank #4). 13 more to reach Bronze.

Full leaderboard

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