The Free Software Media System - Server Backend & API
Authenticated arbitrary file overwrite in SubtitleController -> SubtitleManager
Erwin de Haan470305f75edc
diff --git a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs b/MediaBrowser.Providers/Subtitles/SubtitleManager.csindex d4d79d27b5..1f3d9acff2 100644--- a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs+++ b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs@@ -205,12 +205,30 @@ namespace MediaBrowser.Providers.Subtitlesif (saveInMediaFolder){- savePaths.Add(Path.Combine(video.ContainingFolderPath, saveFileName));+ var mediaFolderPath = Path.GetFullPath(Path.Combine(video.ContainingFolderPath, saveFileName));+ // TODO: Add some error handling to the API user: return BadRequest("Could not save subtitle, bad path.");+ if (mediaFolderPath.StartsWith(video.ContainingFolderPath))+ {+ savePaths.Add(mediaFolderPath);+ }}- savePaths.Add(Path.Combine(video.GetInternalMetadataPath(), saveFileName));+ var internalPath = Path.GetFullPath(Path.Combine(video.GetInternalMetadataPath(), saveFileName));++ // TODO: Add some error to the user: return BadRequest("Could not save subtitle, bad path.");+ if (internalPath.StartsWith(video.GetInternalMetadataPath()))+ {+ savePaths.Add(internalPath);+ }- await TrySaveToFiles(memoryStream, savePaths).ConfigureAwait(false);+ if (savePaths.Count > 0)+ {+ await TrySaveToFiles(memoryStream, savePaths).ConfigureAwait(false);+ }+ else+ {+ _logger.LogError("An uploaded subtitle could not be saved because the resulting paths were invalid.");+ }}}