@@ -34,7 +34,7 @@ const (
34
34
var (
35
35
reForwardedHost = regexp .MustCompile (`host="?([^;"]+)` )
36
36
reForwardedProto = regexp .MustCompile (`proto=(https?)` )
37
- reMimeType = regexp .MustCompile (`^[a-z]+\/[a-z0-9\-\+\.]+ $` )
37
+ reMimeType = regexp .MustCompile (`^(?:application|audio|example|font|haptics|image|message|model|multipart|text|video|x-(?:[0-9A-Za-z!#$%&'*+.^_` + "`" + `|~-]+))\/([0-9A-Za-z!#$%&'*+.^_` + "`" + `|~-]+)((?:[ \t]*;[ \t]*[0-9A-Za-z!#$%&'*+.^_` + "`" + `|~-]+=(?:[0-9A-Za-z!#$%&'*+.^_` + "`" + `|~-]+|"(?:[^"\\]|\.)*"))*) $` )
38
38
// We only allow certain URL-safe characters in upload IDs. URL-safe in this means
39
39
// that their are allowed in a URI's path component according to RFC 3986.
40
40
// See https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
@@ -1112,9 +1112,9 @@ func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request)
1112
1112
// mimeInlineBrowserWhitelist is a map containing MIME types which should be
1113
1113
// allowed to be rendered by browser inline, instead of being forced to be
1114
1114
// downloaded. For example, HTML or SVG files are not allowed, since they may
1115
- // contain malicious JavaScript. In a similiar fashion PDF is not on this list
1115
+ // contain malicious JavaScript. In a similar fashion, PDF is not on this list
1116
1116
// as their parsers commonly contain vulnerabilities which can be exploited.
1117
- // The values of this map does not convey any meaning and are therefore just
1117
+ // The values of this map do not convey any meaning and are therefore just
1118
1118
// empty structs.
1119
1119
var mimeInlineBrowserWhitelist = map [string ]struct {}{
1120
1120
"text/plain" : {},
@@ -1125,38 +1125,40 @@ var mimeInlineBrowserWhitelist = map[string]struct{}{
1125
1125
"image/bmp" : {},
1126
1126
"image/webp" : {},
1127
1127
1128
- "audio/wave" : {},
1129
- "audio/wav" : {},
1130
- "audio/x-wav" : {},
1131
- "audio/x-pn-wav" : {},
1132
- "audio/webm" : {},
1133
- "video/webm" : {},
1134
- "audio/ogg" : {},
1135
- "video/ogg" : {},
1128
+ "audio/wave" : {},
1129
+ "audio/wav" : {},
1130
+ "audio/x-wav" : {},
1131
+ "audio/x-pn-wav" : {},
1132
+ "audio/webm" : {},
1133
+ "audio/ogg" : {},
1134
+
1135
+ "video/mp4" : {},
1136
+ "video/webm" : {},
1137
+ "video/ogg" : {},
1138
+
1136
1139
"application/ogg" : {},
1137
1140
}
1138
1141
1139
1142
// filterContentType returns the values for the Content-Type and
1140
1143
// Content-Disposition headers for a given upload. These values should be used
1141
1144
// in responses for GET requests to ensure that only non-malicious file types
1142
1145
// are shown directly in the browser. It will extract the file name and type
1143
- // from the "fileame " and "filetype".
1146
+ // from the "filename " and "filetype".
1144
1147
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
1145
1148
func filterContentType (info FileInfo ) (contentType string , contentDisposition string ) {
1146
1149
filetype := info .MetaData ["filetype" ]
1147
1150
1148
1151
if reMimeType .MatchString (filetype ) {
1149
- // If the filetype from metadata is well formed, we forward use this
1150
- // for the Content-Type header. However, only whitelisted mime types
1151
- // will be allowed to be shown inline in the browser
1152
+ // If the filetype from metadata is well-formed, we forward use this for the Content-Type header.
1153
+ // However, only allowlisted mime types will be allowed to be shown inline in the browser
1152
1154
contentType = filetype
1153
1155
if _ , isWhitelisted := mimeInlineBrowserWhitelist [filetype ]; isWhitelisted {
1154
1156
contentDisposition = "inline"
1155
1157
} else {
1156
1158
contentDisposition = "attachment"
1157
1159
}
1158
1160
} else {
1159
- // If the filetype from the metadata is not well formed, we use a
1161
+ // If the filetype from the metadata is not well- formed, we use a
1160
1162
// default type and force the browser to download the content.
1161
1163
contentType = "application/octet-stream"
1162
1164
contentDisposition = "attachment"
0 commit comments