Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

HtmlEditorExtender.Decode: fix removal of insecure HTML#532

Merged
AlekseyMartynov merged 6 commits into
DevExpress:masterfrom
AlekseyMartynov:fix/html-editor-decode
May 14, 2020
Merged

HtmlEditorExtender.Decode: fix removal of insecure HTML#532
AlekseyMartynov merged 6 commits into
DevExpress:masterfrom
AlekseyMartynov:fix/html-editor-decode

Conversation

@AlekseyMartynov
Copy link
Copy Markdown
Contributor

@AlekseyMartynov AlekseyMartynov commented Apr 21, 2020

In this PR, I'm rewriting the following part:

result = Regex.Replace(result, "[^<]<[^>]*expression[^>]*>", "", RegexOptions.IgnoreCase | RegexOptions.ECMAScript);
result = Regex.Replace(result, "[^<]<([^>]*)(data\\:[^>]*)>", m => {
var tagGroup = m.Groups[1].Value.ToLower();
var urlGroup = m.Groups[2].Value.ToLower();
if(tagGroup.StartsWith("img") && urlGroup.StartsWith("data:image/"))
return m.Value;
return "";
}, RegexOptions.IgnoreCase | RegexOptions.ECMAScript);
result = Regex.Replace(result, "[^<]<[^>]*script(?!\\w)[^>]*>", "", RegexOptions.IgnoreCase | RegexOptions.ECMAScript);
result = Regex.Replace(result, "[^<]<[^>]*filter[^>]*>", "", RegexOptions.IgnoreCase | RegexOptions.ECMAScript);
result = Regex.Replace(result, "[^<]<[^>]*behavior[^>]*>", "", RegexOptions.IgnoreCase | RegexOptions.ECMAScript);
result = Regex.Replace(result, "[^<]<[^>]*javascript\\:[^>]*>", "", RegexOptions.IgnoreCase | RegexOptions.ECMAScript);
result = Regex.Replace(result, "[^<]<[^>]*position\\:[^>]*>", "", RegexOptions.IgnoreCase | RegexOptions.ECMAScript);

Key points:

@AlekseyMartynov AlekseyMartynov merged commit 16661ab into DevExpress:master May 14, 2020
@AlekseyMartynov AlekseyMartynov deleted the fix/html-editor-decode branch May 14, 2020 11:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bugs in HTML Sanitization font-family: "Brush Script MT" in <style> tag breaks HTML markup

1 participant