T09 · Insecure Skill Coding Practices
- Location
SKILL.md:143- Finding
Process-Wide Built-in Namespace Mutation
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 143–145
Vulnerability Type: Process-wide namespace pollution
Risk Level: Lowpython import builtins builtins.fib = fib_refactored results2 = cycle.run_tests()Technical Analysis
The example modifies Python's global
builtinsmodule by assigningfib_refactoredtobuiltins.fib. The built-in namespace is shared throughout the current Python interpreter, so this change is visible to unrelated modules and code running in the same process.Adding application-specific functions to
builtinsbypasses normal module scoping and can create unexpected name resolution behavior. It may overwrite an existing attribute, conflict with another component that uses the same name, or leave process-wide state behind after the demonstration completes. Although the assigned function is locally defined and no direct attacker-controlled value is present in the audited code, this pattern is unsafe if copied into a shared, long-running, or extensible interpreter.Attack Path
- A user copies or executes the example in a Python process shared with other components.
- The example assigns
fib_refactoredto the process-widebuiltins.fibattribute. - Other code in that interpreter resolves an otherwise undefined
fibname through the modified built-in namespace. - That code executes the injected function or experiences behavior different from its intended module-local resolution.
- In an extensible environment where another component can replace
fib_refactoredbefore assignment, the same pattern could expose unrelated code to substituted behavior.
This finding does not establish remote code execution or privilege escalation by itself. Exploitation depends on the example being executed in a shared interpreter and other code relying on built-in name resolution.
Impact Assessment
The mutation affects the entire current Python interpreter rather ...[truncated 435 chars]
- Remediation
View remediation
Remediation Suggestions
Keep the refactored implementation in module-local scope and explicitly update the test references instead of modifying
builtins. For example:python fib = fib_refactored results2 = cycle.run_tests()Preferably, redesign
TDDCycleso tests receive the implementation explicitly through dependency injection:python def fib_test_basic(implementation): assert implementation(0) == 0 assert implementation(1) == 1Additional hardening measures:
- Remove
import builtinsand thebuiltins.fibassignment. - Avoid process-global mutation in documentation examples.
- Restore any global state in a
finallyblock if temporary mutation is unavoidable. - Run demonstrations in isolated subprocesses when global interpreter changes are required.
- Add a regression test confirming that executing the example does not add or replace attributes in
builtins.
- Remove
