@@ -22,7 +22,7 @@ npm install mdast-util-heading-range
2222
2323Say we have the following file, ` example.md ` :
2424
25- ``` md
25+ ``` markdown
2626# Foo
2727
2828Bar.
@@ -63,7 +63,7 @@ function plugin() {
6363
6464Now, running ` node example ` yields:
6565
66- ``` md
66+ ``` markdown
6767# Foo
6868
6969Qux.
@@ -129,6 +129,33 @@ Extra info (`Object`):
129129* ` start ` (` number ` ) — Index of ` start ` in ` parent `
130130* ` end ` (` number? ` ) — Index of ` end ` in ` parent `
131131
132+ ## Security
133+
134+ Improper use of the ` onrun ` can open you up to a
135+ [ cross-site scripting (XSS)] [ xss ] attack as the value returned from it is
136+ injected into the syntax tree.
137+ This can become a problem if the tree is later transformed to [ ** hast** ] [ hast ] .
138+ The following example shows how a script is injected that could run when loaded
139+ in a browser.
140+
141+ ``` js
142+ function onrun (start , nodes , end ) {
143+ return [start, {type: ' html' , value: ' alert(1)' }, end]
144+ }
145+ ```
146+
147+ Yields:
148+
149+ ``` markdown
150+ # Foo
151+
152+ <script>alert(1)</script>
153+
154+ # Baz
155+ ```
156+
157+ Either do not use user input in ` onrun ` or use [ ` hast-util-santize ` ] [ sanitize ] .
158+
132159## Contribute
133160
134161See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
@@ -192,3 +219,9 @@ abide by its terms.
192219[ heading ] : https://github.com/syntax-tree/mdast#heading
193220
194221[ test ] : #function-testvalue-node
222+
223+ [ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
224+
225+ [ hast ] : https://github.com/syntax-tree/hast
226+
227+ [ sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
0 commit comments