Raise a http 404 error on paths that are too long

We never have any paths this long, and it's nicer to raise a proper 404
than a 500 internal server error.
This commit is contained in:
Magnus Hagander
2019-10-10 20:49:45 +02:00
parent ff11e85e25
commit 2148cb084a

View File

@ -112,6 +112,11 @@ def fallback(request, url):
if not re_staticfilenames.match(url): if not re_staticfilenames.match(url):
raise Http404('Page not found.') raise Http404('Page not found.')
if len(url) > 250:
# Maximum length is really per-directory, but we shouldn't have any pages/fallback
# urls with anywhere *near* that, so let's just limit it on the whole
raise Http404('Page not found.')
try: try:
t = loader.get_template('pages/%s.html' % url) t = loader.get_template('pages/%s.html' % url)
except TemplateDoesNotExist: except TemplateDoesNotExist: