You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a XSS-prevention recommendation.
If escaped code is only ever used inside a quoted attribute or as element text,
escapeing '/' is not necessary.
However, if the escaped code is inserted inside a tag (for example assuming
that it is a well-behavde attribute), then a slash may be meaningful in some
cases. Lots of other things can go wrong in that case, so we recommend against
it.
[email protected]
Review URL: https://codereview.chromium.org//1084473003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@45153 260f80e4-7a28-3924-810f-c04153c831b5
Copy file name to clipboardExpand all lines: sdk/lib/convert/html_escape.dart
+42-9
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,26 @@
4
4
5
5
part of dart.convert;
6
6
7
-
// TODO(floitsch) - Document - Issue 13097
7
+
/**
8
+
* A `String` converter that converts characters to HTML entities.
9
+
*
10
+
* This is intended to sanitice text before inserting the text into an HTML
11
+
* document. Characters that are meaningful in HTML are converted to
12
+
* HTML entities (like `&` for `&`).
13
+
*
14
+
* The general converter escapes all characters that are meaningful in HTML
15
+
* attributes or normal element context. Elements with special content types
16
+
* (like CSS or JavaScript) may need a more specialized escaping that
17
+
* understands that content type.
18
+
*
19
+
* If the context where the text will be inserted is known in more detail,
20
+
* it's possible to omit escaping some characters (like quotes when not
21
+
* inside an attribute value).
22
+
*
23
+
* The escaped text should only be used inside quoted HTML attributes values
24
+
* or as text content of a normal element. Using the escaped text inside a
25
+
* tag, but not inside a quoted attribute value, is still dangerous.
26
+
*/
8
27
constHtmlEscapeHTML_ESCAPE=constHtmlEscape();
9
28
10
29
/**
@@ -28,6 +47,13 @@ class HtmlEscapeMode {
28
47
finalbool escapeQuot;
29
48
/** Whether to escape "'" (apostrophe). */
30
49
finalbool escapeApos;
50
+
/**
51
+
* Whether to escape "/" (forward slash, solidus).
52
+
*
53
+
* Escaping a slash is recommended to avoid cross-site scripting attacks by
54
+
* [the Open Web Application Security Project](https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content)
55
+
*/
56
+
finalbool escapeSlash;
31
57
32
58
/**
33
59
* Default escaping mode which escape all characters.
@@ -40,7 +66,7 @@ class HtmlEscapeMode {
40
66
* which require escapes matching their particular content syntax.
0 commit comments