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

Sanitize translations instead of using _html #3748

Merged
merged 4 commits into from
Oct 9, 2019
Merged

Sanitize translations instead of using _html #3748

merged 4 commits into from
Oct 9, 2019

Conversation

javierm
Copy link
Member

@javierm javierm commented Oct 5, 2019

References

Background

We were using the _html suffix in translations to indicate HTML was allowed in those cases. However, doing so is exactly the same as marking them as html_safe. It's safer to sanitize them instead.

Objectives

  • Sanitize HTML in translation texts instead of marking them as safe

Release notes

⚠️ If you're customizing translations using config/locales/custom/, note we've moved translations related to label forms to the activerecord.yml file (pull request #3746), and we've renamed all translations whose key ended with _html, removing the _html suffix (pull request #3748).

@javierm javierm added the security Pull requests that address a security vulnerability label Oct 5, 2019
@javierm javierm self-assigned this Oct 5, 2019
@javierm javierm added this to Reviewing in Roadmap via automation Oct 5, 2019
@javierm javierm changed the title Locales html anitize HTML in translation texts instead of marking them as safe Oct 5, 2019
@javierm javierm changed the title anitize HTML in translation texts instead of marking them as safe Sanitize translations instead of using _html Oct 5, 2019
@javierm javierm force-pushed the locales_html branch 2 times, most recently from 86d44b7 to d55f539 Compare October 6, 2019 13:31
@javierm javierm moved this from Reviewing to Doing in Roadmap Oct 7, 2019
@javierm javierm moved this from Doing to Reviewing in Roadmap Oct 7, 2019
@javierm javierm force-pushed the html_safe branch 2 times, most recently from f68cde6 to 99ffafd Compare October 7, 2019 00:42
@javierm javierm force-pushed the html_safe branch 2 times, most recently from 87d3bec to 238bee5 Compare October 8, 2019 11:22
@javierm javierm force-pushed the locales_html branch 2 times, most recently from 1b3bfd7 to 80574b7 Compare October 9, 2019 15:38
Although this translation has HTML, we aren't marking them as HTML safe
since we're using `I18n.t` instead of Rails' helper `t` method. So using
the `_html` suffix is counterintuitive in this case.
Using the `_html` suffix automatically marks texts as HTML safe, so
doing so on sanitized texts is redundant.

Note flash texts are not sanitized the moment they are generated, but
are sanitized when displayed in the view.
Using the `_html` suffix in an i18n key is the same as using `html_safe`
on it, which means that translation could potentially be used for XSS
attacks.
The link tags were being stripped out by `content_tag`.
@javierm javierm moved this from Reviewing to Testing in Roadmap Oct 9, 2019
@javierm javierm merged commit dadc3d1 into master Oct 9, 2019
Roadmap automation moved this from Testing to Release 1.1.0 Oct 9, 2019
@javierm javierm deleted the locales_html branch October 9, 2019 18:46
smarques pushed a commit to venetochevogliamo/consul that referenced this pull request Apr 29, 2020
Sanitize translations instead of using `_html`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release notes security Pull requests that address a security vulnerability
Projects
No open projects
Roadmap
  
Release 1.1.0
Development

Successfully merging this pull request may close these issues.

None yet

2 participants