T09 · Insecure Skill Coding Practices
- Location
lib/scanner.py:43- Finding
External Dependency Checks Can Be Bypassed Through Dynamic or Unrecognized Import Syntax
- Content
View full analysis
Vulnerability Details
File Location:
lib/scanner.py, lines 43–54 and line 124
Vulnerability Type: Incomplete static analysis resulting in dependency-check bypass
Risk Level: MediumVulnerable Code
python for line in content.splitlines(): line = line.strip() from_match = re.match(r'^from\s+([\w.]+)\s+import', line) if from_match: imports.append(from_match.group(1)) continue import_match = re.match(r'^import\s+([\w., ]+)', line) if import_match: for mod in import_match.group(1).split(','): mod = mod.strip().split(' as ')[0].strip() if mod and re.match(r'^[\w.]+$', mod): imports.append(mod)The final status is derived solely from the external imports found by this parser:
python 'clean': len(external) == 0,Technical Analysis
The scanner identifies imports by applying regular expressions to individual source lines instead of parsing Python syntax. This only recognizes conventional
importandfrom ... import ...statements that begin on a scanned line.External dependencies loaded through mechanisms such as
importlib.import_module(),__import__(), dynamically executed source, or an import statement following another statement on the same line are not recognized. For example, a scanned file could contain:python import importlib package = importlib.import_module("requests")The scanner would identify
importlibas a standard-library module but would not identifyrequestsas an external dependency. Because thecleanresult is calculated solely from the resultingexternallist, the skill can incorrectly report the scanned project as clean.This is a fail-open condition: unsupported syntax, dynamic imports, and some incomplete analyses are interpreted as an absence of external dependencies rather than as an indeterminate scan requiring manual review.
...[truncated 1683 chars]
- Remediation
View remediation
Remediation Suggestions
- Replace the line-oriented regular-expression parser with
ast.parse()and walk allast.Importandast.ImportFromnodes. This correctly handles indentation, semicolon-separated statements, aliases, parenthesized imports, and multiline syntax. - Inspect calls to common dynamic import mechanisms:
__import__("module")importlib.import_module("module")- Aliases that can be resolved statically
- Extract module names when these calls use constant string arguments.
- If a dynamic import target cannot be resolved statically, return an explicit warning or indeterminate status instead of reporting the project as clean.
- Treat syntax errors, decoding failures, and unreadable files as scan failures. Do not silently interpret them as files with no dependencies.
- Add regression tests covering conventional imports, multiline imports, semicolon-separated imports, constant-string dynamic imports, unresolved dynamic imports, malformed Python files, and unreadable files.
- Distinguish results such as
clean,external dependencies found, andincomplete analysisso users cannot mistake partial coverage for verified stdlib-only compliance.
- Replace the line-oriented regular-expression parser with
