-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📚 DOCS: Clarify docs regarding security configuration (#296)
Co-authored-by: Chris Sewell <[email protected]>
- Loading branch information
1 parent
14cca38
commit 3613e80
Showing
3 changed files
with
26 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,27 +2,36 @@ | |
|
||
# Security | ||
|
||
Many people don't understand that markdown format does not care much about security. | ||
In many cases you have to pass output to sanitizers. | ||
`markdown-it` provides 2 possible strategies to produce safe output: | ||
By default, the `MarkdownIt` parser is initialised to comply with the [CommonMark spec](https://spec.commonmark.org/), which allows for parsing arbitrary HTML tags. | ||
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. | ||
|
||
1. Don't enable HTML. Extend markup features with [plugins](md/plugins). | ||
We think it's the best choice and use it by default. | ||
- That's ok for 99% of user needs. | ||
- Output will be safe without sanitizer. | ||
2. Enable HTML and use external sanitizer package(s). | ||
However, extra precautions are needed when parsing content from untrusted sources. | ||
Generally, the output should be run through sanitizers to ensure safety and prevent vulnerabilities like cross-site scripting (XSS). | ||
With `markdown-it`/`markdown-it-py`, there are two strategies for doing this: | ||
|
||
Also by default `markdown-it` prohibits some kind of links, which could be used | ||
for XSS: | ||
1. Enable HTML (as is needed for full CommonMark compliance), and then use external sanitizer package(s). | ||
2. Disable HTML, and then use [plugins](md/plugins) to selectively enable markup features. | ||
This removes the need for further sanitizing. | ||
|
||
```{warning} | ||
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. | ||
This is not safe when using `markdown-it-py` in web applications that parse user-submitted content. | ||
In such cases, [using the `js-default` preset](using.md) is strongly recommended. | ||
For example: | ||
```python | ||
from markdown_it import MarkdownIt | ||
MarkdownIt("js-default").render("*user-submitted* text") | ||
``` | ||
|
||
Note that even with the default configuration, `markdown-it-py` prohibits some kind of links which could be used for XSS: | ||
|
||
- `javascript:`, `vbscript:` | ||
- `file:` | ||
- `data:`, except some images (gif/png/jpeg/webp). | ||
|
||
So, by default `markdown-it` should be safe. We care about it. | ||
- `data:` (except some images: gif/png/jpeg/webp) | ||
|
||
If you find a security problem - contact us via <[email protected]>. | ||
Such reports are fixed with top priority. | ||
If you find a security problem, please report it to <[email protected]>. | ||
|
||
## Plugins | ||
|
||
|