File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,32 @@ and the last `end`, and the content inside.
101
101
[ ` Array.<Node>? ` ] [ node ] — List of nodes to replace ` start ` , ` nodes ` , and ` end `
102
102
with, optional.
103
103
104
+ ## Security
105
+
106
+ Improper use of ` handler ` can open you up to a [ cross-site scripting (XSS)] [ xss ]
107
+ attack as the value it returns is injected into the syntax tree.
108
+ This can become a problem if the tree is later transformed to [ ** hast** ] [ hast ] .
109
+ The following example shows how a script is injected that could run when loaded
110
+ in a browser.
111
+
112
+ ``` js
113
+ function handler (start , nodes , end ) {
114
+ return [start, {type: ' html' , value: ' alert(1)' }, end]
115
+ }
116
+ ```
117
+
118
+ Yields:
119
+
120
+ ``` markdown
121
+ <!--foo start-->
122
+
123
+ <script>alert(1)</script>
124
+
125
+ <!--foo end-->
126
+ ```
127
+
128
+ Either do not use user input or use [ ` hast-util-santize ` ] [ sanitize ] .
129
+
104
130
## Contribute
105
131
106
132
See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
@@ -166,3 +192,9 @@ abide by its terms.
166
192
[ tree ] : https://github.com/syntax-tree/unist#tree
167
193
168
194
[ html ] : https://github.com/syntax-tree/mdast#html
195
+
196
+ [ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
197
+
198
+ [ hast ] : https://github.com/syntax-tree/hast
199
+
200
+ [ sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
You can’t perform that action at this time.
0 commit comments