Fix for SQL injection issue in table filters, refs #2868

This commit is contained in:
Simon Willison 2026-08-06 10:57:29 -07:00
commit c43d89382f
5 changed files with 119 additions and 23 deletions

View file

@ -521,6 +521,35 @@ def test_table_filter_queries_multiple_of_same_type(app_client):
] == response.json["rows"]
@pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module")
def test_table_filters_quote_identifiers():
with make_app_client(
extra_databases={
"demo.db": """
create table items (
id integer primary key,
"name""quote" text,
"tags]bracket" text
);
insert into items values (1, 'Alice', '["red"]');
"""
},
) as client:
exact_query = urllib.parse.urlencode(
{'name"quote__exact': "Alice", "_shape": "arrays"}
)
exact_response = client.get(f"/demo/items.json?{exact_query}")
assert exact_response.status == 200
assert exact_response.json["rows"] == [[1, "Alice", '["red"]']]
array_query = urllib.parse.urlencode(
{"tags]bracket__arraycontains": "red", "_shape": "arrays"}
)
array_response = client.get(f"/demo/items.json?{array_query}")
assert array_response.status == 200
assert array_response.json["rows"] == [[1, "Alice", '["red"]']]
@pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module")
def test_table_filter_json_arraycontains(app_client):
response = app_client.get("/fixtures/facetable.json?tags__arraycontains=tag1")