Skip to content

Commit 4a4bcbc

Browse files
adlzanchetta-trilogybdukes
authored andcommitted
Add module header and footer settings
1 parent 8a925b8 commit 4a4bcbc

File tree

137 files changed

+2852
-999
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+2852
-999
lines changed

Build/Build.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<AdditionalFiles Include="..\stylecop.json" Link="stylecop.json" />
1616
</ItemGroup>
1717
<ItemGroup>
18-
<PackageReference Include="Cake.BuildSystems.Module" Version="8.0.0" />
18+
<PackageReference Include="Cake.BuildSystems.Module" Version="9.0.0" />
1919
<PackageReference Include="Cake.FileHelpers" Version="7.0.0" />
2020
<PackageReference Include="Cake.Frosting" Version="6.0.0" />
2121
<PackageReference Include="Cake.Frosting.Git" Version="5.0.1" />

Build/ContextExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
namespace DotNetNuke.Build;
66

7+
using System;
78
using System.Diagnostics;
8-
9+
910
using Cake.Common.IO;
1011
using Cake.Core.IO;
1112

@@ -18,6 +19,8 @@ public static class ContextExtensions
1819
/// <returns>The file version.</returns>
1920
public static string GetAssemblyFileVersion(this Context context, FilePath assemblyPath)
2021
{
21-
return FileVersionInfo.GetVersionInfo(context.MakeAbsolute(assemblyPath).FullPath).FileVersion;
22+
var versionInfo = FileVersionInfo.GetVersionInfo(context.MakeAbsolute(assemblyPath).FullPath);
23+
var fileVersion = versionInfo.FileVersion;
24+
return Version.TryParse(fileVersion, out _) ? fileVersion : $"{versionInfo.FileMajorPart}.{versionInfo.FileMinorPart}.{versionInfo.FileBuildPart}";
2225
}
2326
}

Build/Tasks/OtherPackages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace DotNetNuke.Build.Tasks
1818
/// <summary>A cake task to include other 3rd party packages.</summary>
1919
[IsDependentOn(typeof(PackageNewtonsoft))]
2020
[IsDependentOn(typeof(PackageMailKit))]
21+
[IsDependentOn(typeof(PackageHtmlSanitizer))]
2122
[IsDependentOn(typeof(PackageAspNetWebApi))]
2223
[IsDependentOn(typeof(PackageAspNetWebPages))]
2324
[IsDependentOn(typeof(PackageAspNetMvc))]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
namespace DotNetNuke.Build.Tasks;
5+
6+
/// <summary>A cake task to generate the MailKit package.</summary>
7+
public sealed class PackageHtmlSanitizer : PackageComponentTask
8+
{
9+
/// <summary>Initializes a new instance of the <see cref="PackageHtmlSanitizer"/> class.</summary>
10+
public PackageHtmlSanitizer()
11+
: base("HtmlSanitizer")
12+
{
13+
}
14+
}

