Best practices/recommendations on safe HTML exports
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 613
- Avg merge
- 2h 11m
- Merged PRs (30d)
- 1
Description
My motivation is that I have a project that will be accepting and displaying arbitrary user-uploaded Jupyter notebooks in HTML.
I've generally struggled to find information on what best practices are on how to safely render and display notebooks in HTML. It would be great if there was more thorough explanation in the nbconvert documentation about this topic.
I've seen that there is a `sanitize-html` / `should_sanitize_html` option when using the HTML exporter. My understanding from looking at the code is that cells are run through the [`clean_html`](https://github.com/jupyter/nbconvert/blob/50b86f8755fe45c5ad0473727fc102ce957e7c1b/nbconvert/filters/strings.py#L85-L102) filter. Some questions:
- How should I understand this filter's level of safety in a broader context?
- This doesn't appear customizable (in an obvious way—I guess some of these allow lists could be monkeypatched?). Should this _not_ be customized? From trying to use it, it seems like paragraph and header tags are not allowed, which seems to break fairly basic markdown formatting in notebooks.
- Are there other basic vulnerabilities to watch out for that using the sanitize option doesn't address?
One obvious model for rendering user-uploaded notebooks is GitHub. I understand that GitHub does some kind of cleaning or places restrictions on the rendering, but I haven't been able to find details or code about what that actually is. If that is described anywhere, it would also be a helpful thing to link to in the documentation.
([Associated topic](https://discourse.jupyter.org/t/best-practices-recommendations-on-safe-html-exports/20334) on the Jupyter Discourse)
Contributor guide
Research direction
Start with the HTML exporter’s sanitize-html/should_sanitize_html option and the clean_html filter in nbconvert/filters/strings.py. Review the linked Discourse topic and existing nbconvert documentation. Done means documenting the sanitizer’s scope, customization considerations, remaining risks, and any relevant GitHub rendering references.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation, security
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100