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

Escaped HTML in footnotes #118

Closed
AlfredoRamos opened this issue Mar 3, 2018 · 20 comments
Closed

Escaped HTML in footnotes #118

AlfredoRamos opened this issue Mar 3, 2018 · 20 comments

Comments

@AlfredoRamos
Copy link

Hi,

Since the latest change in parsedown (erusev/parsedown#495) footnotes are broken (reference AlfredoRamos/parsedown-extra-laravel/jobs/348703852), they display escaped HTML.

Parsedown: 1.6.4
Parsedown Extra: 0.7.1

<p>Parsedown Extra <sup id="fnref1:1"><a href="#fn:1" class="footnote-ref">1</a></sup></p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">
<p><a href="http://parsedown.org/extra/">http://parsedown.org/extra/</a>&#160;<a href="#fnref1:1" rev="footnote" class="footnote-backref">&#8617;</a></p>
</li>
</ol>
</div>

Parsedown: 1.7.0
Parsedown Extra: 0.7.1

<p>Parsedown Extra <sup id="fnref1:1"><a href="#fn:1" class="footnote-ref">1</a></sup></p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">
&lt;p&gt;&lt;a href="http://parsedown.org/extra/"&gt;http://parsedown.org/extra/&lt;/a&gt;&amp;#160;&lt;a href="#fnref1:1" rev="footnote" class="footnote-backref"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
</li>
</ol>
</div>

As you can see, the HTML inside the<li> tag is escaped.

My test script:

<?php

require __DIR__ . '/vendor/autoload.php';

$parsedown = new ParsedownExtra;
$parsedown->setSafeMode(false);
$parsedown->setMarkupEscaped(false);

echo $parsedown->text('Parsedown Extra [^1]'.PHP_EOL.'[^1]: http://parsedown.org/extra/');

I've tried to disable safe-mode but it doesn't seem to do anything.

My server runs PHP 7.2.3

AlfredoRamos pushed a commit to AlfredoRamos/parsedown-extra-laravel that referenced this issue Mar 3, 2018
@aidantwoods
Copy link
Collaborator

Thanks for reporting this – there's a little bit of discussion over at #117 (comment) if you're interested. Hopefully should have a fix out soon.

AlfredoRamos pushed a commit to AlfredoRamos/parsedown-extra-laravel that referenced this issue Mar 4, 2018
As reported in erusev/parsedown-extra#118 this breaking change will cause errors in the package. For now, a previous version will be used untill that issue is fixed.

This change will also prevent users to update to Laravel v5.6.7 or greater, as it requires Parsedown v1.7.0 or greater.
@jeremycherfas
Copy link

Hello. Any idea when we might expect a fix? Thanks.

@jeremycherfas
Copy link

Bump

@aidantwoods
Copy link
Collaborator

aidantwoods commented Mar 21, 2018

There are some first steps toward what will hopefully become a proper fix in erusev/parsedown#576. Once that is done Parsedown-extra will have access an AST of elements instead of just the final HTML string, so it'll be able to rewrite the parsed structure without directly having to act on an HTML string, and just shoving HTML into what is meant to be text bound within a single element (this is why footnotes are currently being escaped).

It would be possible get a patch out a bit sooner once the smaller erusev/parsedown#574 is finalised, since it'll allow basically keeping the current algorithm with a very minor adjustment.

However from a cursory look (as mentioned in #117 (comment)), I'm pretty sure Parsedown-extra has its own syntax introduced XSS vectors (even just looking within footnotes), so this type of fix wouldn't be suitable if you're dealing with any kind of untrusted user-input (it wouldn't be any worse than the current version is in that regard though – so just a heads up if that applies to anyone).
Does anyone's use case involve user-input?

Anyway, in order to benefit from the new safety features within Parsedown, Parsedown-Extra would need to use the method described above so that escaping can be done properly (and probably some other changes too).

@wottpal
Copy link

wottpal commented Apr 17, 2018

erusev/parsedown#576 and erusev/parsedown#574 seem to be merged. Let us know if we can provide any help for this @aidantwoods!

@wottpal
Copy link

wottpal commented May 30, 2018

Any updates on this?

@BenjaminHoegh
Copy link

BenjaminHoegh commented Jun 7, 2018

The issue is still there @wottpal You can use the pre-release 0.8.0 here is it fixed, but be aware that there are some bugs

@wottpal
Copy link

wottpal commented Jun 8, 2018

Nice to hear somebody took care of it. I’ll wait for the stable 🙃

@slowpokefarm
Copy link

Maybe it can be reverted at least? this issue broke our blogs on October CMS :/

@mnapoli
Copy link

mnapoli commented Jan 4, 2019

Is it possible to tag a stable release so that we can all use the bugfix?

Thanks :)

@adamgreenough
Copy link

Is there any update on this?

@BenjaminHoegh
Copy link

If you use a Definition Lists some where in your markdown it can broke the footnote, not sure why yet

@terrylinooo
Copy link

terrylinooo commented Mar 23, 2019

I develop a WordPress Markwon editor plugin and my user reported this issue to me
terrylinooo/githuber-md#22

After spending time to view the code, I think the only way to solve it is to modify Parsedown.php (line: 1507)

//$markup .= self::escape($Element['text'], true);
$markup .= $Element['text'];

@wottpal
Copy link

wottpal commented Jul 22, 2019

@erusev Just giving this a little push as a lot of people need a newly tagged stable release to fix this.

@edalzell
Copy link

edalzell commented Sep 2, 2019

@aidantwoods @erusev is there an ETA on this?

@jackmcdade
Copy link

Is there anything I can do to help get this resolved? It's been open for 18 months, would love a fix!

@erusev
Copy link
Owner

erusev commented Sep 9, 2019

@aidantwoods could you share your latest thoughts on this issue? I'd love to know about causes and possible solutions. Thanks!

@aidantwoods
Copy link
Collaborator

This should be resolved in 0.8.0-beta-1.

Screenshot 2019-09-09 at 22 45 09

0.8.0-beta-1 along with Parsedown 1.8.0-beta-x are "beta" for the purpose of not breaking extensions. There were a few internal changes on the protected API that in theory could break extensions (overview here).
I made as many as backwards compatible as I could, but in some cases extensions were depending on a particular element structure returned by block* and inline* methods. In theory this structure might change for any reason (e.g. a bugfix) but since there wasn't really a proper API boundary defined that extensions could rely on, it's sort of hard to say that extensions should or shouldn't have relied upon a particular observed behaviour.

Instead of just releasing these beta versions as major version bumps I wanted to create a proper API boundary for extensions to use so that this doesn't occur in future. There's quite a bit of work gone into what that new version might look like over in erusev/parsedown#708, though I'm hesitant to merge this in without feedback.

@nathanlesage
Copy link

Just for clarification: Does this mean that we already see a light at the end of the tunnel? Would like to report this back to the corresponding OctoberCMS-issue so that back there we could also get a heads-up for when it'll work without monkey patching :)

@aidantwoods
Copy link
Collaborator

Short-circuited a fix to this in #144 by porting a subset of a parsedown 1.8 beta feature (rawHtml) into stable. It is important that Parsedown 1.7.x does not itself utilise this feature so as to avoid potential breakage caused by adding features like this.

Fix is released as 0.8.1.

Some context on potential breakage for 1.8-beta:

getgrav/grav#1972 (comment)
erusev/parsedown#580 (comment)
erusev/parsedown#601 (comment)

As mentioned before, I think the right thing to do going forward is to put efforts into 2.0 (which aims to define a clear API for "extensions" to use) rather than trying to tiptoe around an undefined boundary for breakage due to extensions being able (and arguably encouraged by docs) to tightly couple themselves to internal observed behaviours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests