Skip to content

Commit 550e9b7

Browse files
authored
Merge pull request #9 from spassarop/develop
Changes for v1.0.4
2 parents 3185480 + 3a1eb0b commit 550e9b7

File tree

16 files changed

+178
-90
lines changed

16 files changed

+178
-90
lines changed

OWASP.AntiSamy/AntiSamyPolicyExamples/antisamy-anythinggoes.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ http://www.w3.org/TR/html401/struct/global.html
99
xsi:noNamespaceSchemaLocation="antisamy.xsd">
1010

1111
<directives>
12-
<directive name="omitXmlDeclaration" value="true"/>
1312
<directive name="omitDoctypeDeclaration" value="true"/>
1413
<directive name="maxInputSize" value="200000"/>
15-
<directive name="useXHTML" value="true"/>
1614
<directive name="formatOutput" value="true"/>
1715

1816
<!--

OWASP.AntiSamy/AntiSamyPolicyExamples/antisamy-ebay.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ http://www.w3.org/TR/html401/struct/global.html
99
xsi:noNamespaceSchemaLocation="antisamy.xsd">
1010

1111
<directives>
12-
<directive name="omitXmlDeclaration" value="true"/>
1312
<directive name="omitDoctypeDeclaration" value="true"/>
1413
<directive name="maxInputSize" value="20000"/>
15-
<directive name="useXHTML" value="true"/>
1614
<directive name="formatOutput" value="true"/>
1715

1816
<!--

OWASP.AntiSamy/AntiSamyPolicyExamples/antisamy-myspace.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ http://www.w3.org/TR/html401/struct/global.html
99
xsi:noNamespaceSchemaLocation="antisamy.xsd">
1010

1111
<directives>
12-
<directive name="omitXmlDeclaration" value="true"/>
1312
<directive name="omitDoctypeDeclaration" value="true"/>
1413
<directive name="maxInputSize" value="15000"/>
15-
<directive name="useXHTML" value="true"/>
1614
<directive name="formatOutput" value="true"/>
1715

1816
<!--

OWASP.AntiSamy/AntiSamyPolicyExamples/antisamy-slashdot.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ Slashdot allowed tags taken from "Reply" page:
1414
xsi:noNamespaceSchemaLocation="antisamy.xsd">
1515

1616
<directives>
17-
<directive name="omitXmlDeclaration" value="true"/>
1817
<directive name="omitDoctypeDeclaration" value="true"/>
1918
<directive name="maxInputSize" value="5000"/>
20-
<directive name="useXHTML" value="true"/>
2119
<directive name="formatOutput" value="true"/>
2220

2321
<directive name="embedStyleSheets" value="false"/>

OWASP.AntiSamy/AntiSamyPolicyExamples/antisamy-tinymce.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
xsi:noNamespaceSchemaLocation="antisamy.xsd">
99

1010
<directives>
11-
<directive name="omitXmlDeclaration" value="true" />
1211
<directive name="omitDoctypeDeclaration" value="false" />
1312
<directive name="maxInputSize" value="100000" />
1413
<directive name="embedStyleSheets" value="false" />
15-
<directive name="useXHTML" value="true" />
1614
<directive name="formatOutput" value="true" />
1715
</directives>
1816

OWASP.AntiSamy/AntiSamyPolicyExamples/antisamy.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ http://www.w3.org/TR/html401/struct/global.html
1111
<directive name="omitXmlDeclaration" value="true"/>
1212
<directive name="omitDoctypeDeclaration" value="true"/>
1313
<directive name="maxInputSize" value="200000"/>
14-
<directive name="useXHTML" value="true"/>
1514
<directive name="formatOutput" value="true"/>
1615
<directive name="nofollowAnchors" value="true" />
1716
<directive name="validateParamAsEmbed" value="true" />

OWASP.AntiSamy/Css/CssScanner.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ public CssScanner(Policy policy)
9494
IBrowsingContext browsingContext = BrowsingContext.New(Configuration.Default
9595
.WithCss()
9696
.With(new DefaultHttpRequester(userAgent: null, setup: SetupHttpRequest))
97-
.WithDefaultLoader(new LoaderOptions { IsResourceLoadingEnabled = true }));
97+
.WithDefaultLoader(new LoaderOptions {
98+
IsResourceLoadingEnabled = policy.EmbedsStyleSheets,
99+
IsNavigationDisabled = true
100+
}));
98101
parser = new CssParser(cssParserOptions, browsingContext);
99102
}
100103

@@ -188,9 +191,9 @@ private CleanResults DoScan(string taintedCss, bool isInlineCss, string tagName)
188191
}
189192
}
190193

