Repository navigation
Conversation
…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>
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 This is ready to accept once the migration sets #112 stays open. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #112
What does this change, and why?
parse_location()insecfoo.report.sastpreviously matched only a singlefile:linespan and fell back to returning the entire raw cell aslocation_filewithlocation_line=Nonewhenever 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 SARIFartifactLocation.urivalues, split cross-run fingerprints between:8-9and:8, and skippedhash_code_region()and stack language inference (affecting 15 of 18 findings inexamples/sample-output/nodegoat/).This PR:
parse_locations()(pluslocations_to_dicts(),locations_from_raw(), andformat_location_site()) insrc/secfoo/report/sast.pyto parsepath:line,path:start-end(including en/em-dash ranges),path:line,line, bare:linecontinuations inheriting the previous file path, backticked variants, and comma/semicolon-separated lists into(path, start_line, end_line)tuples, while preservingparse_location()returning(first_path, str(first_start) | None)for primary-path fingerprinting andhash_code_region().src/secfoo/report/secret_scanning.py.locationsJSON column onsast_findingsandsecret_findings(included in JSONL exports and stripped by--no-locations), and migrates pre-existing SQLite stores inRunRepository._migrate()by backfillinglocationsand normalizinglocation_file/location_lineon older rows.src/secfoo/report/sarif.pyto emit onelocations[]entry per site withregion.startLineandregion.endLine(whenend_line > start_line), falling back cleanly tolocation_file/location_linewhenlocationsis absent.secfoo findings show), updatesfuzz/fuzz_parsers.py, and refreshesexamples/sample-output/nodegoat/findings.jsonlandfindings.sarif.Testing
pytest testspassesruff check .passes#112strings and edge cases, Hypothesis property tests intests/test_property_parsers.py, NodeGoat SARIF URI/schema validation, SQLite store migration tests, and SAST/Secret Scanning dashboard route tests)