Skip to content

Commit 4cba244

Browse files
deeenesclaude
andcommitted
Fix SQL injection in _quotes: escape single quotes in string values
The _quotes() method wraps values in single quotes for SQL but did not escape internal single quotes, causing SQL syntax errors with URIs containing XML or other special characters (e.g. BioMart queries). Fix: double single quotes (SQL standard escaping) in both the VARCHAR return path and the JSON serialization path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 439ed53 commit 4cba244

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

cachedir/_cache.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,9 +1570,11 @@ def _quotes(string: str | None, typ: str = 'VARCHAR') -> str:
15701570

15711571
string = list(string)
15721572

1573-
string = f"json('{json.dumps(string)}')"
1573+
string = json.dumps(string).replace("'", "''")
1574+
string = f"json('{string}')"
15741575

1575-
return f"'{string}'" if (
1576+
escaped = str(string).replace("'", "''")
1577+
return f"'{escaped}'" if (
15761578
typ.startswith('VARCHAR') or
15771579
typ.startswith('DATETIME')
15781580
) else string

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)