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

<script> cuts off post, crashes editor after save #857

Closed
JohnONolan opened this issue Sep 22, 2013 · 7 comments
Closed

<script> cuts off post, crashes editor after save #857

JohnONolan opened this issue Sep 22, 2013 · 7 comments
Assignees
Labels
affects:editor Work relating to the Koenig Editor bug [triage] something behaving unexpectedly
Milestone

Comments

@JohnONolan
Copy link
Member

From the forum

I tried publishing following article, that previously was served through poet: (careful, german!):

http://pastebin.com/dAj48CBp

At the <script> part Ghost seems to fail after the post is saved. When I open it again the last visible character of the post is the ` and I can’t edit the post, the markdown preview is not generated.

I’m on 0.3, using Firefox 24, Arch Linux

Am I doing it wrong or should this be escaped somehow?

@cgiffard
Copy link
Contributor

I sense an XSS vulnerability too. Probably time to get that CSP middleware in...

@sebgie
Copy link
Contributor

sebgie commented Sep 24, 2013

Ghost currently allows all HTML tags in the editor. This could lead to some unwanted behavior as described above or worse to XSS vulnerabilities. One solution would be restricting the allowed inline HTML tags similar to Stackoverflow.com: http://meta.stackoverflow.com/questions/1777/what-html-tags-are-allowed-on-stack-exchange-sites

@cgiffard
Copy link
Contributor

We can also filter the HTML to ensure all tags are balanced properly.

@cgiffard
Copy link
Contributor

That said, we should be escaping all HTML that appears inside back ticks. Happy to take this one.

@ErisDS
Copy link
Member

ErisDS commented Sep 24, 2013

First, we should make it so that what this guy did doesn't cause an enormous crash and unrecoverable post
Second, we should escape all HTML inside of backticks
Third, we should limit what HTML tags are allowed
Fourth, we should balance tags.

This sounds like a lot for one issue... so lets say the desired outcome from this issue is that the editor doesn't explode completely when users do stupid stuff if possible? The other items can be separate issues I think.

@ErisDS
Copy link
Member

ErisDS commented Sep 26, 2013

So, the main problem to fix, it would seem, is getting codemirror to treat the html in codemirror as text and not execute stuff :/

This comment has script tags in it like this:

<script>alert("fail")</script>

<script>alert("fail")</script>

But github doesn't execute the code, currently ghost does... eek

ErisDS added a commit to ErisDS/Ghost that referenced this issue Sep 26, 2013
closes TryGhost#857

- markdown is inserted into codemirror with .text() not .html()
@ghost ghost assigned ErisDS Sep 26, 2013
@ErisDS
Copy link
Member

ErisDS commented Sep 26, 2013

The tiny change from using .html() to using .text() solves the majority of the problem.

No HTML in the editor is treated as HTML, HTML inside of back ticks is correctly escaped, and although we could balance tags, it's much more obvious that tags are in balanced now, because it breaks in a much more reliable way - if you put a single script tag in, nothing afterwards gets rendered.

I'm really not sure about limiting tags at this stage, there are lots of valid use cases for having script tags inside of posts, such as embedding gists Casper#26

I'm gonna close this for now and think some more about tag balancing and limiting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects:editor Work relating to the Koenig Editor bug [triage] something behaving unexpectedly
Projects
None yet
Development

No branches or pull requests

4 participants