feat: support download directory white list (#752)

This commit is contained in:
Levi authored and GitHub committed 2024-09-20 21:32:21 +08:00
1 parent d3750464aa
commit 2dc7048cba
5 files changed
+65 -19

No files matched your search

+14
View File
@@ -857,6 +857,20 @@ func (d *Downloader) doCreate(f fetcher.Fetcher, opts *base.Options) (taskId str
opts.Path = storeConfig.DownloadDir
}
// if enable white download directory, check if the download directory is in the white list
if len(d.cfg.DownloadDirWhiteList) > 0 {
inWhiteList := false
for _, dir := range d.cfg.DownloadDirWhiteList {
if match, err := filepath.Match(dir, opts.Path); match && err == nil {
inWhiteList = true
break
}
}
if !inWhiteList {
return "", errors.New("download directory is not in white list")
}
}
fm, err := d.parseFm(f.Meta().Req.URL)
if err != nil {
return