Skip to content

Commit

Permalink
chore: make security exceptions better
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Aug 20, 2024
1 parent ce98f0c commit bf00846
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ConvertTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ internal async Task Run() {
var outputPaths = DownloadTask.GetOutputPaths(files);
foreach (var shortOutputPath in outputPaths) {
var outputPath = Path.Join(filesPath, shortOutputPath);
if (PathHelper.MakeRelativeSub(filesPath, Path.GetFullPath(outputPath)) == null) {
throw new SecurityException("path from mod was attempting to leave the files directory");
var fullOutputPath = Path.GetFullPath(outputPath);
if (PathHelper.MakeRelativeSub(filesPath, fullOutputPath) == null) {
throw new SecurityException($"path from mod was attempting to leave the files directory: '{fullOutputPath}' is not within '{filesPath}'");
}

if (outputPath.Equals(existingPath, StringComparison.InvariantCultureIgnoreCase)) {
Expand Down
2 changes: 1 addition & 1 deletion DownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ private async Task DownloadFile(Uri baseUri, string filesPath, string[] outputPa
var joined = Path.GetFullPath(Path.Join(filesPath, outputPath));
// check that this path is under the files path still
if (PathHelper.MakeRelativeSub(filesPath, joined) == null) {
throw new SecurityException("path from mod was attempting to leave the files directory");
throw new SecurityException($"path from mod was attempting to leave the files directory: '{joined}' is not within '{filesPath}'");
}

if (validPath == null && await CheckHash(joined, hash)) {
Expand Down

0 comments on commit bf00846

Please sign in to comment.