coretrace-python-analyzer 0.20.0__py3-none-any.whl → 0.22.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- coretrace_python/__init__.py +1 -1
- coretrace_python/bundled/dependency/reachable_vulnerability/reachable_vulnerability.py +19 -13
- coretrace_python/bundled/dependency/vulnerable_dependency/vulnerable_dependency.py +33 -9
- coretrace_python/bundled/security/command_injection/command_injection.py +1028 -3
- coretrace_python/bundled/security/command_injection/plugin.toml +1 -1
- coretrace_python/cache.py +38 -4
- coretrace_python/cli.py +51 -9
- coretrace_python/dependency/advisories.py +36 -1
- coretrace_python/dependency/correlation.py +151 -13
- coretrace_python/dependency/graph.py +71 -34
- coretrace_python/dependency/vex.py +5 -2
- coretrace_python/engine.py +38 -7
- coretrace_python/findings/baseline.py +268 -34
- coretrace_python/findings/model.py +3 -2
- coretrace_python/findings/suppressions.py +11 -3
- coretrace_python/frontend/ast_adapter.py +27 -1
- coretrace_python/frontend/parser.py +3 -0
- coretrace_python/interprocedural/__init__.py +2 -0
- coretrace_python/interprocedural/callgraph.py +131 -5
- coretrace_python/ir/lowering.py +4 -1
- coretrace_python/ir/model.py +8 -0
- coretrace_python/plugins/__init__.py +2 -1
- coretrace_python/plugins/detectors.py +30 -4
- coretrace_python/plugins/secrets.py +231 -36
- coretrace_python/reporters/json_format.py +14 -7
- coretrace_python/reporters/report.py +7 -2
- coretrace_python/reporters/sarif.py +19 -12
- coretrace_python/reporters/text.py +5 -4
- coretrace_python/source/__init__.py +6 -2
- coretrace_python/source/manager.py +16 -0
- coretrace_python/source/model.py +20 -0
- coretrace_python/source/positions.py +420 -0
- coretrace_python/taint/commands.py +45 -0
- coretrace_python/taint/models.py +10 -7
- {coretrace_python_analyzer-0.20.0.dist-info → coretrace_python_analyzer-0.22.0.dist-info}/METADATA +10 -1
- {coretrace_python_analyzer-0.20.0.dist-info → coretrace_python_analyzer-0.22.0.dist-info}/RECORD +40 -38
- {coretrace_python_analyzer-0.20.0.dist-info → coretrace_python_analyzer-0.22.0.dist-info}/WHEEL +0 -0
- {coretrace_python_analyzer-0.20.0.dist-info → coretrace_python_analyzer-0.22.0.dist-info}/entry_points.txt +0 -0
- {coretrace_python_analyzer-0.20.0.dist-info → coretrace_python_analyzer-0.22.0.dist-info}/licenses/LICENSE +0 -0
- {coretrace_python_analyzer-0.20.0.dist-info → coretrace_python_analyzer-0.22.0.dist-info}/licenses/NOTICE +0 -0
coretrace_python/__init__.py
CHANGED
|
@@ -8,12 +8,14 @@ from collections.abc import Iterator, Sequence
|
|
|
8
8
|
from typing import ClassVar
|
|
9
9
|
|
|
10
10
|
from coretrace_python.analysis import AnyAnalysis
|
|
11
|
-
from coretrace_python.dependency import Advisory, DependencyAnalysis
|
|
11
|
+
from coretrace_python.dependency import Advisory, AdvisoryEntryPoint, DependencyAnalysis
|
|
12
12
|
from coretrace_python.dependency.correlation import (
|
|
13
13
|
ConditionCheck,
|
|
14
|
+
affected_entries,
|
|
14
15
|
affected_symbols,
|
|
15
16
|
check_conditions,
|
|
16
17
|
evidence,
|
|
18
|
+
suffix_index,
|
|
17
19
|
)
|
|
18
20
|
from coretrace_python.findings import Confidence, Finding
|
|
19
21
|
from coretrace_python.interprocedural import CallGraphAnalysis, ExternalSymbol
|
|
@@ -30,6 +32,7 @@ class ReachableVulnerabilityPlugin(ProjectPlugin):
|
|
|
30
32
|
affected = affected_symbols(ctx.dependencies, ctx.advisories)
|
|
31
33
|
if not affected:
|
|
32
34
|
return ()
|
|
35
|
+
suffixes = suffix_index(affected, ctx.modules)
|
|
33
36
|
findings: list[Finding] = []
|
|
34
37
|
for module in ctx.modules:
|
|
35
38
|
graph = ctx.call_graph(module)
|
|
@@ -37,30 +40,28 @@ class ReachableVulnerabilityPlugin(ProjectPlugin):
|
|
|
37
40
|
for site in graph.sites(function):
|
|
38
41
|
if not isinstance(site.target, ExternalSymbol):
|
|
39
42
|
continue
|
|
40
|
-
for advisory in
|
|
41
|
-
entry = advisory.entry_point(site.target.symbol)
|
|
43
|
+
for advisory, entry in affected_entries(site.target.symbol, affected, suffixes):
|
|
42
44
|
if entry is not None and entry.read:
|
|
43
45
|
continue # a call reads its callee first: reported with the reads
|
|
44
|
-
check = check_conditions(entry, site.arguments)
|
|
46
|
+
check = check_conditions(entry, site.arguments, prior_calls=site.prior_calls)
|
|
45
47
|
if check.contradicted is not None:
|
|
46
48
|
continue
|
|
47
|
-
findings.append(_reached(advisory, site.target.symbol, site.location, function, check))
|
|
49
|
+
findings.append(_reached(advisory, site.target.symbol, site.location, function, check, entry))
|
|
48
50
|
# Reading ``request.form.get`` reads ``request.form``: one finding per entry
|
|
49
51
|
# point and function, where the function first reads it.
|
|
50
52
|
reported: set[tuple[Advisory, SymbolId]] = set()
|
|
51
53
|
for read in graph.reads(function):
|
|
52
54
|
for symbol in _read_through(read.symbol):
|
|
53
|
-
for advisory in
|
|
54
|
-
entry = advisory.entry_point(symbol)
|
|
55
|
+
for advisory, entry in affected_entries(symbol, affected, suffixes):
|
|
55
56
|
if entry is None or not entry.read or (advisory, symbol) in reported:
|
|
56
57
|
continue
|
|
57
58
|
reported.add((advisory, symbol))
|
|
58
59
|
check = check_conditions(entry, None)
|
|
59
|
-
findings.append(_reached(advisory, symbol, read.location, function, check))
|
|
60
|
+
findings.append(_reached(advisory, symbol, read.location, function, check, entry))
|
|
60
61
|
for call in ctx.templates.calls:
|
|
61
|
-
for advisory in
|
|
62
|
-
check = check_conditions(
|
|
63
|
-
findings.append(_reached(advisory, call.symbol, call.span, None, check))
|
|
62
|
+
for advisory, entry in affected_entries(call.symbol, affected, suffixes):
|
|
63
|
+
check = check_conditions(entry, None)
|
|
64
|
+
findings.append(_reached(advisory, call.symbol, call.span, None, check, entry))
|
|
64
65
|
return findings
|
|
65
66
|
|
|
66
67
|
|
|
@@ -73,7 +74,12 @@ def _read_through(symbol: SymbolId) -> Iterator[SymbolId]:
|
|
|
73
74
|
|
|
74
75
|
|
|
75
76
|
def _reached(
|
|
76
|
-
advisory: Advisory,
|
|
77
|
+
advisory: Advisory,
|
|
78
|
+
symbol: SymbolId,
|
|
79
|
+
span: SourceSpan,
|
|
80
|
+
function: str | None,
|
|
81
|
+
check: ConditionCheck,
|
|
82
|
+
entry: AdvisoryEntryPoint | None,
|
|
77
83
|
) -> Finding:
|
|
78
84
|
return Finding(
|
|
79
85
|
rule_id="reachable-vulnerability",
|
|
@@ -85,5 +91,5 @@ def _reached(
|
|
|
85
91
|
confidence=Confidence.HIGH,
|
|
86
92
|
span=span,
|
|
87
93
|
function=function,
|
|
88
|
-
metadata=evidence(advisory, symbol, "reachable", check),
|
|
94
|
+
metadata=evidence(advisory, symbol, "reachable", check, entry),
|
|
89
95
|
)
|
|
@@ -3,11 +3,18 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from collections.abc import Sequence
|
|
6
|
+
from pathlib import PurePath
|
|
6
7
|
from typing import ClassVar
|
|
7
8
|
|
|
8
9
|
from coretrace_python.analysis import AnyAnalysis
|
|
9
|
-
from coretrace_python.dependency import DependencyAnalysis
|
|
10
|
-
from coretrace_python.dependency.correlation import
|
|
10
|
+
from coretrace_python.dependency import Advisory, DependencyAnalysis, Requirement
|
|
11
|
+
from coretrace_python.dependency.correlation import (
|
|
12
|
+
affected_entries,
|
|
13
|
+
affected_symbols,
|
|
14
|
+
check_conditions,
|
|
15
|
+
ruled_out,
|
|
16
|
+
suffix_index,
|
|
17
|
+
)
|
|
11
18
|
from coretrace_python.findings import Confidence, Finding
|
|
12
19
|
from coretrace_python.interprocedural import CallGraphAnalysis, ExternalSymbol
|
|
13
20
|
from coretrace_python.plugins import ProjectContext, ProjectPlugin
|
|
@@ -38,11 +45,7 @@ class VulnerableDependencyPlugin(ProjectPlugin):
|
|
|
38
45
|
findings.append(
|
|
39
46
|
Finding(
|
|
40
47
|
rule_id="vulnerable-dependency",
|
|
41
|
-
message=(
|
|
42
|
-
f"{advisory.id}: {advisory.package} {advisory.vulnerable} is "
|
|
43
|
-
f"{'required' if pinned else 'allowed'} by {requirement.name}"
|
|
44
|
-
f"{requirement.specifier or ''}: {advisory.summary}"
|
|
45
|
-
),
|
|
48
|
+
message=_message(ctx, advisory, requirement),
|
|
46
49
|
severity=advisory.severity,
|
|
47
50
|
confidence=Confidence.HIGH if pinned else Confidence.MEDIUM,
|
|
48
51
|
span=requirement.span,
|
|
@@ -52,11 +55,32 @@ class VulnerableDependencyPlugin(ProjectPlugin):
|
|
|
52
55
|
return findings
|
|
53
56
|
|
|
54
57
|
|
|
58
|
+
def _message(ctx: ProjectContext, advisory: Advisory, requirement: Requirement) -> str:
|
|
59
|
+
"""The evidence: for a locked package, the version the lock file pins and the
|
|
60
|
+
packages that require it; for a declared requirement, the specifier that allows or
|
|
61
|
+
requires a vulnerable version."""
|
|
62
|
+
|
|
63
|
+
if requirement.locked is None:
|
|
64
|
+
verb = "required" if requirement.pinned is not None else "allowed"
|
|
65
|
+
return (
|
|
66
|
+
f"{advisory.id}: {advisory.package} {advisory.vulnerable} is {verb} by "
|
|
67
|
+
f"{requirement.name}{requirement.specifier or ''}: {advisory.summary}"
|
|
68
|
+
)
|
|
69
|
+
lock = PurePath(str(requirement.span.source_id)).name
|
|
70
|
+
dependents = sorted(ctx.dependencies.required_by(requirement.name) or ())
|
|
71
|
+
required = f" (required by {', '.join(dependents)})" if dependents else ""
|
|
72
|
+
return (
|
|
73
|
+
f"{advisory.id}: {advisory.package} {requirement.locked}, pinned in {lock}, "
|
|
74
|
+
f"is in {advisory.vulnerable}{required}: {advisory.summary}"
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
55
78
|
def _ruled_out(ctx: ProjectContext) -> dict[str, list[str]]:
|
|
56
79
|
"""By advisory, the calls to its entry points whose arguments contradict one of its
|
|
57
80
|
conditions: the evidence that the requirement, imported, is not reached there."""
|
|
58
81
|
|
|
59
82
|
affected = affected_symbols(ctx.dependencies, ctx.advisories)
|
|
83
|
+
suffixes = suffix_index(affected, ctx.modules)
|
|
60
84
|
excluded: dict[str, list[str]] = {}
|
|
61
85
|
for module in sorted(ctx.modules):
|
|
62
86
|
graph = ctx.call_graph(module)
|
|
@@ -64,8 +88,8 @@ def _ruled_out(ctx: ProjectContext) -> dict[str, list[str]]:
|
|
|
64
88
|
for site in graph.sites(function):
|
|
65
89
|
if not isinstance(site.target, ExternalSymbol):
|
|
66
90
|
continue
|
|
67
|
-
for advisory in
|
|
68
|
-
check = check_conditions(
|
|
91
|
+
for advisory, entry in affected_entries(site.target.symbol, affected, suffixes):
|
|
92
|
+
check = check_conditions(entry, site.arguments, prior_calls=site.prior_calls)
|
|
69
93
|
if check.contradicted is not None:
|
|
70
94
|
excluded.setdefault(advisory.id, []).append(ruled_out(module, site, check))
|
|
71
95
|
return excluded
|