Changeset - 1cfe805689a2
[Not reviewed]
0 3 0
Ben Sturmfels (bsturmfels) - 2 months ago 2024-03-20 04:45:46
ben@sturm.com.au
Handle trailing slashes in static content
3 files changed with 12 insertions and 6 deletions:
0 comments (0 inline, 0 general)
TODO.md
Show inline comments
...
 
@@ -2,5 +2,8 @@
 

	
 
* split the template/content files out from `conservancy/static` into their own
 
  `content` directory (avoid mixing static and non-static content)
 
* ask Denver about why so many license files
 
* serve a 400 in Apache for a hostname we don't explicitly support
 
* use `<detail>` elements for supporter page hidden sections, rather than complex jQuery - or consider Alpine.js
 
* use `<detail>` elements for supporter page hidden sections, rather than
 
  complex jQuery - or consider Alpine.js
 
* replace `internalNavigate` with inline flexbox layout
...
 
@@ -11,3 +14,4 @@
 

	
 
* remove `ForceCanonicalHostnameMiddleware` by ensuring canonical redirect and HTTPS redirect is done by Apache
 
* remove `ForceCanonicalHostnameMiddleware` by ensuring canonical redirect and
 
  HTTPS redirect is done by Apache
 
* standardise settings to replace `settings.py` and `djangocommonsettings.py`
conservancy/urls.py
Show inline comments
...
 
@@ -47,3 +47,3 @@ urlpatterns = [
 
    re_path(r'^projects/', static_views.index),
 
    re_path(r'^GiveUpGitHub', static_views.index),
 
    re_path(r'^GiveUpGitHub/', static_views.index),
 
    re_path(r'^npoacct/', static_views.index, {'fundraiser_sought': 'npoacct'}),
conservancy/views.py
Show inline comments
...
 
@@ -3,4 +3,3 @@ import mimetypes
 
from django.conf import settings
 
from django.http import Http404
 
from django.http import FileResponse
 
from django.http import FileResponse, Http404, HttpResponseRedirect
 
from django.template.response import TemplateResponse
...
 
@@ -37,3 +36,6 @@ def index(request, *args, **kwargs):
 
    safe_from_path_traversal = full_path.is_relative_to(base_path)
 
    if not full_path.exists() or not safe_from_path_traversal:
 
    if full_path.is_dir():
 
        # Should have been accessed with a trailing slash.
 
        return HttpResponseRedirect(request.path + '/')
 
    elif not full_path.exists() or not safe_from_path_traversal:
 
        raise Http404()
0 comments (0 inline, 0 general)