Skip to content

Commit 26d58b4

Browse files
committed
fix(backend): fix html route middlewares
1 parent ca7eb62 commit 26d58b4

File tree

2 files changed

+15
-39
lines changed

2 files changed

+15
-39
lines changed

src/main/parts/middleware.clj

+13-35
Original file line numberDiff line numberDiff line change
@@ -106,37 +106,23 @@
106106
(response/status 401)))))
107107

108108
(defn wrap-html-defaults
109-
"Middleware that applies a customized set of Ring defaults for HTML routes.
110-
111-
This middleware configures a subset of Ring's `site-defaults` that's
112-
appropriate for server-rendered HTML pages.
113-
114-
Applied configurations:
115-
- Parameters: Parses standard, nested, and keyword parameters
116-
- Static resources: Enabled
117-
- Security headers:
118-
- X-Frame-Options
119-
- X-Content-Type-Options
120-
- X-XSS-Protection
121-
- X-Permitted-Cross-Domain-Policies
122-
- X-Download-Options
123-
- Cookie response attributes
124-
125-
Explicitly disabled:
126-
- Session handling: Disabled completely as we use stateless JWT auth
127-
- Global anti-forgery: Disabled here but applied selectively to form-handling
128-
routes, see `anti-forgery`
129-
130-
Usage: Apply this middleware to routes that serve HTML content, and separately
131-
apply `anti-forgery` middleware only to routes that process form submissions."
109+
"Middleware that applies a set of Ring defaults for HTML routes.
110+
Among other things, this middleware enables:
111+
112+
- Anti-forgery protection
113+
- Sessions (necessary for CSRF tokens to work)
114+
115+
We disable wrapping static resources here because these resources need to be
116+
available for all routes, and this middleware is set for certain routes only.
117+
FIXME: This might be troublesome, review middleware order.
118+
119+
And other defaults that are not immediately relevant to us. See
120+
`site-defaults` for the full details."
132121
[handler]
133122
(wrap-defaults
134123
handler
135124
(-> site-defaults
136-
(assoc :session false)
137-
(assoc :security
138-
(-> (:security site-defaults)
139-
(assoc :anti-forgery false))))))
125+
(assoc :static false))))
140126

141127
;; TODO: Investigate whether Content Security Policy is needed:
142128
;; - https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
@@ -206,11 +192,3 @@
206192
(def anti-forgery
207193
"Anti-forgery middleware for HTML forms, see docs on `wrap-anti-forgery`"
208194
wrap-anti-forgery)
209-
210-
;; File upload handling is commented out for now
211-
;; To enable file uploads, uncomment the following:
212-
;; (defn wrap-multipart-params
213-
;; "Handle multipart form data including file uploads"
214-
;; [handler]
215-
;; (-> handler
216-
;; (multipart-params/wrap-multipart-params)))

src/main/parts/routes.clj

+2-4
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@
8383
;; - Proper HTML content-type and string conversion
8484

8585
;; A form is present on the homepage, so we apply CSRF protection
86-
["/" {:middleware [middleware/anti-forgery
87-
middleware/wrap-html-defaults
86+
["/" {:middleware [middleware/wrap-html-defaults
8887
middleware/wrap-html-response]
8988
:get {:handler pages/home-page}}]
9089

@@ -95,8 +94,7 @@
9594
["/up" {:get {:handler (fn [_] {:status 200 :body "OK"})}}]
9695

9796
;; Form submission endpoint with CSRF protection
98-
["/waitlist-signup" {:middleware [middleware/anti-forgery
99-
middleware/wrap-html-defaults
97+
["/waitlist-signup" {:middleware [middleware/wrap-html-defaults
10098
middleware/wrap-html-response]
10199
:post {:handler waitlist/signup}}]
102100

0 commit comments

Comments
 (0)