@@ -22,7 +22,7 @@ npm install mdast-util-heading-range
22
22
23
23
Say we have the following file, ` example.md ` :
24
24
25
- ``` md
25
+ ``` markdown
26
26
# Foo
27
27
28
28
Bar.
@@ -63,7 +63,7 @@ function plugin() {
63
63
64
64
Now, running ` node example ` yields:
65
65
66
- ``` md
66
+ ``` markdown
67
67
# Foo
68
68
69
69
Qux.
@@ -129,6 +129,33 @@ Extra info (`Object`):
129
129
* ` start ` (` number ` ) — Index of ` start ` in ` parent `
130
130
* ` end ` (` number? ` ) — Index of ` end ` in ` parent `
131
131
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
+
132
159
## Contribute
133
160
134
161
See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
@@ -192,3 +219,9 @@ abide by its terms.
192
219
[ heading ] : https://github.com/syntax-tree/mdast#heading
193
220
194
221
[ 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