Skip to content

Commit

Permalink
Use text/html for CSRF error page, refs #2390
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Aug 15, 2024
1 parent 160d82f commit 05dfd34
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1661,11 +1661,12 @@ async def setup_db():
async def custom_csrf_error(scope, send, message_id):
await asgi_send(
send,
await self.render_template(
content=await self.render_template(
"csrf_error.html",
{"message_id": message_id, "message_name": Errors(message_id).name},
),
403,
status=403,
content_type="text/html; charset=utf-8",
)

asgi = asgi_csrf.asgi_csrf(
Expand Down
1 change: 1 addition & 0 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,4 +1171,5 @@ async def test_custom_csrf_error(ds_client):
cookies={"csrftoken": "x"},
)
assert response.status_code == 403
assert response.headers["content-type"] == "text/html; charset=utf-8"
assert "Error code is FORM_URLENCODED_MISMATCH." in response.text

0 comments on commit 05dfd34

Please sign in to comment.