Repository navigation
fix(report): parse ranged and multi-site locations into real paths (#112) - #183
Conversation
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
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]>
|
This is a really thorough piece of work. The upgrade rekey, the backfill that only touches NULL rows, the SARIF I pushed one follow-up commit (4d254ef) to your branch for a case in the rekey. On the sample files: leaving |
Leaderboard update
aaas72 now has 12 points (rank #4). 13 more to reach Bronze. |
Closes #112
What was wrong
parse_location()only understoodfile: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
report/sast.py):parse_locations()returns every(path, start_line, end_line). It handlespath:line,path:start-end(hyphen or en/em dash),path:line:col, backticked sites and comma/semicolon lists. A bare:61or61reuses 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.locationsJSON column onsast_findingsandsecret_findings.location_file/location_lineand the fingerprint use the first site, soall.js:8-9andall.js:8are the same finding. Opening an existing store re-deriveslocationsfor older rows and setslocation_file/location_lineto their first site, so the dashboard and the incremental-scan file scope see a real path. OnlyNULLrows are touched, so a second open does nothing.pre_112_fingerprint()recomputes that key, andrunner.pyrekeys the open row the next time the finding is reported (same mechanism as the legacy region-hash rekey, now also forsecret_findings). Without this, every multi-site finding would show as closed + new after the upgrade.locations[]entry per site, withregion.endLinefor a real range. Records withoutlocationsfall back tolocation_file/location_lineas before.locationsis exported as a list, not a JSON string.--no-locationsdrops it.server.js:135-137 · app/views/layout.html:75).docs/REFERENCE.mddescribes thelocationsfield and the SARIF behaviour.Done-when checklist
test_issue_examples_parse_into_every_site).parse_locationsnever returns a path containing,,;, a backtick or a trailing:range. A second property round-trips generated lists.uri(no encoded,:;space or backtick). F12, the example in the issue, now gives three locations:server.js78-102,app/routes/session.js116 andapp/routes/error.js10-12.locationsis re-derived for old SAST and secret rows.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.sarifandfindings.jsonluntouched 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 onmainwithoutsecfoo vendor mermaid.ruff checkadds no new findings on the changed files.