secure filename in webvtt regex against accidental evaluation

Co-authored-by: Ramires Viana <59319979+ramiresviana@users.noreply.github.com>
This commit is contained in:
Mazen Besher 2021-12-20 13:51:59 +01:00 committed by GitHub
parent d1b4d54ccf
commit 39abd1da6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -279,7 +279,7 @@ func (i *FileInfo) detectSubtitles() {
dir, err := afs.ReadDir(parentDir) dir, err := afs.ReadDir(parentDir)
if err == nil { if err == nil {
base := strings.TrimSuffix(i.Name, ext) base := strings.TrimSuffix(i.Name, ext)
r := regexp.MustCompile(base + `\.(.*\.)?vtt`) r := regexp.MustCompile("^" + regexp.QuoteMeta(base) + `\.(.*\.)?vtt$`)
for _, f := range dir { for _, f := range dir {
if !f.IsDir() { if !f.IsDir() {
if matches := r.FindStringSubmatch(f.Name()); len(matches) == 2 { if matches := r.FindStringSubmatch(f.Name()); len(matches) == 2 {