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

[Bug] Markdown #10326

Closed
3 of 9 tasks
TimerWolf opened this issue Feb 18, 2020 · 18 comments
Closed
3 of 9 tasks

[Bug] Markdown #10326

TimerWolf opened this issue Feb 18, 2020 · 18 comments

Comments

@TimerWolf
Copy link

TimerWolf commented Feb 18, 2020

Description

I think that this and the broken feature is called markdown, and if you use it this way as i do under this text it will break, for some reason it don't here at github :)

If the link provided not working, just use the code that i used here!

Example

# Status Hover
1 Works Here
2 Broken Here
@jolheiser
Copy link
Member

The markdown parser we use must not allow > in link titles. (< also aren't allowed, nor are most symbols from what I could tell)
My best guess is it's to block users from breaking out of the rendered HTML tag and insert potentially malicious elements.

@zeripath
Copy link
Contributor

zeripath commented Feb 18, 2020

Have you tried & g t ; ?

@lafriks
Copy link
Member

lafriks commented Feb 18, 2020

To be honest I don't see difference between github and gitea rendered tables 🤔

@TimerWolf
Copy link
Author

TimerWolf commented Feb 18, 2020

The markdown parser we use must not allow > in link titles. (< also aren't allowed, nor are most symbols from what I could tell)
My best guess is it's to block users from breaking out of the rendered HTML tag and insert potentially malicious elements.

Maybe that's the case but why would it be allowed here on github then?

Have you tried & g t ; ?

That did not work ether, but it works here on github as well.

To be honest I don't see difference between github and gitea rendered tables 🤔

The broken one don´t show you the tooltip in "try.gitea.io" when you hover over it.

@jolheiser
Copy link
Member

GH uses a different parser than us, more than likely. I haven't had a chance to look for a possible config option, but my guess is we would need to extend our parser for this to work.

@guillep2k
Copy link
Member

It took me a while to understand the problem 😁. For reference:

GitHub, mouse hover on first item:

image

GitHub, mouse hover on second item:

image

Gitea, mouse hover on first item:

image

Gitea, mouse hover on second item:

image

@TimerWolf since we can't access the exact markdown code you've used, would you paste it here in a code block?

    ```
    ### Markdown code
    [text](url)
    ```

@jolheiser
Copy link
Member

jolheiser commented Feb 18, 2020

@guillep2k

[Works](https://: "1, 2 ,3, 4, 5")
[Broken](https://: "1&lt;  2 -> 3 -> 4 -> 5")

Essentially this is exploiting link titles for hovering purposes.
I'm trying to look through goldmark to see where this is processed, but it's admittedly slow going at the moment.

@guillep2k
Copy link
Member

No luck. The parser won't even take (Unicode U+FF1C - FULLWIDTH LESS-THAN SIGN). As far as I can tell, no symbol outside a small subset will be accepted. *, $ and # are rejected, accented characters (á) and comma (,) seem OK, but colon, semicolon and ampersand are out of the question.

@jolheiser
Copy link
Member

jolheiser commented Feb 18, 2020

This looks like an upstream bug, possibly?
It should be allowed per CommonMark spec (Example 502).

@TimerWolf
Copy link
Author

TimerWolf commented Feb 18, 2020

@guillep2k: thanks for straight that things out for me, for some reason when i do stuff it always end up that people don't understand what i mean.

I don't know why as i was quite clear to me as i did change the code to "hover -> here" and also actually have the "status" indicator, but thanks again and sorry if anyone if it was a bit unclear.

The code is back to it's original i was never suppose to change not sure why i accepted that change, it was only suppose to be a preview test that @zeripath suggested...

@jolheiser: i like to use the hover for this purpose when it's a lot of text that should fit in and in the same time not break the table, like descriptions.

@mrsdizzie
Copy link
Member

mrsdizzie commented Feb 19, 2020

This comes from default bluemonday policy and not goldmark:

// Paragraph of text in an attribute such as *.'title', img.alt, etc
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#attr-title
// Note that we are not allowing chars that could close tags like '>'
Paragraph = regexp.MustCompile(`^[\p{L}\p{N}\s\-_',\[\]!\./\\\(\)]*$`)

Then enabled for title here:

// "title" is permitted as it improves accessibility.
p.AllowAttrs("title").Matching(Paragraph).Globally()

If we did want to overide it and allow a closing tag for link titles we could use this in https://github.com/go-gitea/gitea/blob/master/modules/markup/sanitizer.go,

sanitizer.policy.AllowAttrs("title").Matching(regexp.MustCompile(`^[\p{L}\p{N}\s\-_',\[\]!\./\\\(\)\>]*$`)).OnElements("a")

Which in testing would output:

<td>Broken</td>
<td><a href="https://:" title="1 -&gt; 2 -&gt; 3 -&gt; 4 -&gt; 5">How</a></td>

Which seems fine in that example. I believe. You can see it currently doesn't allow other characters as well (pretty much anything that isn't a word number and those few punctuations listed)

@jolheiser
Copy link
Member

Shoot, I thought I tested it well enough locally. Good catch @mrsdizzie!

@mrsdizzie
Copy link
Member

@jolheiser Does that seem like something we should change you think?

@jolheiser
Copy link
Member

It seems that would solve this particular issue, but I'm not sure if there would be other unintended effects. Based on the comment in the bluemonday excerpt, it seems like > was left out intentionally.

If you test with that sanitizer, can you escape titles using raw html?

@mrsdizzie
Copy link
Member

Hmm seems fine in my probably limited testing

@jolheiser
Copy link
Member

jolheiser commented Feb 19, 2020

We switcht from blackfriday to gildmark, so this may also fixed this issue

As mentioned above, this is because of our sanitizer, not goldmark.

Hmm seems fine in my probably limited testing

@mrsdizzie would you mind opening a PR? We can discuss whether we should include more symbols there?

I'm still cautious because bluemonday specifically mentions blocking >

mrsdizzie added a commit to mrsdizzie/gitea that referenced this issue Feb 19, 2020
According to the common mark spec:

 https://spec.commonmark.org/0.29/#link-title

You should be able to stick abut anything in there. Right now we're
limited by the default setting of bluemonday which restricts what can go
in a title tag and makes our rendering not compliant with the spec.

This should fix go-gitea#10326
@mrsdizzie
Copy link
Member

@jolheiser opened PR for further discussion

@lafriks
Copy link
Member

lafriks commented Mar 15, 2020

Fixed by #10527 if not please reopen

@lafriks lafriks closed this as completed Mar 15, 2020
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants