Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-2147] Replace deprecated method with a sanitize library #374

Open
matthieucan opened this issue Feb 20, 2023 · 9 comments
Open

[CT-2147] Replace deprecated method with a sanitize library #374

matthieucan opened this issue Feb 20, 2023 · 9 comments
Labels
enhancement New feature or request help_wanted Trickier changes, with a clear starting point, good for previous/experienced contributors triage

Comments

@matthieucan
Copy link

matthieucan commented Feb 20, 2023

Describe the feature

Currently, doc blocks are sanitized from custom html elements. This prevents going beyond markdown styling for documentation, and tinkering with features such as mermaid.js.

I understand this is enabled for security reasons, but:

Describe alternatives you've considered

I'm not aware of any alternative.

Additional context

N/A

Who will this benefit?

Users who want to

  • Apply any custom styling
  • Create html elements with class (no pun intended) to be rendered by mermaid.js.
  • Extend the catalog with all the possibilities offered by html and javascript.

Are you interested in contributing this feature?

Yes.

@matthieucan matthieucan added enhancement New feature or request triage labels Feb 20, 2023
@github-actions github-actions bot changed the title Do not sanitize html elements in markdown files [CT-2147] Do not sanitize html elements in markdown files Feb 20, 2023
@dbeatty10
Copy link
Contributor

Thanks for reaching out @matthieucan !

Even though markedProvider.setOptions({sanitize: true}); has been deprecated, I think we'd still want to replace it with something similar rather than just remove it altogether.

Those docs suggest the following:

Instead use a sanitize library, like DOMPurify (recommended), sanitize-html or insane on the output HTML.

A question I don't know the answer to: would any of these sanitize libraries be compatible with mermaid.js?

I'm not sure if there are other relevant alternatives to DOMPurify, sanitize-html, or insane 🤷.

I'm going to label the effort to replace the sanitization approach as help_wanted, if you or anyone wants to tackle it! I'll also update the issue title accordingly.

@dbeatty10 dbeatty10 added help_wanted Trickier changes, with a clear starting point, good for previous/experienced contributors and removed triage labels Feb 20, 2023
@dbeatty10 dbeatty10 changed the title [CT-2147] Do not sanitize html elements in markdown files [CT-2147] Replace deprecated method with a sanitize library Feb 20, 2023
@matthieucan
Copy link
Author

Thanks for your fast answer @dbeatty10!

I'm not sure sanitizing html elements in markdown would be compatible with the use of external libraries. The idea I had was, if I can inject <pre class="mermaid">some graph</pre> within a docs block, then I can use mermaid.js to render the graph.
But if all html elements are stripped, it won't work, unless we have a way to "mark" specific elements to be rendered.

Could you expand on the reasons why markdown is sanitized? Is it to prevent Javascript injections?
In my understanding, a user who has write access to the docs block would also have write access to the index.html, so if they wanted to inject Javascript they would be able to. But perhaps I don't get the full picture here!

@dbeatty10
Copy link
Contributor

@matthieucan thanks for explaining the push/pull here between stripping HTML elements and marking a specific chunk of markdown to be rendered by mermaid.js.

I don't actually know the full story of why the markdown is sanitized. It was added in one-line PR here about 1 year ago.

@iknox-fa is there any background you can share about why sanitize: true was added? And which alternatives might be possible to replace its intent with some other mechanism?

@dbeatty10
Copy link
Contributor

@matthieucan I connected with some folks internally to learn more. The summary is that we just don't allow arbitrary HTML/JS anymore because it's not a security best practice.

So at this point, we definitely want to keep the sanitization in. As you noted earlier, the current method is deprecated, so it would be best to replace it with one of the alternatives mentioned above.

I'm not sure if there's still some way to do Mermaid parsing or not, but we need to leave in a sanitization step.

@matthieucan
Copy link
Author

@dbeatty10 Thanks for getting back to me!

In the meantime I experimented with using

```mermaid
some graph
```

Which renders into <pre class="language-mermaid">.... That's pretty neat, and I had not tried this earlier. I think that would allow to hook mermaid into a page!

It's unfortunate we can't inject different html nodes into markdown, for other unrelated experiments or styling, but I certainly understand the security concerns there. Perhaps an option to allow it, which would not be the default?

@dbeatty10
Copy link
Contributor

That's awesome news @matthieucan !

For proof-of-concepts (POCs), you could definitely fork this repo and take out the sanitization so you can do unrelated experiments or styling. But we couldn't merge those in without the sanitization.

@matthieucan
Copy link
Author

Gotcha, thanks! :)

Copy link
Contributor

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

@github-actions github-actions bot added the Stale label Feb 17, 2024
@matthieucan
Copy link
Author

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

Still valid

@github-actions github-actions bot added triage and removed Stale labels Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help_wanted Trickier changes, with a clear starting point, good for previous/experienced contributors triage
Projects
None yet
Development

No branches or pull requests

2 participants