Skip to content

Commit

Permalink
add html, htm and cshtml, and extensionless to default upload extensi…
Browse files Browse the repository at this point in the history
…on blacklist
  • Loading branch information
volkanceylan committed Apr 6, 2023
1 parent b3e333a commit f54e9bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serenity.ComponentModel;
namespace Serenity.ComponentModel;

/// <summary>
/// Constraints of the uploaded file size.
Expand All @@ -21,7 +21,7 @@ public interface IUploadFileConstraints : IUploadOptions

/// <summary>
/// Contains extensions that are considered dangerous / disallowed.
/// Default is ".asax;.compiled;.ascx;.asmx;.aspx;.bat;.cmd;.com;.config;.dll;.jar;.jsp;.htaccess;.htpasswd;.lnk;.php;.ps1;.vbe;.vbs"
/// Default is ".;.asax;.compiled;.ascx;.asmx;.aspx;.bat;.cmd;.com;.config;.cshtml;.dll;.jar;.jsp;.htaccess;.htpasswd;.html;.htm;.lnk;.php;.ps1;.vbe;.vbs"
/// </summary>
public string? ExtensionBlacklist { get; }

Expand Down
6 changes: 3 additions & 3 deletions src/Serenity.Net.Core/ComponentModel/Upload/UploadOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Serenity.Web;
using Serenity.Web;

namespace Serenity.ComponentModel;

Expand Down Expand Up @@ -99,8 +99,8 @@ public class UploadOptions : IUploadFileConstraints, IUploadFileOptions, IUpload
/// <summary>
/// Default list of blacklisted extensions;
/// </summary>
public const string DefaultExtensionBlacklist = ".asax;.compiled;.ascx;.asmx;.aspx;.bat;.cmd;.com;.config;" +
".dll;.jar;.jsp;.htaccess;.htpasswd;.lnk;.php;.ps1;.vbe;.vbs";
public const string DefaultExtensionBlacklist = ".;.asax;.compiled;.ascx;.asmx;.aspx;.bat;.cmd;.com;.config;.cshtml;" +
".dll;.jar;.jsp;.htm;.html;.htaccess;.htpasswd;.lnk;.php;.ps1;.vbe;.vbs";

/// <inheritdoc/>
public string? ExtensionBlacklist { get; set; }
Expand Down
9 changes: 5 additions & 4 deletions src/Serenity.Net.Services/Upload/DefaultUploadValidator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;

namespace Serenity.Web;

Expand Down Expand Up @@ -39,11 +39,12 @@ public void ValidateFile(IUploadFileConstraints constraints,
throw new ArgumentNullException(nameof(filename));

isImageExtension = false;
var fileExtension = Path.GetExtension(filename);

var fileExtension = Path.GetExtension(filename);

if ((constraints.ExtensionBlacklist ?? UploadOptions.DefaultExtensionBlacklist)
.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)
.Any(x => string.Equals(x.Trim(), fileExtension, StringComparison.OrdinalIgnoreCase)))
.Any(x => string.Equals(x.Trim(), fileExtension, StringComparison.OrdinalIgnoreCase) ||
(x.Trim() == "." && string.IsNullOrEmpty(fileExtension))))
throw new ValidationError(string.Format(CultureInfo.CurrentCulture,
UploadTexts.Controls.ImageUpload.ExtensionBlacklisted.ToString(localizer),
fileExtension));
Expand Down

0 comments on commit f54e9bf

Please # to comment.