191-
if (isCData && !policy.UsesXhtml)
194+
if (isCData)
192195
{
193-
cleanStylesheet = $"<![CDATA[[{cleanStylesheet}]]>";
196+
cleanStylesheet = $"<![CDATA[{cleanStylesheet}]]>";
194197
}
195198

196199
return new CleanResults(startOfScan, new DateTime(), cleanStylesheet, ErrorMessages);
@@ -461,6 +464,7 @@ private string GetPropertyErrorMessage(string propertyName, string propertyValue
461464
private void SetupHttpRequest(HttpWebRequest httpWebRequest)
462465
{
463466
httpWebRequest.Timeout = policy.ConnectionTimeout;
467+
httpWebRequest.AllowAutoRedirect = false;
464468
}
465469

466470
private void AddError(string errorKey, params object[] arguments)

OWASP.AntiSamy/Html/InternalPolicy.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using System.Collections.Generic;
2626
using OWASP.AntiSamy.Html.Scan;
2727
using Tag = OWASP.AntiSamy.Html.Model.Tag;
28+
using Property = OWASP.AntiSamy.Html.Model.Property;
2829

2930
namespace OWASP.AntiSamy.Html
3031
{
@@ -40,8 +41,8 @@ public InternalPolicy(ParseContext parseContext) : base(parseContext)
4041
SetProperties();
4142
}
4243

43-
public InternalPolicy(Policy old, Dictionary<string, string> directives, Dictionary<string, Tag> tagRules)
44-
: base(old, directives, tagRules)
44+
public InternalPolicy(Policy old, Dictionary<string, string> directives, Dictionary<string, Tag> tagRules, Dictionary<string, Property> cssRules)
45+
: base(old, directives, tagRules, cssRules)
4546
{
4647
SetProperties();
4748
}
@@ -54,10 +55,8 @@ private void SetProperties()
5455
ValidatesParamAsEmbed = IsTrue(Constants.VALIDATE_PARAM_AS_EMBED);
5556
FormatsOutput = IsTrue(Constants.FORMAT_OUTPUT);
5657
PreservesSpace = IsTrue(Constants.PRESERVE_SPACE);
57-
OmitsXmlDeclaration = IsTrue(Constants.OMIT_XML_DECLARATION);
5858
OmitsDoctypeDeclaration = IsTrue(Constants.OMIT_DOCTYPE_DECLARATION);
5959
EntityEncodesInternationalCharacters = IsTrue(Constants.ENTITY_ENCODE_INERNATIONAL_CHARS);
60-
UsesXhtml = IsTrue(Constants.USE_XHTML);
6160
string onUnknownTagActionValue = GetDirectiveByName(Constants.ON_UNKNOWN_TAG_ACTION);
6261
OnUnknownTagAction = string.IsNullOrEmpty(onUnknownTagActionValue) ? string.Empty : onUnknownTagActionValue.ToLowerInvariant();
6362
PreservesComments = IsTrue(Constants.PRESERVE_COMMENTS);

OWASP.AntiSamy/Html/Model/Property.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace OWASP.AntiSamy.Html.Model
2929
/// <summary> A model for CSS properties and the "rules" they must follow (either literals
3030
/// or regular expressions) in order to be considered valid.</summary>
3131
// Author: Jason Li
32-
internal class Property
32+
public class Property
3333
{
3434
public List<string> AllowedRegExp { get; set; } = new List<string>();
3535
public List<string> AllowedValues { get; set; } = new List<string>();
@@ -38,7 +38,7 @@ internal class Property
3838
public string OnInvalid { get; set; }
3939
public string Description { get; set; }
4040

41-
public Property(string name) => this.Name = name;
41+
public Property(string name) => Name = name;
4242

4343
/// <summary> Add the specified value to the allowed list of valid values.</summary>
4444
/// <param name="safeValue">The new valid value to add to the list.</param>

OWASP.AntiSamy/Html/ParseContext.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ public class ParseContext
4040
internal Dictionary<string, Attribute> globalAttributes = new Dictionary<string, Attribute>();
4141
internal Dictionary<string, Attribute> dynamicAttributes = new Dictionary<string, Attribute>();
4242
internal List<string> allowedEmptyTags = new List<string>();
43-
internal List<string> requireClosingTags = new List<string>();
4443

4544
internal void ResetParametersWhereLastConfigurationWins()
4645
{
4746
allowedEmptyTags.Clear();
48-
requireClosingTags.Clear();
4947
}
5048
}
5149
}

0 commit comments

Comments
 (0)