fix: harden sqlite identifier quoting#2690
Open
atharvasingh7007 wants to merge 1 commit intosimonw:mainfrom
Open
fix: harden sqlite identifier quoting#2690atharvasingh7007 wants to merge 1 commit intosimonw:mainfrom
atharvasingh7007 wants to merge 1 commit intosimonw:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
escape_sqlite()to standard SQLite double-quoted identifier escaping instead of bracket quoting[{name}]interpolations in Python query builders withescape_sqlite()Root cause
escape_sqlite()wrapped identifiers in square brackets but did not safely handle]inside the identifier. SQLite does not provide a reliable bracket-escape form for embedded], so a malicious table name could break out of that quoting.This also left a few hand-written
[{name}]call sites vulnerable even if the helper was corrected.Testing
python -m pytest tests/test_utils.py tests/test_api.py tests/test_internals_database.py tests/test_crossdb.py -k "escape_sqlite or closing_bracket or detect_fts_different_table_names"python -m ruff check datasette/app.py datasette/database.py datasette/facets.py datasette/filters.py datasette/utils/__init__.py datasette/utils/internal_db.py datasette/views/table.py tests/test_api.py tests/test_crossdb.py tests/test_internals_database.py tests/test_utils.pyCloses #2677
📚 Documentation preview 📚: https://datasette--2690.org.readthedocs.build/en/2690/