Skip to content

Commit e313c7d

Browse files
committed
Return status 400 on invalid file names
The multipart middleware would throw an exception when it encountered an invalid filename. For most apps that exception would be caught by the default exception handler and result in a status code of 500 instead of 400. This commit catches this specific exception and returns a 400 response from the server instead.
1 parent f39f06c commit e313c7d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ring-core/src/ring/middleware/multipart_params.clj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
FileItemIterator
1515
FileItemStream
1616
FileUpload
17+
InvalidFileNameException
1718
ProgressListener]
1819
[org.apache.commons.io IOUtils]))
1920
(defn- progress-listener
@@ -170,6 +171,12 @@
170171
([handler options]
171172
(fn
172173
([request]
173-
(handler (multipart-params-request request options)))
174+
(try
175+
(handler (multipart-params-request request options))
176+
(catch InvalidFileNameException e
177+
{:status 400 :body (.getMessage e)})))
174178
([request respond raise]
175-
(handler (multipart-params-request request options) respond raise)))))
179+
(try
180+
(handler (multipart-params-request request options) respond raise)
181+
(catch InvalidFileNameException e
182+
{:status 400 :body (.getMessage e)}))))))

0 commit comments

Comments
 (0)