Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public static class ContentSettingsExtensions
/// Allow upload if extension is whitelisted OR if there is no whitelist and extension is NOT blacklisted.
/// </summary>
public static bool IsFileAllowedForUpload(this ContentSettings contentSettings, string extension) =>
contentSettings.AllowedUploadFiles.Any(x => x.InvariantEquals(extension)) ||
(contentSettings.AllowedUploadFiles.Any() == false &&
contentSettings.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension)) == false);
contentSettings.AllowedUploadedFileExtensions.Any(x => x.InvariantEquals(extension)) ||
(contentSettings.AllowedUploadedFileExtensions.Any() == false &&
contentSettings.DisallowedUploadedFileExtensions.Any(x => x.InvariantEquals(extension)) == false);

/// <summary>
/// Gets the auto-fill configuration for a specified property alias.
Expand Down
13 changes: 13 additions & 0 deletions src/Umbraco.Core/Configuration/Models/ContentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,13 @@ @keyframes umbraco-preview-badge--effect {{
/// Gets or sets a value for the collection of file extensions that are disallowed for upload.
/// </summary>
[DefaultValue(StaticDisallowedUploadFiles)]
[Obsolete("Please use DisAllowedUploadedFileExtensions instead, scheduled for removal in V13")]
public IEnumerable<string> DisallowedUploadFiles { get; set; } = StaticDisallowedUploadFiles.Split(',');

/// <summary>
/// Gets or sets a value for the collection of file extensions that are allowed for upload.
/// </summary>
[Obsolete("Please use AllowedUploadedFileExtensions instead, scheduled for removal in V13")]
public IEnumerable<string> AllowedUploadFiles { get; set; } = Array.Empty<string>();

/// <summary>
Expand Down Expand Up @@ -249,4 +251,15 @@ @keyframes umbraco-preview-badge--effect {{
/// </summary>
[DefaultValue(StaticAllowEditInvariantFromNonDefault)]
public bool AllowEditInvariantFromNonDefault { get; set; } = StaticAllowEditInvariantFromNonDefault;

/// <summary>
/// Gets or sets a value for the collection of file extensions that are allowed for upload.
/// </summary>
public string[] AllowedUploadedFileExtensions { get; set; } = Array.Empty<string>();

/// <summary>
/// Gets or sets a value for the collection of file extensions that are disallowed for upload.
/// </summary>
[DefaultValue(StaticDisallowedUploadFiles)]
public string[] DisallowedUploadedFileExtensions { get; set; } = StaticDisallowedUploadFiles.Split(',');
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,32 @@ public static IUmbracoBuilder AddConfiguration(this IUmbracoBuilder builder)
}
});

// TODO: Remove this in V13
// This is to avoid a breaking change in ContentSettings, if the old AllowedFileUploads has a value, and the new
// AllowedFileUploadExtensions does not, copy the value over, if the new has a value, use that instead.
builder.Services.Configure<ContentSettings>(settings =>
{
// We have to use Config.GetSection().Get<string[]>, as the GetSection.GetValue<string[]> simply cannot retrieve a string array
var allowedUploadedFileExtensionsValue = builder.Config.GetSection($"{Constants.Configuration.ConfigContent}:{nameof(ContentSettings.AllowedUploadedFileExtensions)}").Get<string[]>();
var allowedUploadFilesValue = builder.Config.GetSection($"{Constants.Configuration.ConfigContent}:{nameof(ContentSettings.AllowedUploadFiles)}").Get<string[]>();

if (allowedUploadedFileExtensionsValue is null && allowedUploadFilesValue is not null)
{
settings.AllowedUploadedFileExtensions = allowedUploadFilesValue;
}
});

// TODO: Remove this in V13
builder.Services.Configure<ContentSettings>(settings =>
{
var disallowedUploadedFileExtensionsValue = builder.Config.GetSection($"{Constants.Configuration.ConfigContent}:{nameof(ContentSettings.DisallowedUploadedFileExtensions)}").Get<string[]>();
var disallowedUploadFilesValue = builder.Config.GetSection($"{Constants.Configuration.ConfigContent}:{nameof(ContentSettings.DisallowedUploadFiles)}").Get<string[]>();

if (disallowedUploadedFileExtensionsValue is null && disallowedUploadFilesValue is not null)
{
settings.DisallowedUploadedFileExtensions = disallowedUploadFilesValue;
}
});
return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,11 @@ internal async Task<Dictionary<string, object>> GetServerVariablesAsync()
},
{
"disallowedUploadFiles",
string.Join(",", _contentSettings.DisallowedUploadFiles)
string.Join(",", _contentSettings.DisallowedUploadedFileExtensions)
},
{
"allowedUploadFiles",
string.Join(",", _contentSettings.AllowedUploadFiles)
string.Join(",", _contentSettings.AllowedUploadedFileExtensions)
},
{
"maxFileSize",
Expand Down