Skip to content

Commit 3d9543c

Browse files
committed
Add notes on security
1 parent 0200931 commit 3d9543c

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

readme.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ npm install mdast-util-heading-range
2222

2323
Say we have the following file, `example.md`:
2424

25-
```md
25+
```markdown
2626
# Foo
2727

2828
Bar.
@@ -63,7 +63,7 @@ function plugin() {
6363

6464
Now, running `node example` yields:
6565

66-
```md
66+
```markdown
6767
# Foo
6868

6969
Qux.
@@ -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

134161
See [`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

Comments
 (0)