-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Safe Mode #161
Comments
Also, protected function identifyLink($excerpt)
{
...
$url = $Link['url'];//str_replace(array('&', '<'), array('&', '<'), $Link['url']);
... Should take into consideration safe_mode, and ignore this replacement. |
@clphillips Do you actually want Parsedown to have HTML-free mode? |
@hkdobrev Yes. HTML-free in terms of not allowing HTML content from untrusted users. In many cases the only HTML I want is what is produced by markdown flavored plain-text. I'm actually hard pressed to find a single situation where I would actually want HTML content intermingled in my markdown text. |
This is an absolute requirement to use this library as renderer for user-entered content. |
you should use something like HTML purifier to extract all elements you do not want from the produced markdown. |
@cebe Uh, no we shouldn't. HTML purifier is extremely slow, and is a ridiculous solution for something that can be solved with 5 lines of code in this library. |
@cebe there is absolutely no need to parse a huge DOM tree with a very complex library, when a simple text search & replace is sufficient. This is just waisting resources (and PHP is not exactly the fastest language available, so...). Maybe we should also include securing link destinations:
|
I agree that it might make sense for Parsedown to do some sanitisation. It doesn't have to, but since it already knows so much about the texts it parses, it might not be too hard. |
Just for reference, other popular markdown libraries (for other languages) also support a "safe mode". See Python-Markdown and MarkdownDeep, for example. Will try to update this issue with a pull request with the changes I've made when I get a chance. |
@clphillips Thanks. I'll check them out. |
I agree that the markdown parser can do it more easily. |
Just adding fuel to the fire. Hoping to use Parsedown, but this is a blocker for me. I would also like to avoid using HTML Purifier for performance and licensing reasons. Happy to lend a hand. |
👍 Would also like to see safe mode. |
Anyone started on this or are we looking for volunteers?
|
I'm working on it. |
Awesome! 👍
|
I'm still waiting for this to be implemented before I can deploy parsedown on my website. Is there any progress? |
Could we come up with a simple specification? |
Either have a whitelist of allowed elements (like ) and escape other elements, or just escape all html tags. |
@xPaw This alone would not make the output safe. It's more complicated than that. What would we do with things like There's a related discussion at http://security.stackexchange.com/questions/14664/how-do-i-use-markdown-securely. |
Indeed urls have to be escaped as well. (shouldn't this already be done regardless of safe mode?) |
I suggest to have several setters for disabling certain functionality. One of them would disable usage of HTML in the Markdown. Another could be about XSS. Then we could have a setter for safe-mode which will set several of those setters. I am suggesting this approach, because some would want HTML-free mode without messing with parsing of URLs or images. |
Good to hear a safe mode is in the works. I am currently using Michel Fortin's Markdown parser and have done the following to prevent XSS: Disable HTML tags and entities, which escapes meta characters Edit: Updated link |
[xss](http://"onmouseover="alert(1)) This vector can pop a alert box in firefox! |
For several years I used Textile https://github.com/textile/php-textile and there is textileRestricted method which is suitable for untrusted input. As I understand there is no such thing in this library? |
Would someone like to create a simple set of test data that includes |
@erusev You want that as a PR, or what? Examples here: XSS Filter Evasion Cheat Sheet. |
@clphillips Sure, but let's start simple. We could start with 5 to 10 pairs to see if this test driven approach would work. |
Perhaps, we could start with something like: https://github.com/markdown-it/markdown-it/blob/019bbda5f5ee8b7d00f2633340aef3b0d000e3f1/test/fixtures/markdown-it/xss.txt |
Hi, any ETA on this? I need markdown in my latest project. I was thinking of using parsedown but it will be for user generated content. |
I'm interested too. Any news for the safe mode ? |
I've been thinking about this and I do plan to start implementing it, hopefully, in January. |
any update on this? |
Not yet, but perhaps soon. |
Great, looking forward. |
Is there any word on this right now? |
Updates? |
Not yet, it's taking me some time :( |
Well, for me worked perfectly by using the setMarkupEscaped option to true: $markdown = "The markdown of the following image ... ";
$Parsedown = new Parsedown();
$Parsedown->setMarkupEscaped(true);
echo $Parsedown->text($markdown); For example, the following markdown: Would display in the browser the second alert if the Maybe it was so simple and is not what everybody needs ... but it worked for me and maybe for someone else is useful too. |
Hi @sdkcarlos, Apologies for being blunt here, I'd just like to make sure that no one gets the wrong impression.
This is not the case. Parsedown is not safe with only Parsedown is still vulnerable to XSS attacks other than those introduced by inputting plain HTML tags, because Parsedown does not at present correctly encode data in attributes, nor does it sanitise link destinations (thus allowing use of the I'd highly encourage you to take a look at #495 if you would like a version of Parsedown that is designed to be safe from XSS. |
Thanks for the suggestion @aidantwoods , i've just updated my {
"require": {
"erusev/parsedown": "dev-master#bbb7687f31d6904f3a0e11e97bc61852a62cfe90",
}
} now i'm able to use |
Maybe use the following so that your composer will prefer the next stable Parsedown (once it is available) "require": {
"erusev/parsedown": "^1.7.0 || dev-master#bbb7687f31d6904f3a0e11e97bc61852a62cfe90",
} (Assuming that the minor version would deserve a bump when this new feature is merged, @erusev |
Hi @sdkcarlos, I've implemented the anti-xss patch as a Parsedown extension, so you can now instead require Hopefully we'll see it in Parsedown core at some point though :) |
Parsedown offers no safe option for rendering, so, for those of us who allow no HTML content within markdown text, we must sanitize prior to feeding to Parsedown. As a result, Parsedown double encodes HTML entities (see #50).
Instead, Parsedown should offer a "safe" option.
Usage:
Output:
The text was updated successfully, but these errors were encountered: