|
2 | 2 |
|
3 | 3 | # Security |
4 | 4 |
|
5 | | -Many people don't understand that markdown format does not care much about security. |
6 | | -In many cases you have to pass output to sanitizers. |
7 | | -`markdown-it` provides 2 possible strategies to produce safe output: |
| 5 | +By default, the `MarkdownIt` parser is initialised to comply with the [CommonMark spec](https://spec.commonmark.org/), which allows for parsing arbitrary HTML tags. |
| 6 | +This can be useful for many use cases, for example when writing articles for one's own blog or composing technical documentation for a software package. |
8 | 7 |
|
9 | | -1. Don't enable HTML. Extend markup features with [plugins](md/plugins). |
10 | | - We think it's the best choice and use it by default. |
11 | | - - That's ok for 99% of user needs. |
12 | | - - Output will be safe without sanitizer. |
13 | | -2. Enable HTML and use external sanitizer package(s). |
| 8 | +However, extra precautions are needed when parsing content from untrusted sources. |
| 9 | +Generally, the output should be run through sanitizers to ensure safety and prevent vulnerabilities like cross-site scripting (XSS). |
| 10 | +With `markdown-it`/`markdown-it-py`, there are two strategies for doing this: |
14 | 11 |
|
15 | | -Also by default `markdown-it` prohibits some kind of links, which could be used |
16 | | -for XSS: |
| 12 | +1. Enable HTML (as is needed for full CommonMark compliance), and then use external sanitizer package(s). |
| 13 | +2. Disable HTML, and then use [plugins](md/plugins) to selectively enable markup features. |
| 14 | + This removes the need for further sanitizing. |
| 15 | + |
| 16 | +```{warning} |
| 17 | +Unlike the original `markdown-it` JavaScript project, which uses the second, safe-by-default strategy, `markdown-it-py` enables the more convenient, but less secure, CommonMark-compliant settings by default. |
| 18 | +
|
| 19 | +This is not safe when using `markdown-it-py` in web applications that parse user-submitted content. |
| 20 | +In such cases, [using the `js-default` preset](using.md) is strongly recommended. |
| 21 | +For example: |
| 22 | +
|
| 23 | +```python |
| 24 | +from markdown_it import MarkdownIt |
| 25 | +MarkdownIt("js-default").render("*user-submitted* text") |
| 26 | +``` |
| 27 | + |
| 28 | +Note that even with the default configuration, `markdown-it-py` prohibits some kind of links which could be used for XSS: |
17 | 29 |
|
18 | 30 | - `javascript:`, `vbscript:` |
19 | 31 | - `file:` |
20 | | -- `data:`, except some images (gif/png/jpeg/webp). |
21 | | - |
22 | | -So, by default `markdown-it` should be safe. We care about it. |
| 32 | +- `data:` (except some images: gif/png/jpeg/webp) |
23 | 33 |
|
24 | | -If you find a security problem - contact us via <executablebooks@gmail.com>. |
25 | | -Such reports are fixed with top priority. |
| 34 | +If you find a security problem, please report it to <executablebooks@gmail.com>. |
26 | 35 |
|
27 | 36 | ## Plugins |
28 | 37 |
|
|
0 commit comments