File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -607,7 +607,20 @@ var localMusicDir = os.Getenv("MUSIC_DIR") // e.g. "/mp3"
607607func localList (prefix string ) ([]string , []string , error ) {
608608 var dirs , files []string
609609 base := filepath .Join (localMusicDir , prefix )
610- entries , err := os .ReadDir (base )
610+ // Validate that base is inside localMusicDir (avoid path traversal)
611+ rootAbs , err := filepath .Abs (localMusicDir )
612+ if err != nil {
613+ return nil , nil , fmt .Errorf ("failed to resolve music dir: %w" , err )
614+ }
615+ baseAbs , err := filepath .Abs (base )
616+ if err != nil {
617+ return nil , nil , fmt .Errorf ("failed to resolve target dir: %w" , err )
618+ }
619+ // Ensure the requested baseAbs is within rootAbs
620+ if ! strings .HasPrefix (baseAbs , rootAbs ) {
621+ return nil , nil , fmt .Errorf ("invalid directory path: %s" , prefix )
622+ }
623+ entries , err := os .ReadDir (baseAbs )
611624 if err != nil {
612625 return nil , nil , err
613626 }
You can’t perform that action at this time.
0 commit comments