Skip to content

Commit 3613e80

Browse files
📚 DOCS: Clarify docs regarding security configuration (#296)
Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com>
1 parent 14cca38 commit 3613e80

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- Configurable syntax: you can add new rules and even replace existing ones.
1818
- Pluggable: Adds syntax extensions to extend the parser (see the [plugin list][md-plugins]).
1919
- High speed (see our [benchmarking tests][md-performance])
20-
- [Safe by default][md-security]
20+
- Easy to configure for [security][md-security]
2121
- Member of [Google's Assured Open Source Software](https://cloud.google.com/assured-open-source-software/docs/supported-packages)
2222

2323
This is a Python port of [markdown-it], and some of its associated plugins.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- {fa}`check,text-success mr-1` Configurable syntax: you can add new rules and even replace existing ones.
77
- {fa}`check,text-success mr-1` Pluggable: Adds syntax extensions to extend the parser (see the [plugin list](md/plugins))
88
- {fa}`check,text-success mr-1` High speed (see our [benchmarking tests](md/performance))
9-
- {fa}`check,text-success mr-1` [Safe by default](md/security)
9+
- {fa}`check,text-success mr-1` Easy to configure for [security](md/security)
1010
- {fa}`check,text-success mr-1` Member of [Google's Assured Open Source Software](https://cloud.google.com/assured-open-source-software/docs/supported-packages)
1111

1212
For a good introduction to [markdown-it] see the __[Live demo](https://markdown-it.github.io)__.

docs/security.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,36 @@
22

33
# Security
44

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.
87

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:
1411

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:
1729

1830
- `javascript:`, `vbscript:`
1931
- `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)
2333

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>.
2635

2736
## Plugins
2837

0 commit comments

Comments
 (0)