Skip to content

Commit 56c7083

Browse files
committed
Add notes on security
1 parent 6a92aa7 commit 56c7083

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

readme.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff 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`
102102
with, 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

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

0 commit comments

Comments
 (0)