Skip to content

Commit

Permalink
Uncontrolled data used in path expression (#542)
Browse files Browse the repository at this point in the history
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 3b5fce3 commit a45a54b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Web/Grand.Web.Admin/Controllers/SettingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,11 @@ private void SavePushNotificationsToFile(PushNotificationsSettingsModel model, I
private string GetSafeFilePath(IConfiguration configuration, IWebHostEnvironment webHostEnvironment, string filename)
{
var directoryParam = configuration[CommonPath.DirectoryParam] ?? "";

// Validate directoryParam to ensure it does not contain ".." or path separators
if (directoryParam.Contains("..") || directoryParam.Contains("/") || directoryParam.Contains("\\"))
throw new ArgumentException("Invalid directory parameter - contains illegal characters.");

var safeDirectoryName = Path.GetFileName(directoryParam);
var combinedPath = Path.Combine(webHostEnvironment.WebRootPath, safeDirectoryName, filename);
var fullPath = Path.GetFullPath(combinedPath, webHostEnvironment.WebRootPath);
Expand Down

0 comments on commit a45a54b

Please sign in to comment.