From 7500a618feec18d82a7ed9217b5b249c0944d152 Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 19 Oct 2026 00:32:06 +0200 Subject: [PATCH] feat(guardrails): injection domain (INJ-*): per-language SQL concat and raw escapes, dynamic EXECUTE, PostgREST, NoSQL, shell into DB tools; shared code_files/hits/dedupe helpers --- lib/tests/guardrails-scan.test.sh | 52 +++++++ skills/guardrails/scripts/checks/common.py | 41 ++++++ skills/guardrails/scripts/checks/injection.py | 139 ++++++++++++++++++ skills/guardrails/scripts/scan.py | 4 +- 4 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 skills/guardrails/scripts/checks/injection.py diff --git a/lib/tests/guardrails-scan.test.sh b/lib/tests/guardrails-scan.test.sh index 3cb6d50..5036089 100644 --- a/lib/tests/guardrails-scan.test.sh +++ b/lib/tests/guardrails-scan.test.sh @@ -52,6 +52,7 @@ SQL=supabase/migrations/0001_init.sql TSX=src/components/ContactForm.tsx NOTIFY=supabase/functions/notify/index.ts SMS=supabase/functions/sms/index.ts +API=src/pages/api/notes.ts echo "== clean fixture" out=$(scan "$GOOD"); rc=$? @@ -175,6 +176,32 @@ mutant firebase-loop WARN FN-SELF-TRIGGER \ mutant key-body FAIL API-SECRET-LITERAL \ 'printf -- "-----BEGIN %s KEY-----\n%s\n" PRIVATE "$(head -c 40 /dev/zero | tr "\0" A)" > src/key.ts' +echo "== injection" +mutant sql-template FAIL INJ-SQL-CONCAT \ + "printf '%s\n' 'const q = \`select id from notes where owner = \${owner}\`;' >> $API" +mutant sql-concat FAIL INJ-SQL-CONCAT \ + "printf '%s\n' 'const q = \"select id from notes where owner = \" + owner;' >> $API" +mutant sql-fstring FAIL INJ-SQL-CONCAT \ + "printf '%s\n' 'cur.execute(f\"delete from notes where id = {note_id}\")' > src/lib/cleanup.py" +mutant sql-php-interpolation FAIL INJ-SQL-CONCAT \ + "printf '%s\n' 'query(\"select id from notes where owner = \$owner\");' > src/lib/notes.php" +mutant sql-py-concat FAIL INJ-SQL-CONCAT \ + "printf '%s\n' 'cur.execute(\"select id from notes where owner = \" + owner)' > src/lib/cleanup.py" +mutant sql-quoted-value FAIL INJ-SQL-CONCAT \ + "printf '%s\n' \$'const q = \"select id from notes where owner = \\'\" + owner + \"\\'\";' >> $API" +mutant sql-php-dot FAIL INJ-SQL-CONCAT \ + "printf '%s\n' \$'query(\"select id from notes where owner = \\'\" . \$owner . \"\\'\");' > src/lib/notes.php" +mutant sql-raw-unsafe FAIL INJ-SQL-RAW-UNSAFE \ + "printf '%s\n' 'const rows = await prisma.\$queryRawUnsafe(statement);' >> $API" +mutant sql-dynamic-exec WARN INJ-SQL-DYNAMIC-EXEC \ + "printf '%s\n' \"execute 'select count(*) from ' || tbl into n;\" >> $SQL" +mutant postgrest-filter WARN INJ-POSTGREST-FILTER \ + "printf '%s\n' 'const { data } = await supabase.from(\"notes\").select().or(\`owner.eq.\${who}\`);' >> $API" +mutant nosql-operator WARN INJ-NOSQL-OPERATOR \ + "printf '%s\n' 'const doc = await Notes.findOne({ owner: req.body.owner });' >> $API" +mutant shell-db-tool FAIL INJ-SHELL-DB-TOOL \ + "printf '%s\n' 'execSync(\`pg_dump --table=\${table} app > backup.sql\`);' > src/lib/backup.ts" + echo "== benign patterns stay silent" benign() { # benign