Skip to content

Commit

Permalink
Authenticated arbitrary file overwrite in SubtitleController -> Subti…
Browse files Browse the repository at this point in the history
…tleManager

GHSL-2021-050: Issue 5 Arbitrary file overwrite.
  • Loading branch information
EraYaN committed Mar 20, 2021
1 parent 239a715 commit 470305f
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions MediaBrowser.Providers/Subtitles/SubtitleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,30 @@ public Task UploadSubtitle(Video video, SubtitleResponse response)

if (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.");
}
}
}

Expand Down

0 comments on commit 470305f

Please sign in to comment.