Advice about sanitizing markdown #554
Replies: 5 comments
-
The resulting HTML doesn't carry XSS potential does it? |
Beta Was this translation helpful? Give feedback.
-
I checked it and it is now treated as a relative link. So no more XSS in the resulting HTML. |
Beta Was this translation helpful? Give feedback.
-
HtmlSanitizer doesn't check for XSS per se, so there is no way of detecting if the input contains XSS. I think your approach seems legitimate for the use case you have described. As far I have understood your use case, it's not only about XSS but also about letting the user know that some of the markup they have used would be removed, letting them revise their input. |
Beta Was this translation helpful? Give feedback.
-
Yes, that is exactly my usecase. I want to inform the user, if the markdown text they provided, contains any potential malicious stuff, so they cannot save this markdown. But i did a small analysis how e.g. Github is doing that like in this comment functioniality. They are sending the markdown to the backend and are rendering and sanitizing it in the backend too. So i will do the same and do that in the backend. |
Beta Was this translation helpful? Give feedback.
-
I have implemented the rendering of markdown now in the backend. I use markdig and now i just send the rendered html back to the frontend. So this is working fine now, and the above vulnerability is solved 😄 |
Beta Was this translation helpful? Give feedback.
-
I have following situation. I have developed a application with the possibility to add and save a markdown text.
To prevent XSS, the following process happens:
As a hint: The markdown text is saved if it is valid, NOT the html. It is then loaded from the backend by potentially other users and then converted in the frontend to html. <-- potentially risk of XSS
Now let's assume we have following markdown text:
I have manually encoded the href part as Unicode Hex Character Code to simulate a XSS attack:
which is converted in the backend to this by the markdig library and this is then used to sanitized by the HtmlSanitizer:
The problem is, that now the HtmlSanitizer does not sanitize the html.
My code is as follow:
Maybe I am missing something. Can anyone give me a hint about this kind of problem?
Beta Was this translation helpful? Give feedback.
All reactions