mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 19:11:10 +00:00
Removes the option to disable theme scripts
This commit is contained in:
1 parent
531450b3db
commit
15945c2e56
17 files changed
+15
-201
No files matched your search
@@ -46,9 +46,4 @@ public sealed class ThemeEngineOptionsDto
|
||||
/// Gets or sets the maximum allowed number of entries in a theme pack archive.
|
||||
/// </summary>
|
||||
public int MaxEntries { get; set; } = 250;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether script elements in theme templates and script files in theme assets are allowed to be served.
|
||||
/// </summary>
|
||||
public bool AllowThemeScripts { get; set; }
|
||||
}
|
||||
@@ -45,12 +45,6 @@ public sealed class ThemeService : IThemeService
|
||||
"^[A-Za-z0-9][A-Za-z0-9._ -]*$",
|
||||
RegexOptions.Compiled | RegexOptions.CultureInvariant);
|
||||
|
||||
// strips every script element from a template, both the inline content and the src attribute variants,
|
||||
// so that no script bundled in a theme is executed in any client when scripts are disabled
|
||||
private static readonly Regex s_scriptElementPattern = new(
|
||||
"<script\\b[^>]*>[\\s\\S]*?</script\\s*>",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
|
||||
|
||||
private static readonly JsonSerializerOptions s_manifestJsonOptions = new(JsonSerializerDefaults.Web)
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
@@ -87,11 +81,6 @@ public sealed class ThemeService : IThemeService
|
||||
_mutationGate = s_storageGates.GetOrAdd(_storageRoot, static _ => new SemaphoreSlim(1, 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether theme templates may contain script elements and theme assets may include script files.
|
||||
/// </summary>
|
||||
public bool AllowThemeScripts => _options.AllowThemeScripts;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum allowed size of a theme archive, in bytes.
|
||||
/// </summary>
|
||||
@@ -280,8 +269,6 @@ public sealed class ThemeService : IThemeService
|
||||
return Errors.Themes.ThemeFilesUnreadable;
|
||||
|
||||
string template = await File.ReadAllTextAsync(fullPathResult.Value, cancellationToken);
|
||||
if (!AllowThemeScripts)
|
||||
template = StripScriptElements(template);
|
||||
|
||||
return template;
|
||||
}
|
||||
@@ -330,10 +317,6 @@ public sealed class ThemeService : IThemeService
|
||||
if (!normalizedPath.StartsWith("assets/", StringComparison.Ordinal))
|
||||
return PackageInvalid("The requested asset is not located under the assets directory.");
|
||||
|
||||
// scripts in theme assets are gated globally: when disabled, script files are not served at all
|
||||
if (!AllowThemeScripts && string.Equals(Path.GetExtension(normalizedPath), ".js", StringComparison.OrdinalIgnoreCase))
|
||||
return Errors.Themes.ThemeFilesUnreadable;
|
||||
|
||||
Result<string> fullPathResult = ResolveContainedPath(ResolveThemePath(themeId), normalizedPath);
|
||||
if (fullPathResult.IsFailure)
|
||||
return fullPathResult.Errors;
|
||||
@@ -782,16 +765,6 @@ public sealed class ThemeService : IThemeService
|
||||
return Error.Validation(code: "Theme.Package.Invalid", description: description);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes every script element from a theme template, so that no script bundled in the theme runs when scripts are disabled.
|
||||
/// </summary>
|
||||
/// <param name="template">The template content to strip script elements from.</param>
|
||||
/// <returns>The template content without script elements.</returns>
|
||||
private static string StripScriptElements(string template)
|
||||
{
|
||||
return s_scriptElementPattern.Replace(template, string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the storage path of a theme pack directory for a theme identifier.
|
||||
/// </summary>
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
"MaxArchiveBytes": 8388608,
|
||||
"MaxExpandedBytes": 25165824,
|
||||
"MaxSingleFileBytes": 6291456,
|
||||
"MaxEntries": 250,
|
||||
"AllowThemeScripts": true
|
||||
"MaxEntries": 250
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=<host>;Database=<database>;User Id=<user>;Password=<password>;"
|
||||
|
||||
Reference in new issue
Block a user