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

reduce direct html injection, add escaping where necessary #8817

Merged
merged 18 commits into from
Nov 30, 2021
Merged

Conversation

tyrasd
Copy link
Member

@tyrasd tyrasd commented Nov 18, 2021

fixes #8813 by:

  • partially reverting 32f8274 (Add lang attribute to translated text #7998) so that html is only used when necessary and safe.
    • this is now almost exclusively the case when html comes from an internal source like t.html(…).
  • t.html now escapes all replacement strings, except when they are explicitly marked as html code.
  • replacing many unnecessary calls to d3_selection.html with a new method that directly and safely appends the localized text to the dom: ~selection.html(t.html("…"))selection.call(t.append("…"))
  • adding a missing encodeURIComponent thanks @1ec5
  • use a more precise "language code" for the no-language-code specified case (unrelated to the fix, but also included because it touches the same code), thanks @1ec5

todo:

  • add to changelog
  • add unit tests for new t.append method

@tyrasd tyrasd added the bug-release-blocker An important bug - let's get this fixed in the next release! label Nov 18, 2021
Copy link
Collaborator

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making these extensive changes. I haven’t gotten a chance to look through the whole PR, but here’s a couple things that I noticed at a glance.

Copy link
Collaborator

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good as far as I can tell.

@tyrasd tyrasd marked this pull request as draft November 23, 2021 17:48
by using d3 to insert the localized text spans directly into the DOM
@tyrasd
Copy link
Member Author

tyrasd commented Nov 26, 2021

Quick update on this issue: I do now consider (almost?) all usages of d3's .html(…) and thus also all usages of t.html as problematic code. Instead, all text should have been inserted using d3 natively (see the new t.htmlDom method). I'm starting to rewrite all affected portions of the code. Most "regular" calls to t.html should already be refactored. I don't yet have an implementation which works for the nested localized spans and there are a few places where the .html injection was used "creatively", which I will still have to look at.

I noticed that there are some glitches in various parts of the UI at the moment:

  • walkthrough
  • help menu
  • issues/validation menu(??)
  • turn restrictions field
  • global search results

//edit: here's an example of a further html injection vector: via OSM tags 🙈
image

@tyrasd
Copy link
Member Author

tyrasd commented Nov 29, 2021

The UI glitches seem to be resolved now. Only a few small todos are now left (see top comment).

There's quite a bit more t.html I really would like to remove from the code base eventually, but they require deeper refactoring and don't seem to be obvious XSS / HTML injection vectors or AFAICS.

@tyrasd tyrasd marked this pull request as ready for review November 29, 2021 18:38
@tyrasd tyrasd merged commit e66edcb into develop Nov 30, 2021
@tyrasd tyrasd deleted the issue-8813 branch November 30, 2021 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-release-blocker An important bug - let's get this fixed in the next release!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OSM username isn't escaped properly
2 participants