mirror of
https://github.com/simonw/datasette.git
synced 2026-09-09 01:54:15 +02:00
Fix for SQL injection issue in table filters, refs #2868
This commit is contained in:
parent
1d68d86e04
commit
c43d89382f
5 changed files with 119 additions and 23 deletions
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue