index: limit file name length

This commit is contained in:
Peter Cai 2020-02-19 16:49:41 +08:00
parent 709a6d24a9
commit 4a1b677243
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F
2 changed files with 6 additions and 1 deletions

View File

@ -49,6 +49,8 @@ handleRequest = (event) ->
handlePUT = (req, file) ->
if not util.validateLength req
return buildInvalidResponse "Maximum upload size: " + util.MAX_UPLOAD_SIZE
if file.length > util.MAX_FILENAME_LENGTH
return buildInvalidResponse "File name too long (max #{util.MAX_FILENAME_LENGTH})"
# Generate a valid ID first
id = null

View File

@ -2,6 +2,8 @@ import { detect as detectBrowser } from 'detect-browser'
# Maimum upload size (in bytes)
MAX_UPLOAD_SIZE = 10 * 1024 * 1024 # 10 MB
# Maximum file name length
MAX_FILENAME_LENGTH = 255 # bytes
# Validate content-length header
validateLength = (req) ->
@ -88,5 +90,6 @@ export {
isBrowser,
isText,
progressText,
humanFileSize
humanFileSize,
MAX_FILENAME_LENGTH
}