A parallel two-stage security audit agent for Python codebases. Both stages run concurrently, each focusing on a non-overlapping set of vulnerability classes.
agent.yaml— Orchestration with two parallel stages + gatesinjection-system.md/injection-agent.md/injection-task.md— Stage 1resources-system.md/resources-agent.md/resources-task.md— Stage 2references/python-security-guide.md— Comprehensive Python security guide
Focuses exclusively on:
- Command Injection —
subprocesswithshell=True,os.system(),os.popen()with user input - SQL Injection — f-strings /
%formatting / concatenation in database queries - XSS —
Markup()/mark_safe()on user data,autoescape=False - SSTI —
render_template_string()/env.from_string()with user-controlled template content; leads to RCE (CWE-94) - Insecure Deserialization —
pickle.loads(),yaml.load()without SafeLoader,eval()/exec(),marshal.loads(),jsonpickle.decode(),shelvewith user keys,torch.load()withoutweights_only=True,numpy.load(allow_pickle=True)on untrusted data - XML / XXE —
xml.etree,xml.sax,xml.dom.minidom,lxml.etreeon user-supplied XML; fix withdefusedxml - Input Validation — Missing validation at HTTP route handlers, CLI args, WebSocket messages, file-format parsers
Focuses exclusively on:
- Path Traversal — User-controlled file paths without
Path.resolve()+ boundary validation - SSRF — User-controlled URLs to
requests/urllib/httpx/aiohttpwithout allowlist - Weak Cryptography —
randomfor security values, MD5/SHA-1 for passwords,verify=False,CERT_NONE - Hardcoded Secrets — API keys, passwords, tokens, private keys in source code
- Web Framework Misconfig — Django
DEBUG=True/ hardcodedSECRET_KEY; Flaskdebug=True/ hardcodedsecret_key; FastAPI open CORS with credentials - Dependency Vulnerabilities — Packages with known CVEs in requirements.txt, unpinned versions
- Error Information Leaks — Stack traces, internal errors, file paths in HTTP responses
- Insecure Temp Files —
tempfile.mktemp()TOCTOU race (CWE-377); fix withmkstemp()orNamedTemporaryFile() - ReDoS — Regex patterns with catastrophic backtracking on user-controlled input (CWE-1333)
After each stage, the following checks run:
- Syntax check:
python -m compileall -q . - Test suite:
pytest -x --tb=no -q
If a gate fails, the pipeline stops.
squad run python-security-auditEach stage applies fixes within its category scope only:
- Replaces
subprocess(cmd, shell=True)withsubprocess.run([binary, arg1, arg2]) - Parameterizes SQL queries replacing string interpolation
- Removes
Markup()/mark_safe()on user-controlled data - Replaces
pickle.loads()withjson.loads()where appropriate - Replaces
yaml.load()withyaml.safe_load() - Replaces
eval()withast.literal_eval()for simple literals - Validates file paths with
Path.resolve()and base-dir boundary checks - Replaces
random.*withsecrets.token_hex()/secrets.token_urlsafe() - Replaces hardcoded secrets with
os.environ['KEY'] - Removes
verify=Falsefrom requests - Moves
DEBUG/SECRET_KEYout of source and into environment variables - Replaces internal error details in HTTP responses with safe generic messages
- Code quality issues with no security impact
- Changes requiring new dependencies
- Test-asserted behavior
- Issues in the other stage's scope
- Fixes requiring 50+ lines of new code
- python-review — General code quality review
- python-tests — Test coverage improvement
- python-doc-comments — Docstring generation