Skip to content

Commit 40cea88

Browse files
committed
fix(patterns): gate constructed-path AST parse behind join pre-check
The AST-based os.path.join resolver parsed every Python file, defeating the runner's parse-once invariant (one shared parse per file across the analyzer fan-out). Gate the local parse behind a cheap textual pre-check so files without a plausible join() call never pay for it. The module stays lexical, preserving windowed and normalized-view scans for all file types. Signed-off-by: Deepak Jain <[email protected]>
1 parent 8262737 commit 40cea88

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎src/skillspector/nodes/analyzers/static_patterns_privilege_escalation.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,17 +663,26 @@ def _is_qualified_benign_access_requirement(
663663
return heading_index >= 0 and lines[heading_index].strip() == "## Access Requirements"
664664

665665

666+
# Cheap pre-check before parsing for constructed join calls: the AST walk
667+
# below is only worthwhile when the text plausibly contains a join() call.
668+
# This keeps the module lexical (windowed and normalized-view scans keep
669+
# working for every file type) while preserving the runner's parse-once
670+
# invariant for files without any join call.
671+
_JOIN_CALL_HINT = re.compile(r"\bjoin\s*\(")
672+
673+
666674
def _constructed_sensitive_paths(content: str, file_path: str) -> list[tuple[int, str, float]]:
667675
"""Return literal sensitive paths assembled with ``os.path.join`` in Python.
668676
669677
Resolved from the Python AST so calls split across lines and supported
670678
import spellings (``import os.path as p``, ``from os.path import join``,
671679
``from os import path``) are recognized without reparsing tricks. Only
672680
fully-literal positional argument lists are resolved; anything dynamic is
673-
left to the existing pattern loop. Parsing stays local to this module so
674-
its runner contract (lexical scanning, windowed views) does not change;
675-
unparseable content simply yields no findings here.
681+
left to the existing pattern loop. Unparseable content simply yields no
682+
findings here.
676683
"""
684+
if not _JOIN_CALL_HINT.search(content):
685+
return []
677686
parsed = parse_python_source(content, file_path)
678687
tree = parsed.tree
679688
if tree is None:

0 commit comments

Comments
 (0)