@@ -109,7 +109,7 @@ Whether to compile list-items tightly (`boolean?`, default: `false`).
109
109
Add a prefix to links to headings in the table of contents (` string? ` ,
110
110
default: ` null ` ).
111
111
Useful 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 ] .
113
113
114
114
###### ` options.parents `
115
115
@@ -144,6 +144,39 @@ An object representing the table of contents.
144
144
` null ` if no table of contents could be created, either because
145
145
no heading was found or because no following headings were found
146
146
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
+
147
180
## Contribute
148
181
149
182
See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
@@ -202,7 +235,7 @@ abide by its terms.
202
235
203
236
[ hast ] : https://github.com/syntax-tree/hast
204
237
205
- [ hast-util- sanitize] : https://github.com/syntax-tree/hast-util-sanitize
238
+ [ sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
206
239
207
240
[ is ] : https://github.com/syntax-tree/unist-util-is
208
241
@@ -219,3 +252,5 @@ abide by its terms.
219
252
[ blockquote ] : https://github.com/syntax-tree/mdast#blockquote
220
253
221
254
[ parents ] : #optionsparents
255
+
256
+ [ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
0 commit comments