fix: read filename from Content-Disposition header bypassing Go sanitization
This commit is contained in:
parent
ca6edafbce
commit
bfb8334379
@ -4032,8 +4032,16 @@ func (u *UI) actionFaceGalleryImport(w http.ResponseWriter, r *http.Request) {
|
||||
count := 0
|
||||
for _, files := range r.MultipartForm.File {
|
||||
for _, hdr := range files {
|
||||
// webkitdirectory paths can have varying depth, extract last dir as person name
|
||||
parts := strings.Split(strings.ReplaceAll(hdr.Filename, "\\", "/"), "/")
|
||||
// Go 1.20+ sanitizes hdr.Filename to basename only, parse raw Content-Disposition for full path
|
||||
cd := hdr.Header.Get("Content-Disposition")
|
||||
fullPath := hdr.Filename
|
||||
if idx := strings.LastIndex(cd, `filename="`); idx >= 0 {
|
||||
start := idx + len(`filename="`)
|
||||
if end := strings.IndexByte(cd[start:], '"'); end >= 0 {
|
||||
fullPath = cd[start : start+end]
|
||||
}
|
||||
}
|
||||
parts := strings.Split(strings.ReplaceAll(fullPath, "\\", "/"), "/")
|
||||
if len(parts) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user