@@ -109,7 +109,7 @@ Whether to compile list-items tightly (`boolean?`, default: `false`).
109109Add a prefix to links to headings in the table of contents (` string? ` ,
110110default: ` null ` ).
111111Useful for example when later going from [ mdast] [ ] to [ hast] [ ] and sanitizing
112- with [ ` hast-util-sanitize ` ] [ hast-util- sanitize] .
112+ with [ ` hast-util-sanitize ` ] [ sanitize ] .
113113
114114###### ` options.parents `
115115
@@ -144,6 +144,39 @@ An object representing the table of contents.
144144 ` null ` if no table of contents could be created, either because
145145 no heading was found or because no following headings were found
146146
147+ ## Security
148+
149+ Use of ` mdast-util-toc ` does not involve [ ** hast** ] [ hast ] , user content, or
150+ change the tree, so there are no openings for [ cross-site scripting (XSS)] [ xss ]
151+ attacks.
152+
153+ Injecting ` map ` into the syntax tree may open you up to XSS attacks as existing
154+ nodes are copied into the table of contents.
155+ The following example shows how an existing script is copied into the table of
156+ contents.
157+
158+ For the following Markdown:
159+
160+ ``` markdown
161+ # Alpha
162+
163+ ## Bravo<script>alert(1)</script>
164+
165+ ## Charlie
166+ ```
167+
168+ Yields in ` map ` :
169+
170+ ``` markdown
171+ - [Alpha](#alpha)
172+
173+ - [Bravo<script>alert(1)</script>](#bravoscriptalert1script)
174+ - [Charlie](#charlie)
175+ ```
176+
177+ Always use [ ` hast-util-santize ` ] [ sanitize ] when transforming to
178+ [ ** hast** ] [ hast ] .
179+
147180## Contribute
148181
149182See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
@@ -202,7 +235,7 @@ abide by its terms.
202235
203236[ hast ] : https://github.com/syntax-tree/hast
204237
205- [ hast-util- sanitize] : https://github.com/syntax-tree/hast-util-sanitize
238+ [ sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
206239
207240[ is ] : https://github.com/syntax-tree/unist-util-is
208241
@@ -219,3 +252,5 @@ abide by its terms.
219252[ blockquote ] : https://github.com/syntax-tree/mdast#blockquote
220253
221254[ parents ] : #optionsparents
255+
256+ [ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
0 commit comments