fix(guardrails): probe map and fields verdicts fail closed, console rule sees public/, raw escape WARN, argv silent, plan validation
This commit is contained in:
1 parent
6c0006bce3
commit
c0fdbec3c1
8 files changed
+206
-44
No files matched your search
@@ -88,6 +88,40 @@ class H(BaseHTTPRequestHandler):
|
||||
if path == "/api/clean":
|
||||
return self._send(200, b'{"id": 7, "name": "Ada", "role": "member"}',
|
||||
{"Content-Type": "application/json"})
|
||||
if path == "/embed.js":
|
||||
return self._send(200, b'var s="//# sourceMappingURL=data:'
|
||||
b'application/json;base64,"+btoa(m);\n')
|
||||
if path == "/redir.js":
|
||||
return self._send(200, b"console.log(6);\n")
|
||||
if path == "/redir.js.map":
|
||||
return self._send(302, b"", {"Location": "http://other.invalid/m"})
|
||||
if path == "/hdr.js":
|
||||
return self._send(200, b"console.log(7);\n",
|
||||
{"SourceMap": "/hdr.real.map"})
|
||||
if path == "/hdr.real.map":
|
||||
return self._send(200, b'{"version":3,"sources":["a.ts"]}')
|
||||
if path == "/cmt.js":
|
||||
return self._send(200, b"console.log(8);\n//# sourceMappingURL="
|
||||
b"cmt.real.map\n")
|
||||
if path == "/cmt.real.map":
|
||||
return self._send(200, b'{"version":3,"sources":["b.ts"]}')
|
||||
if path == "/offhost.js":
|
||||
return self._send(200, b"x();\n//# sourceMappingURL="
|
||||
b"http://other.invalid/o.map\n")
|
||||
if path == "/trunc.js":
|
||||
return self._send(200, b"a" * 1_000_001)
|
||||
if path == "/bigmap.js":
|
||||
return self._send(200, b"y();\n")
|
||||
if path == "/bigmap.js.map":
|
||||
return self._send(200, b'{"sources":["c.ts"],"x":"' + b"A" * 1_000_001)
|
||||
if path == "/api/echo":
|
||||
bearer = self.headers.get("Authorization", "")
|
||||
body = b'{"id": 1, "password_hash": "x"}' if bearer else b'{"id": 1}'
|
||||
return self._send(200, body, {"Content-Type": "application/json"})
|
||||
if path == "/api/graphql":
|
||||
return self._send(200, b'{"data": {"users": {"edges": [{"node": '
|
||||
b'{"passwordHash": "x"}}]}}}',
|
||||
{"Content-Type": "application/json"})
|
||||
if path == "/boom":
|
||||
return self._send(500, b"Traceback (most recent call last):\n"
|
||||
b' File "app.py", line 12, in handler\n')
|
||||
@@ -274,6 +308,79 @@ OUT="$(probe --authorized "$WORK/lower.json")"
|
||||
check "lowercase CORS header names are still read" \
|
||||
"$(verdict "$OUT" 'cors-reflect')" OPEN
|
||||
|
||||
echo "== exposure probes: map channels and fail-closed paths"
|
||||
cat > "$WORK/maps.json" <<EOF
|
||||
{"base_url": "$BASE",
|
||||
"exposure": {"scripts": ["/embed.js", "/redir.js", "/hdr.js", "/cmt.js",
|
||||
"/offhost.js", "/trunc.js", "/bigmap.js"], "error_routes": []}}
|
||||
EOF
|
||||
OUT="$(probe --authorized "$WORK/maps.json")"
|
||||
check "a sourceMappingURL string inside code is CLOSED, not an inline map" \
|
||||
"$(verdict "$OUT" 'sourcemap:/embed.js')" CLOSED
|
||||
check "a map that redirects off host is SKIPPED, never CLOSED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/redir.js')" SKIPPED
|
||||
check "a map named by the SourceMap header is OPEN" \
|
||||
"$(verdict "$OUT" 'sourcemap:/hdr.js')" OPEN
|
||||
check "a map named by the trailing comment is OPEN" \
|
||||
"$(verdict "$OUT" 'sourcemap:/cmt.js')" OPEN
|
||||
check "a map url on another host is SKIPPED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/offhost.js')" SKIPPED
|
||||
check "a truncated script is SKIPPED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/trunc.js')" SKIPPED
|
||||
check "an oversize map is SKIPPED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/bigmap.js')" SKIPPED
|
||||
|
||||
echo "== fields probe: depth and bearer"
|
||||
cat > "$WORK/fields.json" <<EOF
|
||||
{"base_url": "$BASE",
|
||||
"routes": [{"path": "/api/echo"}, {"path": "/api/graphql"}],
|
||||
"exposure": {"scripts": [], "error_routes": []}}
|
||||
EOF
|
||||
OUT="$(probe --authorized "$WORK/fields.json")"
|
||||
check "a sensitive key nested past four levels is OPEN" \
|
||||
"$(verdict "$OUT" 'fields:/api/graphql')" OPEN
|
||||
check "the fields probe sends the bearer (key seen only with it)" \
|
||||
"$(verdict "$OUT" 'fields:/api/echo')" OPEN
|
||||
OUT="$(env -u GUARDRAILS_JWT2 python3 -B "$PROBE" --authorized "$WORK/fields.json")"
|
||||
check "without the bearer the same route is CLOSED" \
|
||||
"$(verdict "$OUT" 'fields:/api/echo')" CLOSED
|
||||
|
||||
echo "== plan validation and host guard"
|
||||
printf '{"base_url": "file:///tmp"}\n' > "$WORK/file.json"
|
||||
probe --authorized "$WORK/file.json" >/dev/null 2>&1
|
||||
check "a file:// base_url exits 2" "$?" 2
|
||||
printf '{"base_url": 5}\n' > "$WORK/num.json"
|
||||
ERR="$(probe --authorized "$WORK/num.json" 2>&1 >/dev/null)"
|
||||
check "a non-string base_url exits 2 without a traceback" \
|
||||
"$(printf '%s\n' "$ERR" | grep -c 'Traceback')" 0
|
||||
probe --authorized "$WORK/num.json" >/dev/null 2>&1
|
||||
check "a non-string base_url exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "rate_limit": {"count": 5}}\n' "$BASE" > "$WORK/nopath.json"
|
||||
ERR="$(probe --authorized "$WORK/nopath.json" 2>&1 >/dev/null)"
|
||||
check "a rate_limit with no path gives a usage message, no traceback" \
|
||||
"$(printf '%s\n' "$ERR" | grep -c 'rate_limit.path must be a string')" 1
|
||||
probe --authorized "$WORK/nopath.json" >/dev/null 2>&1
|
||||
check "a rate_limit with no path exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "routes": [{"path": "/a\\u001b[31mb"}]}\n' "$BASE" > "$WORK/ctl.json"
|
||||
check "a control character in a path is an ERROR row, no traceback" \
|
||||
"$(probe --authorized "$WORK/ctl.json" 2>&1 | grep -c 'Traceback')" 0
|
||||
check "control characters of a target never reach the output" \
|
||||
"$(probe --authorized "$WORK/ctl.json" | LC_ALL=C grep -c "$(printf '\033')")" 0
|
||||
same_host() { python3 -B -c '
|
||||
import sys
|
||||
sys.path.insert(0, sys.argv[1])
|
||||
import probe
|
||||
print(bool(probe._same_host(sys.argv[2], sys.argv[3])))' \
|
||||
"$ROOT/skills/guardrails/scripts" "$1" "$2"; }
|
||||
check "an https to http move is not the same host" \
|
||||
"$(same_host https://a.test/x http://a.test/y)" False
|
||||
check "a different port is not the same host" \
|
||||
"$(same_host http://a.test/x http://a.test:81/y)" False
|
||||
check "a same-scheme same-host url is kept" \
|
||||
"$(same_host http://a.test/x /y)" True
|
||||
check "an http to https upgrade on the host is kept" \
|
||||
"$(same_host http://a.test/x https://a.test/y)" True
|
||||
|
||||
echo "== JSON output"
|
||||
check "json reports the open count" \
|
||||
"$(probe --authorized --json "$WORK/plan.json" \
|
||||
|
||||
@@ -179,8 +179,14 @@ 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' \$'<?php \$r = \$db->query(\"select id from notes where owner = \\'\" . \$owner . \"\\'\");' > src/lib/notes.php"
|
||||
mutant sql-raw-unsafe FAIL INJ-SQL-RAW-UNSAFE \
|
||||
mutant sql-raw-unsafe WARN INJ-SQL-RAW-UNSAFE \
|
||||
"printf '%s\n' 'const rows = await prisma.\$queryRawUnsafe(statement);' >> $API"
|
||||
mutant sql-sqla-text-var WARN INJ-SQL-RAW-UNSAFE \
|
||||
"printf '%s\n' 'import sqlalchemy' 'conn.execute(text(query))' > src/lib/db.py"
|
||||
mutant shell-db-os-system FAIL INJ-SHELL-DB-TOOL \
|
||||
"printf '%s\n' 'os.system(\"psql \" + url)' > src/lib/backup.py"
|
||||
mutant shell-db-template FAIL INJ-SHELL-DB-TOOL \
|
||||
"printf '%s\n' 'exec(\`psql \${db}\`);' > src/lib/backup.ts"
|
||||
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 \
|
||||
@@ -191,6 +197,12 @@ 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 "== exposure"
|
||||
mutant console-data-public-dir WARN EXP-CONSOLE-DATA \
|
||||
"mkdir -p public/js; printf '%s\n' 'console.log(user);' > public/js/app.js"
|
||||
mutant data-attr-hidden-input WARN EXP-DATA-ATTR-SENSITIVE \
|
||||
"printf '%s\n' '<input type=\"hidden\" name=\"api_key\" value={k} />' >> $TSX"
|
||||
mutant debug-errorhandler FAIL EXP-DEBUG-ON \
|
||||
"printf '%s\n' 'app.use(errorhandler());' >> $API"
|
||||
mutant console-data WARN EXP-CONSOLE-DATA \
|
||||
"printf '%s\n' 'console.log(\"saved\", session);' >> $TSX"
|
||||
mutant sourcemap-next FAIL EXP-SOURCEMAP-PUBLIC \
|
||||
@@ -306,6 +318,16 @@ benign minified-bundle \
|
||||
benign long-line-bundle \
|
||||
"head -c 6000 /dev/zero | tr '\\0' x > src/lib/bundle.js; printf '%s\n' ' const q=\`select id from notes where owner = \${o}\`;' >> src/lib/bundle.js"
|
||||
|
||||
benign sqla-text-method \
|
||||
"printf '%s\n' 'import sqlalchemy' 'label = project.text(path)' > src/lib/db.py"
|
||||
benign shell-db-argv-spawn \
|
||||
"printf '%s\n' 'spawn(\"psql\", [\"-f\", file], {env});' > src/lib/backup.ts"
|
||||
benign shell-db-argv-python \
|
||||
"printf '%s\n' 'subprocess.run([\"psql\", f\"--dbname={url}\"])' > src/lib/backup.py"
|
||||
benign shell-db-env-ref \
|
||||
"printf '%s\n' 'execSync(\"psql \$DATABASE_URL -f schema.sql\");' > src/lib/backup.ts"
|
||||
benign console-public-minified \
|
||||
"mkdir -p public/js; printf '%s\n' 'console.log(user);' > public/js/app.min.js"
|
||||
benign console-plain-string \
|
||||
"printf '%s\n' 'console.log(\"ready\");' >> $TSX"
|
||||
benign console-string-data \
|
||||
|
||||
Reference in new issue
Block a user