Escape tokenize argument in enable_fts (#828)

The tokenize value passed to Table.enable_fts() was interpolated directly
into the CREATE VIRTUAL TABLE statement inside a single-quoted string
literal. A value containing a single quote could break out of that literal
and inject arbitrary SQL, which executes via executescript(). This is
reachable from the CLI via 'enable-fts --tokenize'.

Route the value through the existing Database.quote() helper so SQLite
itself escapes it. Legitimate tokenizers such as 'porter' are unaffected.
Adds a regression test.
This commit is contained in:
Bunlong Heng 2026-08-12 01:48:06 -04:00 committed by GitHub
commit 2d3c6b9a1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View file

@ -3514,7 +3514,9 @@ class Table(Queryable):
table_fts=quote_identifier(self.name + "_fts"),
columns=", ".join(quote_identifier(c) for c in columns),
fts_version=fts_version,
tokenize=f"\n tokenize='{tokenize}'," if tokenize else "",
tokenize=(
f"\n tokenize={self.db.quote(tokenize)}," if tokenize else ""
),
)
)
should_recreate = False