Skip to content

Commit

Permalink
Fix hex escape issue in style element
Browse files Browse the repository at this point in the history
  • Loading branch information
mganss committed Dec 23, 2020
1 parent 0963175 commit a3a7602
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/HtmlSanitizer/HtmlSanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ private void SanitizeStyleSheets(IHtmlDocument dom, string baseUrl)
else i++;
}

styleTag.InnerHtml = styleSheet.ToCss();
styleTag.InnerHtml = styleSheet.ToCss().Replace("<", "\\3c");
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/HtmlSanitizer.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3201,6 +3201,19 @@ public void PreParsedDocumentWithContextTest()

Assert.Equal("<html><head></head><body><div>hi</div></body></html>", returnedDocument.ToHtml());
}

[Fact]
public void StyleByPassTest()
{
var sanitizer = new HtmlSanitizer();

sanitizer.AllowedTags.Add("style");

var html = "aaabc<style>x[x='\\3c /style>\\3c img src onerror=alert(1)>']{}</style>";
var sanitized = sanitizer.Sanitize(html, "http://www.example.com");

Assert.Equal("aaabc<style>x[x=\"\\3c/style>\\3cimg src onerror=alert(1)>\"] { }</style>", sanitized);
}
}
}

Expand Down

0 comments on commit a3a7602

Please sign in to comment.