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.
101101[ ` Array.<Node>? ` ] [ node ] — List of nodes to replace ` start ` , ` nodes ` , and ` end `
102102with, optional.
103103
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+
104130## Contribute
105131
106132See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
@@ -166,3 +192,9 @@ abide by its terms.
166192[ tree ] : https://github.com/syntax-tree/unist#tree
167193
168194[ 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