Build/Tasks/unversionedManifests.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
DNN Platform/Components/MailKit/*.dnn
2-
DNN Platform/Components/Microsoft.*/**/*.dnn
3-
DNN Platform/Components/Newtonsoft/*.dnn
4-
DNN Platform/Components/WebFormsMvp/*.dnn
5-
DNN Platform/Components/SharpZipLib/*.dnn
1+
DNN Platform/Components/**/*.dnn
62
DNN Platform/JavaScript Libraries/HoverIntent/*.dnn
73
DNN Platform/JavaScript Libraries/jQuery*/*.dnn
84
DNN Platform/JavaScript Libraries/Knockout*/*.dnn
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<dotnetnuke type="Package" version="5.0">
2+
<packages>
3+
<package name="DotNetNuke.HtmlSanitizer" type="Library" version="1.0.0">
4+
<friendlyName>HtmlSanitizer Components</friendlyName>
5+
<description>Provides AngleSharp and HtmlSanitizer assemblies for the platform.</description>
6+
<dependencies/>
7+
<owner>
8+
<name>.NET Foundation and Contributors</name>
9+
<organization>DNN Community</organization>
10+
<url>https://dnncommunity.org</url>
11+
<email>info@dnncommunity.org</email>
12+
</owner>
13+
<license src="License.txt"/>
14+
<releaseNotes>
15+
This package includes AngleSharp, AngleSharp.Css and HtmlSanitizer assemblies.
16+
</releaseNotes>
17+
<components>
18+
<component type="Assembly">
19+
<assemblies>
20+
<assembly>
21+
<path>bin</path>
22+
<name>AngleSharp.dll</name>
23+
<version />
24+
</assembly>
25+
<assembly>
26+
<path>bin</path>
27+
<name>AngleSharp.Css.dll</name>
28+
<version />
29+
</assembly>
30+
<assembly>
31+
<path>bin</path>
32+
<name>HtmlSanitizer.dll</name>
33+
<version />
34+
</assembly>
35+
<assembly>
36+
<path>bin</path>
37+
<name>System.Collections.Immutable.dll</name>
38+
<version />
39+
</assembly>
40+
<assembly>
41+
<path>bin</path>
42+
<name>System.Text.Encoding.CodePages.dll</name>
43+
<version />
44+
</assembly>
45+
<assembly>
46+
<path>bin</path>
47+
<name>System.Runtime.CompilerServices.Unsafe.dll</name>
48+
<version/>
49+
</assembly>
50+
</assemblies>
51+
</component>
52+
</components>
53+
</package>
54+
</packages>
55+
</dotnetnuke>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (C) 2012-2020 .NET Foundation and Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

DNN Platform/Library/Common/Utilities/HtmlUtils.cs

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ namespace DotNetNuke.Common.Utilities
1313
using DotNetNuke.Internal.SourceGenerators;
1414
using DotNetNuke.Services.Upgrade;
1515

16-
/// <summary>HtmlUtils is a Utility class that provides Html Utility methods.</summary>
16+
using Ganss.Xss;
17+
18+
/// <summary>HtmlUtils is a Utility class that provides HTML Utility methods.</summary>
1719
public partial class HtmlUtils
1820
{
1921
// Create Regular Expression objects
@@ -579,5 +581,81 @@ public static IHtmlString JavaScriptStringEncode(string value)
579581
/// <inheritdoc cref="HttpUtility.JavaScriptStringEncode(string,bool)"/>
580582
public static IHtmlString JavaScriptStringEncode(string value, bool addDoubleQuotes)
581583
=> new HtmlString(HttpUtility.JavaScriptStringEncode(value, addDoubleQuotes));
584+
585+
/// <summary>Sanitize the given HTML, removing element which could include JavaScript.</summary>
586+
/// <param name="htmlInput">The HTML to sanitize.</param>
587+
/// <returns>The sanitized HTML.</returns>
588+
public static string CleanOutOfJavascript(string htmlInput)
589+
{
590+
var sanitizer = new HtmlSanitizer();
591+
592+
// We need to disallow all attributes that might contain JS
593+
sanitizer.AllowedAttributes.Remove("onclick");
594+
sanitizer.AllowedAttributes.Remove("onmouseover");
595+
sanitizer.AllowedAttributes.Remove("onmouseout");
596+
sanitizer.AllowedAttributes.Remove("onkeypress");
597+
sanitizer.AllowedAttributes.Remove("onkeydown");
598+
sanitizer.AllowedAttributes.Remove("onkeyup");
599+
600+
// We need to disallow tags like '<form action="javascript:submitForm()">'
601+
sanitizer.AllowedSchemes.Remove("javascript");
602+
603+
// Tags like '<script>' are obviously not allowed
604+
sanitizer.AllowedTags.Remove("script");
605+
606+
return sanitizer.Sanitize(htmlInput);
607+
}
608+
609+
/// <summary>Determines whether the given <paramref name="htmlInput"/> contains any JavaScript.</summary>
610+
/// <param name="htmlInput">The HTML to check.</param>
611+
/// <returns><see langword="true"/> if <paramref name="htmlInput"/> contains JavaScript, otherwise <see langword="false"/>.</returns>
612+
public static bool ContainsJavaScript(string htmlInput)
613+
{
614+
if (string.IsNullOrEmpty(htmlInput))
615+
{
616+
return false;
617+
}
618+
619+
string cleaned = CleanOutOfJavascript(htmlInput);
620+
621+
// Strip all HTML syntax characters and whitespace for comparison
622+
string strippedOriginal = StripHtmlSyntax(htmlInput);
623+
string strippedCleaned = StripHtmlSyntax(cleaned);
624+
625+
// If the stripped versions are different, JavaScript was likely removed
626+
return !string.Equals(strippedOriginal, strippedCleaned, StringComparison.OrdinalIgnoreCase);
627+
}
628+
629+
/// <summary>Sanitizes the given <paramref name="rawHtmlInput"/> if <paramref name="allowJavaScript"/> is <see langword="false"/>.</summary>
630+
/// <param name="rawHtmlInput">The raw HTML input.</param>
631+
/// <param name="allowJavaScript">Whether to allow JavaScript in the HTML.</param>
632+
/// <returns>The HTML, potentially sanitized.</returns>
633+
public static string SanitizeHtmlIfNeeded(string rawHtmlInput, bool allowJavaScript)
634+
{
635+
// If input is null or empty: nothing to do
636+
if (string.IsNullOrEmpty(rawHtmlInput))
637+
{
638+
return string.Empty;
639+
}
640+
641+
// If JavaScript is not allowed: HTML must be sanitized
642+
if (!allowJavaScript)
643+
{
644+
return CleanOutOfJavascript(rawHtmlInput);
645+
}
646+
647+
return rawHtmlInput;
648+
}
649+
650+
private static string StripHtmlSyntax(string html)
651+
{
652+
if (string.IsNullOrEmpty(html))
653+
{
654+
return string.Empty;
655+
}
656+
657+
// Remove all whitespace and HTML syntax characters
658+
return Regex.Replace(html, @"[\s<>/""'=]", string.Empty);
659+
}
582660
}
583661
}

DNN Platform/Library/DotNetNuke.Library.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@
8888
</PropertyGroup>
8989
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
9090
<ItemGroup>
91+
<Reference Include="AngleSharp, Version=1.4.0.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
92+
<HintPath>..\..\packages\AngleSharp.1.4.0\lib\net472\AngleSharp.dll</HintPath>
93+
</Reference>
94+
<Reference Include="AngleSharp.Css, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
95+
<HintPath>..\..\packages\AngleSharp.Css.1.0.0-beta.159\lib\net472\AngleSharp.Css.dll</HintPath>
96+
</Reference>
9197
<Reference Include="BouncyCastle.Crypto, Version=1.9.0.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
9298
<HintPath>..\..\packages\Portable.BouncyCastle.1.9.0\lib\net40\BouncyCastle.Crypto.dll</HintPath>
9399
</Reference>
@@ -101,6 +107,9 @@
101107
<SpecificVersion>False</SpecificVersion>
102108
<HintPath>..\Controls\DotNetNuke.WebControls\bin\DotNetNuke.WebControls.dll</HintPath>
103109
</Reference>
110+
<Reference Include="HtmlSanitizer, Version=9.0.0.0, Culture=neutral, PublicKeyToken=61c49a1a9e79cc28, processorArchitecture=MSIL">
111+
<HintPath>..\..\packages\HtmlSanitizer.9.1.878-beta\lib\net461\HtmlSanitizer.dll</HintPath>
112+
</Reference>
104113
<Reference Include="ICSharpCode.SharpZipLib, Version=1.4.2.13, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
105114
<HintPath>..\..\packages\SharpZipLib.1.4.2\lib\netstandard2.0\ICSharpCode.SharpZipLib.dll</HintPath>
106115
</Reference>
@@ -151,6 +160,9 @@
151160
<Reference Include="System.Buffers, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
152161
<HintPath>..\..\packages\System.Buffers.4.6.0\lib\net462\System.Buffers.dll</HintPath>
153162
</Reference>
163+
<Reference Include="System.Collections.Immutable, Version=9.0.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
164+
<HintPath>..\..\packages\System.Collections.Immutable.9.0.2\lib\net462\System.Collections.Immutable.dll</HintPath>
165+
</Reference>
154166
<Reference Include="System.ComponentModel.Composition" />
155167
<Reference Include="System.ComponentModel.DataAnnotations" />
156168
<Reference Include="System.configuration" />
@@ -178,6 +190,9 @@
178190
<Reference Include="System.Runtime.Serialization" />
179191
<Reference Include="System.Security" />
180192
<Reference Include="System.ServiceModel.Web" />
193+
<Reference Include="System.Text.Encoding.CodePages, Version=9.0.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
194+
<HintPath>..\..\packages\System.Text.Encoding.CodePages.9.0.2\lib\net462\System.Text.Encoding.CodePages.dll</HintPath>
195+
</Reference>
181196
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
182197
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
183198
</Reference>

DNN Platform/Library/Entities/Portals/PortalSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,12 @@ public bool DisablePrivateMessage
514514
/// <inheritdoc />
515515
public bool InlineEditorEnabled { get; internal set; }
516516

517+
/// <summary>Gets a value indicating whether JavaScript is allowed in module headers.</summary>
518+
public bool AllowJsInModuleHeaders { get; internal set; }
519+
520+
/// <summary>Gets a value indicating whether JavaScript is allowed in module footer.</summary>
521+
public bool AllowJsInModuleFooters { get; internal set; }
522+
517523
/// <inheritdoc />
518524
public bool SearchIncludeCommon { get; internal set; }
519525

0 commit comments

Comments
 (0)