mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Reject null characters in redirect URLs
This commit is contained in:
parent
3aff9f76e4
commit
879239b02c
@ -8,6 +8,9 @@ from wagtail.contrib.redirects import models
|
||||
|
||||
|
||||
def _get_redirect(request, path):
|
||||
if '\0' in path: # reject URLs with null characters, which crash on Postgres (#4496)
|
||||
return None
|
||||
|
||||
try:
|
||||
return models.Redirect.get_for_site(request.site).get(old_path=path)
|
||||
except models.Redirect.MultipleObjectsReturned:
|
||||
|
@ -273,6 +273,19 @@ class TestRedirects(TestCase):
|
||||
|
||||
self.assertRedirects(response, '/redirectto', status_code=301, fetch_redirect_response=False)
|
||||
|
||||
def test_reject_null_characters(self):
|
||||
response = self.client.get('/test%00test/')
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
response = self.client.get('/test\0test/')
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
response = self.client.get('/test/?foo=%00bar')
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
response = self.client.get('/test/?foo=\0bar')
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
||||
class TestRedirectsIndexView(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user