Commit Graph

15065 Commits

Author SHA1 Message Date
Javi Martín
ef2b2317e5 Fix flaky officing results spec
The page could have "7777" as a content for the poll's name, since that
name is generated using a random hexadecimal number.

Restricting the search to the area of the page where the "7777" used to
be solves the problem.
2019-10-09 21:57:20 +02:00
Javier Martín
dadc3d174c Merge pull request #3748 from consul/locales_html
Sanitize translations instead of using `_html`
2019-10-09 20:44:01 +02:00
Javi Martín
9a299aeeb5 Fix checkbox label containing links
The link tags were being stripped out by `content_tag`.
2019-10-09 19:46:47 +02:00
Javi Martín
6b1864fbcd Sanitize translations instead of using _html
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.
2019-10-09 19:46:47 +02:00
Javi Martín
b66859945e Remove _html suffix from already sanitized texts
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.
2019-10-09 19:46:47 +02:00
Javi Martín
7782ed73b6 Remove unneeded _html suffix
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.
2019-10-09 19:46:47 +02:00
Javier Martín
acce50ada2 Merge pull request #3690 from consul/dependabot/bundler/devise-4.7.1
[Security] Bump devise from 4.6.2 to 4.7.1
2019-10-09 19:37:01 +02:00
dependabot-preview[bot]
22e91271e5 [Security] Bump devise from 4.6.2 to 4.7.1
Bumps [devise](https://github.com/plataformatec/devise) from 4.6.2 to 4.7.1. **This update includes a security fix.**
- [Release notes](https://github.com/plataformatec/devise/releases)
- [Changelog](https://github.com/plataformatec/devise/blob/master/CHANGELOG.md)
- [Commits](https://github.com/plataformatec/devise/compare/v4.6.2...v4.7.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-09 16:43:34 +00:00
Javier Martín
39dd4c628f Merge pull request #3751 from consul/prepare_1.1_tasks
Remove tasks executed in version 1.0.0
2019-10-08 21:21:36 +02:00
Javi Martín
0a2efb1d80 Use application logger in set_original_heading_id
The pull request adding the original heading was done before we started
using `ApplicationLogger` in rake tasks.
2019-10-08 20:39:26 +02:00
Javi Martín
4fad6f16f6 Make set_original_heading_id task idempotent
This way there'll be no side effects if accidentally executed on data
already having the `original_heading_id`.
2019-10-08 20:30:02 +02:00
Javi Martín
acbad38749 Update execute_release_tasks task
It now contains tasks we've added after version 1.0.0
2019-10-08 20:20:41 +02:00
Javi Martín
7bb39c8e4e Execute add_new_settings on every release
Although it's already executed when deploying with capistrano, heroku
installations don't use capistrano for deployment, so we're also
executing it when upgrading.

This isn't a one-time task, so it makes sense to have it executed on
every release.
2019-10-08 20:19:48 +02:00
Javi Martín
8fb44961e9 Remove tasks to rename/remove deprecated settings
I was thinking of leaving these tasks empty, so in the future we could
use them again if we rename or remove more settings. But since we
haven't renamed nor removed any settings for more than seven months, and
we've only used these tasks once, I'm simply removing the tasks. It's
easy to add them back if we ever need them.
2019-10-08 20:19:48 +02:00
Javi Martín
122b066573 Remove already executed tasks
These tasks were executed when upgading to version 0.19, 1.0.0-beta or
1.0.0.
2019-10-08 20:19:48 +02:00
Javier Martín
8b2acc1e0a Merge pull request #3747 from consul/html_safe
Sanitize texts instead of using html_safe
2019-10-08 19:54:18 +02:00
Javi Martín
391f58eb90 Sanitize dashboard action before displaying it
We were using `<%==`, which is the same as using `raw`.

Note ERB Lint doesn't warn us of this usage. Brakeman does warn us,
though.
2019-10-08 19:10:14 +02:00
Javi Martín
a20c0f078d Use safe_join instead of <%==
Using `<%==` is the same as using `raw`, and here we only want to mark
as safe a `<br>` tag.
2019-10-08 19:10:14 +02:00
Javi Martín
00a6f5b601 Remove <%== usage displaying settings
Using `<%==` is the same as using `raw`. I'm not sure if we meant
`sanitize` in this case, or it's just a typo. I'm assuming the latter
since we don't use anything similar in any other places.
2019-10-08 19:10:14 +02:00
Javi Martín
b1b449b187 Add rubocop and erb-lints rules for output safetey
This way we make sure we won't add `html_safe` or `raw` calls in the
future.

I'm excluding `text_with_links_helpers` for this check, because in this
situation the use of `html_safe` is justified: we check the original
input is safe, and we're only adding link tags to raw URLs.
2019-10-08 19:10:13 +02:00
Javi Martín
89402bdbf6 Use raw instead of html_safe
They do the exact same thing; however `html_safe` might confuse
developers into thinking it will make the HTML safe. Using `raw` makes
it clear that we're inserting the text without escaping it.
2019-10-08 19:10:13 +02:00
Javi Martín
9eee79f218 Sanitize markdown output
We were using the markdown renderer with the `filter_html` option set to
false, so we weren't removing hypothetical `<script>` tags.
2019-10-08 18:46:21 +02:00
Javi Martín
61bf9a5c73 Use sanitize instead of html_safe
The difference is `html_safe` allows every HTML tag, including the
`<script>` tag, while `sanitize` only allows tags which are considered
safe. In this case, we want to allow a `<span>` tag in a translation,
and links inside flash messages.
2019-10-08 18:46:21 +02:00
Javi Martín
928312e218 Use sanitize in translations with links
Sometimes we're interpolating a link inside a translation, and marking
the whole translations as HTML safe.

However, some translations added by admins to the database or through
crowdin are not entirely under our control.

Although AFAIK crowdin checks for potential cross-site scripting
attacks, it's a good practice to sanitize parts of a string potentially
out of our control before marking the string as HTML safe.
2019-10-08 18:46:21 +02:00
Javi Martín
56f690b8a9 Use attributes in translations with sanitize
There's a slight chance an attribute like an author's name might contain
an attempt to perform XSS attacks. So, instead of marking the whole text
as HTML safe, we can sanitize it.

Also note I'm removing the `_html` suffix in the i18n key, since it's
got the same effect as using `html_safe`.
2019-10-08 18:46:21 +02:00
Javi Martín
75a28fafcb Sanitize label texts automatically
This way we can remove all those `html_safe` calls and we avoid
potential XSS attacks in label texts.
2019-10-08 18:46:21 +02:00
Javi Martín
2586229e38 Remove duplication in TextWithLinksHelper
We were using `Rinku.auto_link` the same way twice. And it makes sense
that the method `sanitize_and_auto_link` first sanitizes the text and
then calls `auto_link_already_sanitized_text`.
2019-10-08 18:46:21 +02:00
Javi Martín
0b40865e61 Raise an exception when handling unsafe content
We were confused about what `.html_safe` did, and were automatically
marking as safe content which was not.
2019-10-08 18:46:20 +02:00
Javi Martín
2aabf79fb4 Rename methods to add auto links to HTML
The name `safe_html_with_links` was confusing and could make you think
it takes care of making the HTML safe. So I've renamed it in a way that
makes it a bit more intuitive that it expects its input to be already
sanitized.

I've changed `text_with_links` as well so now the two method names
complement each other.
2019-10-08 18:46:20 +02:00
Javi Martín
2ffbae890e Sanitize valuation explanations
If we don't sanitize them, valuators might attempt Cross-Site Scripting
attacks.
2019-10-08 18:46:20 +02:00
Javi Martín
8b73cfc019 Sanitize annotation context before displaying it
There's a case where we would face a Cross-Site Scripting attack. An
attacker could use the browser's developer tools to add (on their
browser) a `<code>` tag with a `<script>` tag inside in the text of the
draft version. After doing so, commenting on that text would result in
the attacker's JavaScript being executed.
2019-10-08 18:46:20 +02:00
Javi Martín
0f485308b7 Sanitize CKEditor content before displaying it
It's possible to create a newsletter or a proposed action with
<script> tags by filling in the body using a textarea instead of a
CKEditor. While we trust our administrators not to do so, it's better to
completely eliminate that possibility.
2019-10-08 18:46:20 +02:00
Javi Martín
368f42f1a2 Revert loofah update
We need to update other gems as well if we update this one. Dependabot
updated it automatically when updating `foundation_rails_helper`, but it
doesn't seem to be necessary.
2019-10-08 18:46:20 +02:00
Javi Martín
60ae224115 Use tag to mark a <br> as safe HTML
Using `html_safe` on the whole text meant the translations were also
considered HTML safe, but they are not supposed to have HTML.
2019-10-08 18:46:20 +02:00
Javi Martín
6b12da7654 Fix ERB being used in an HTML comment
This was causing erb-lint to issue a warning.
2019-10-08 18:46:20 +02:00
Javi Martín
db1ccb18c7 Use safe_join instead of html_safe
The name `html_safe` is very confusing, and many developers (including
me a few years ago) think what that method does is convert the HTML
contents to safe content. It's actually quite the opposite: it marks the
string as safe, so the HTML inside it isn't stripped out by Rails.

In some cases we were marking strings as safe because we wanted to add
some HTML. However, it meant the whole string was considered safe, and
not just the contents which were under our control.

In particular, some translations added by admins to the database or
through crowding were marked as safe, when it wasn't necessarily the
case.

Although AFAIK crowdin checks for potential cross-site scripting
attacks, it's a good practice to sanitize parts of a string potentially
out of our control before marking the string as HTML safe.
2019-10-08 18:46:20 +02:00
Javi Martín
eb16b9df48 Remove unneded html_safe in investment description
The description is already marked as HTML safe because we sanitize it
before storing it in the database.
2019-10-08 13:20:22 +02:00
Javi Martín
55a190f44a Remove unneeded _html suffix in I18n keys
This suffix does the same thing as calling `.html_safe` on them. So we
don't need to use it in texts that don't use HTML.
2019-10-08 13:20:22 +02:00
Javi Martín
031b5aba63 Remove unnecessary html_safe in paths
Paths are just regular strings with no HTML, so they don't need to be
marked as safe HTML.
2019-10-08 13:20:22 +02:00
Javi Martín
20ca6beb30 Remove unneeded html_safe and raw calls
There's no HTML in these texts, or it has already been escaped by Rails
`link_to` helper method.
2019-10-08 13:20:22 +02:00
Javier Martín
2c80c05372 Merge pull request #3739 from consul/dependabot/bundler/rubocop-0.75.0
Bump rubocop from 0.60.0 to 0.75.0
2019-10-08 13:20:01 +02:00
Javi Martín
19555442da Update Hound's rubocop version
Hound doesn't support version 0.75 yet, so we need to use 0.72.0.
2019-10-08 12:52:11 +02:00
Javi Martín
63d31f47c7 Add missing rubocop dependencies
Rails and performance cops have been extracted to separate gems.

Note in the past we had to add these lines in order to activate Rails
cops:

```
Rails:
  Enabled: true
```

But we didn't do it, and so Rails cops were ignored.

With the new version, it's enough to require `rubocop-rails`.
2019-10-08 12:42:46 +02:00
Javier Martín
4e37ef045e Merge pull request #3750 from consul/obsolete_code
Fix typos in legacy code
2019-10-08 12:28:53 +02:00
Javi Martín
e06bbaed78 Remove unused and add missing Spanish i18n keys
They were accidentally added in commit 9d1ca3bf, missing in that same
commit, or left by accident in commit 78c6f6f7.
2019-10-07 17:26:45 +02:00
Javi Martín
2614253b69 Fix typo in <br> tag
We probably meant `<br>`, `<br />` or `<br/>`, but wrote `</br>`
instead.
2019-10-07 17:26:24 +02:00
Javi Martín
29e8f1ac9f Remove obsolete method
This code isn't used since commit eef8ad1b.
2019-10-07 17:25:11 +02:00
Javier Martín
c3685e748b Merge pull request #3744 from consul/admin_booths_search
Fix booth search with blank text
2019-10-07 15:21:46 +02:00
Javi Martín
710a1d8357 Split Poll::Booth.search in two methods
We use this method in two different scenarios. In an AJAX request, we
don't want to return every booth if the search is blank. However, in a
normal HTTP GET request, we want to return every record when the search
is empty, as we do everywhere else.

It's possible the behaviour of the AJAX call is unusual, since it
searches all booths, and not just the ones assigned to a poll. If we
changed this behaviour, we could simplify the code and remove the
`quick_search` method.
2019-10-07 14:30:39 +02:00
Javi Martín
24e4f4518f Render search field before "no results" message
The same way it's done in other sections.
2019-10-07 14:30:39 +02:00