Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions examples/sample-output/nodegoat/findings.jsonl

Large diffs are not rendered by default.

205 changes: 190 additions & 15 deletions examples/sample-output/nodegoat/findings.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,32 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "server.js%3A78-102%2C%20app/routes/session.js%3A116%2C%20app/routes/error.js%3A10-12"
"uri": "server.js"
},
"region": {
"endLine": 102,
"startLine": 78
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/routes/session.js"
},
"region": {
"startLine": 116
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/routes/error.js"
},
"region": {
"endLine": 12,
"startLine": 10
}
}
}
Expand All @@ -26,7 +51,11 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/routes/profile.js%3A59-61"
"uri": "app/routes/profile.js"
},
"region": {
"endLine": 61,
"startLine": 59
}
}
}
Expand All @@ -43,7 +72,21 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "server.js%3A104-113%2C%20app/views/profile.html%3A73"
"uri": "server.js"
},
"region": {
"endLine": 113,
"startLine": 104
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/views/profile.html"
},
"region": {
"startLine": 73
}
}
}
Expand All @@ -60,7 +103,22 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "config/env/all.js%3A8-9%2C%20artifacts/db-reset.js%3A15-18"
"uri": "config/env/all.js"
},
"region": {
"endLine": 9,
"startLine": 8
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "artifacts/db-reset.js"
},
"region": {
"endLine": 18,
"startLine": 15
}
}
}
Expand All @@ -77,7 +135,11 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/routes/index.js%3A70-73"
"uri": "app/routes/index.js"
},
"region": {
"endLine": 73,
"startLine": 70
}
}
}
Expand All @@ -94,7 +156,20 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/data/user-dao.js%3A25%2C%20%3A61"
"uri": "app/data/user-dao.js"
},
"region": {
"startLine": 25
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/data/user-dao.js"
},
"region": {
"startLine": 61
}
}
}
Expand All @@ -111,7 +186,21 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "server.js%3A135-137%2C%20app/views/layout.html%3A75"
"uri": "server.js"
},
"region": {
"endLine": 137,
"startLine": 135
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/views/layout.html"
},
"region": {
"startLine": 75
}
}
}
Expand All @@ -128,7 +217,11 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/routes/index.js%3A55-56"
"uri": "app/routes/index.js"
},
"region": {
"endLine": 56,
"startLine": 55
}
}
}
Expand All @@ -145,7 +238,11 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/routes/allocations.js%3A16-23"
"uri": "app/routes/allocations.js"
},
"region": {
"endLine": 23,
"startLine": 16
}
}
}
Expand All @@ -162,7 +259,11 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/data/allocations-dao.js%3A77-79"
"uri": "app/data/allocations-dao.js"
},
"region": {
"endLine": 79,
"startLine": 77
}
}
}
Expand All @@ -179,7 +280,11 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/routes/research.js%3A15-26"
"uri": "app/routes/research.js"
},
"region": {
"endLine": 26,
"startLine": 15
}
}
}
Expand All @@ -196,7 +301,11 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/routes/contributions.js%3A32-34"
"uri": "app/routes/contributions.js"
},
"region": {
"endLine": 34,
"startLine": 32
}
}
}
Expand All @@ -213,7 +322,20 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/views/tutorial/a2.html%3A153%2C%20app/views/tutorial/a3.html%3A176"
"uri": "app/views/tutorial/a2.html"
},
"region": {
"startLine": 153
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "app/views/tutorial/a3.html"
},
"region": {
"startLine": 176
}
}
}
Expand All @@ -230,7 +352,47 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "artifacts/db-reset.js%3A18%2C27%2C35%3B%20test/e2e/fixtures/users/%2A.json%3B%20test/security/profile-test.js%3A37"
"uri": "artifacts/db-reset.js"
},
"region": {
"startLine": 18
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "artifacts/db-reset.js"
},
"region": {
"startLine": 27
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "artifacts/db-reset.js"
},
"region": {
"startLine": 35
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "test/e2e/fixtures/users/%2A.json"
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "test/security/profile-test.js"
},
"region": {
"startLine": 37
}
}
}
Expand All @@ -247,7 +409,20 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "config/env/development.js%3A6%2C%20config/env/test.js%3A6"
"uri": "config/env/development.js"
},
"region": {
"startLine": 6
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "config/env/test.js"
},
"region": {
"startLine": 6
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions fuzz/fuzz_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@

from __future__ import annotations

import re
import sys

import atheris

with atheris.instrument_imports():
from secfoo.report.sast import parse_location, parse_locations
from secfoo.report.severity import count_severities, extract_overall_risk_rating
from secfoo.skills.loader import SkillLoadError, _parse_frontmatter
from secfoo.web.finding_filters import normalize_severity

_TRAILING_RANGE_RE = re.compile(r":\s*\d+(?:\s*-\s*\d*)?\s*$")


def test_one_input(data: bytes) -> None:
provider = atheris.FuzzedDataProvider(data)
Expand All @@ -50,6 +54,17 @@ def test_one_input(data: bytes) -> None:
normalised = normalize_severity(text[:64])
assert normalize_severity(normalised) == normalised

# Location parsing must never return delimiters, backticks, or trailing ranges.
loc_path, _loc_line = parse_location(text[:256])
assert all(ch not in loc_path for ch in (",", ";", "`"))
assert not _TRAILING_RANGE_RE.search(loc_path)
for site_path, start_line, end_line in parse_locations(text[:256]):
assert site_path
assert all(ch not in site_path for ch in (",", ";", "`"))
assert not _TRAILING_RANGE_RE.search(site_path)
if end_line is not None:
assert start_line is not None and end_line > start_line >= 1


def main() -> None:
atheris.Setup(sys.argv, test_one_input)
Expand Down
11 changes: 9 additions & 2 deletions src/secfoo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,9 @@ class FindingsFormat(str, Enum):

# Lifecycle bookkeeping that means nothing outside this one SQLite file.
_EXPORT_DROP_COLUMNS = {"id", "project_id", "first_seen_run_id", "last_seen_run_id", "closed_in_run_id"}
_EXPORT_LOCATION_COLUMNS = {"location_file", "location_line", "code_region_hash", "reachability_evidence"}
_EXPORT_LOCATION_COLUMNS = {
"location_file", "location_line", "locations", "code_region_hash", "reachability_evidence",
}


@findings_app.command(name="export")
Expand Down Expand Up @@ -1920,6 +1922,7 @@ def findings_show(
no_runtime: Annotated[bool, typer.Option("--no-runtime", help="Skip runtime evidence (no fetch).")] = False,
) -> None:
"""One finding in full, with its runtime evidence and a remediation hint."""
from secfoo.report.sast import format_location_site
from secfoo.runtime.developer import remediation_hint

with RunRepository() as repo:
Expand All @@ -1931,7 +1934,11 @@ def findings_show(
skill_id, row, runtime = matches[0]
console.print(f"[bold]{_finding_title(skill_id, row)}[/] ({skill_id}, {row.get('severity')}, {row.get('status')})")
console.print(f"Project: {row.get('display_name')} Fingerprint: {row['fingerprint']}")
for label, key in (("Location", "location_file"), ("Reachability", "reachability"), ("Fixed in", "fixed_in"),
rendered_sites = [format_location_site(site) for site in (row.get("locations") or [])]
location_display = ", ".join(s for s in rendered_sites if s) or row.get("location_file")
if location_display:
console.print(f"Location: {location_display}")
for label, key in (("Reachability", "reachability"), ("Fixed in", "fixed_in"),
("Recommendation", "recommendation")):
if row.get(key):
console.print(f"{label}: {row[key]}")
Expand Down
Loading
Loading