sinkmark: find dangerous sinks in source
job
find places where outside input can reach a call that runs code, runs SQL, or runs a shell, and report each one once.
gap it targets
- evidence (fixture): in our fixture run, a popular python ruleset reported
eval of a query arg but missed query = "... '" + user_id + "'" followed by cur.execute(query), where user_id came from request.args in another route.
- evidence (fixture): the same
eval call came back twice under two rule IDs. this skill reports one finding per sink.
- hypothesis: starting from sinks and walking back to sources misses fewer bugs than matching whole patterns, at the cost of some medium-confidence noise.
inputs
- a repo path. v1 scope is
.py files. other languages: report "not covered" instead of guessing.
- optional: a list of changed files, to focus on a diff.
method
- list python files, skipping
venv, .venv, site-packages, node_modules, build, dist.
- find sinks with grep first, then read each hit in context:
- SQL:
.execute(, .executemany(, .raw(, text( from SQLAlchemy, cursor.mogrify(
- code:
eval(, exec(, compile(, __import__(
- shell:
os.system(, os.popen(, subprocess.*(..., shell=True)
- deserialize:
pickle.loads(, pickle.load(, yaml.load( without SafeLoader, marshal.loads(
- for each sink, look at the argument. is it built with
+, %, .format(, or an f-string, or is it a variable assigned from one? if yes, it is a candidate.
- walk back: which function holds it, who calls that function in this file, and do any callers pass
request.args, request.form, request.json, request.values, request.cookies, request.headers, request.GET, request.POST, a FastAPI path or query param, sys.argv, or input()?
- check for a real fix on the path: SQL params passed as a separate tuple or dict,
ast.literal_eval instead of eval, shlex.quote with a list argv and no shell, yaml.safe_load. a regex check or str() is not a fix.
- set confidence: high when a source reaches the sink, medium when the sink takes a string-built value with no source found, low when the value could be constant but you could not prove it.
- one finding per sink line plus CWE. if two checks hit the same line for the same CWE, merge them.
what counts as a finding
- a SQL, code, shell, or deserialize sink whose argument is built from non-constant strings.
- not a finding: constant SQL with bound parameters,
eval of a literal you can see, test files that only exercise a sanitizer (mark info if unsure).
output
{"command":"sinkmark","rule_id":"ks.py.sqli.string-built-query","kind":"sast","severity":"high","confidence":"high","cwe":["CWE-89"],"title":"SQL built from request input reaches execute","location":{"path":"src/app.py","start_line":15,"end_line":16},"evidence":"query built with + from user_id; user_id from request.args in user()","sources":["sinkmark"],"status":"open"}
write all findings as a JSON array, and SARIF 2.1.0 if asked.
today vs later
- today: grep plus reading, plus any static analyzer already installed. treat their output as extra leads, not the answer, and still do steps 3 to 5 yourself.
- once the keelsec engine exists:
keelsec sinkmark <path> --format json does the AST walk and call graph; you only triage.
stop and scope
- read only. never run the app to "test" a sink. live confirmation belongs to
lastproof, on an owned staging target.
- say clearly which languages and folders you did not cover.
1---2name: sinkmark3description: "Use when reviewing Python source for injection bugs, especially SQL built from strings, eval or exec of input, shell=True, pickle or unsafe yaml loads. Traces web input to dangerous calls across functions in the same file. Local only."4metadata:5 source: https://skillmd.com/skills/codejunkie99/sinkmark6---78# sinkmark: find dangerous sinks in source910## job11find places where outside input can reach a call that runs code, runs SQL, or runs a shell, and report each one once.1213## gap it targets14- evidence (fixture): in our fixture run, a popular python ruleset reported `eval` of a query arg but missed `query = "... '" + user_id + "'"` followed by `cur.execute(query)`, where `user_id` came from `request.args` in another route.15- evidence (fixture): the same `eval` call came back twice under two rule IDs. this skill reports one finding per sink.16- hypothesis: starting from sinks and walking back to sources misses fewer bugs than matching whole patterns, at the cost of some medium-confidence noise.1718## inputs19- a repo path. v1 scope is `.py` files. other languages: report "not covered" instead of guessing.20- optional: a list of changed files, to focus on a diff.2122## method231. list python files, skipping `venv`, `.venv`, `site-packages`, `node_modules`, `build`, `dist`.242. find sinks with grep first, then read each hit in context:25 - SQL: `.execute(`, `.executemany(`, `.raw(`, `text(` from SQLAlchemy, `cursor.mogrify(`26 - code: `eval(`, `exec(`, `compile(`, `__import__(`27 - shell: `os.system(`, `os.popen(`, `subprocess.*(..., shell=True)`28 - deserialize: `pickle.loads(`, `pickle.load(`, `yaml.load(` without `SafeLoader`, `marshal.loads(`293. for each sink, look at the argument. is it built with `+`, `%`, `.format(`, or an f-string, or is it a variable assigned from one? if yes, it is a candidate.304. walk back: which function holds it, who calls that function in this file, and do any callers pass `request.args`, `request.form`, `request.json`, `request.values`, `request.cookies`, `request.headers`, `request.GET`, `request.POST`, a FastAPI path or query param, `sys.argv`, or `input()`?315. check for a real fix on the path: SQL params passed as a separate tuple or dict, `ast.literal_eval` instead of `eval`, `shlex.quote` with a list argv and no shell, `yaml.safe_load`. a regex check or `str()` is not a fix.326. set confidence: high when a source reaches the sink, medium when the sink takes a string-built value with no source found, low when the value could be constant but you could not prove it.337. one finding per sink line plus CWE. if two checks hit the same line for the same CWE, merge them.3435## what counts as a finding36- a SQL, code, shell, or deserialize sink whose argument is built from non-constant strings.37- not a finding: constant SQL with bound parameters, `eval` of a literal you can see, test files that only exercise a sanitizer (mark `info` if unsure).3839## output40```json41{"command":"sinkmark","rule_id":"ks.py.sqli.string-built-query","kind":"sast","severity":"high","confidence":"high","cwe":["CWE-89"],"title":"SQL built from request input reaches execute","location":{"path":"src/app.py","start_line":15,"end_line":16},"evidence":"query built with + from user_id; user_id from request.args in user()","sources":["sinkmark"],"status":"open"}42```43write all findings as a JSON array, and SARIF 2.1.0 if asked.4445## today vs later46- today: grep plus reading, plus any static analyzer already installed. treat their output as extra leads, not the answer, and still do steps 3 to 5 yourself.47- once the keelsec engine exists: `keelsec sinkmark <path> --format json` does the AST walk and call graph; you only triage.4849## stop and scope50- read only. never run the app to "test" a sink. live confirmation belongs to `lastproof`, on an owned staging target.51- say clearly which languages and folders you did not cover.