-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Don't replace underscores in auto-generated IDs in goldmark #12805
Don't replace underscores in auto-generated IDs in goldmark #12805
Conversation
Fix go-gitea#12196 Signed-off-by: Andrew Thornton <art27@cantab.net>
Technically this is breaking. |
Codecov Report
@@ Coverage Diff @@
## master #12805 +/- ##
==========================================
- Coverage 43.13% 43.13% -0.01%
==========================================
Files 654 654
Lines 72205 72205
==========================================
- Hits 31146 31143 -3
+ Misses 36011 36009 -2
- Partials 5048 5053 +5
Continue to review full report at Codecov.
|
Are these underscores coming out of Goldmark like that or are we actually replacing them elsewhere ourselves? I have a suspicion that the latter is the case and then this fix may not be right. BTW it may be possible to add compat with old links in JS thought I'm fine with not adding compat. |
@silverwind this is the place we replace them in goldmark. Outside of goldmark we simply assert that ids need the prefix user-content- |
So they are coming out like that of Goldmark? If so, may be a bug there because I think it strives to be compatible with GFM. The |
We have to protect ids - without prefixing these how do you propose this? |
FYI IDs are generated within our variant of goldmark using: gitea/modules/markup/markdown/goldmark.go Lines 197 to 217 in 29ac1f9
Goldmark's default generator is: gitea/vendor/github.com/yuin/goldmark/parser/parser.go Lines 75 to 115 in 29ac1f9
when I moved us to Goldmark that generator was significantly different from our previous blackfriday generator therefore to make the changes as non-breaking as possible I created the above one. Going back to why we have to prefix IDs: I cannot stress this enough, we absolutely have to prefix ids. Github also does this. Our JS code and our CSS relies on IDs in several places - if you do not prefix user content ids you will get conflicts with multiple ids and will break rendering and potentially create security holes. |
I never understood the reason behind this. Why are user-generated ids so bad?
I think browsers handle that gracefully and scroll to the first id
What benefit would an attacker gain from this exactly? As I see it, they can't really do anything dangerous when controlling ids, but of course it depends on our JS and I'd rather prefer to use classnames only in JS anyways. |
🚀 |
Fix #12196
Signed-off-by: Andrew Thornton art27@cantab.net