Commit Graph

14774 Commits

Author SHA1 Message Date
Javi Martín
6b5d25b28e Update Ruby after deploy:updating
We need to download the most recent CONSUL and check its `.ruby-version`
file before installing Ruby.

The `rvm1-capistrano` gem knows it and was invoking the `updating` task
before installing Ruby. So we were getting a warning in Capistrano about
the `updating` task being executed twice.
2019-11-17 17:17:17 +01:00
Julian Nicolas Herrero
81cf1635bb Merge pull request #3808 from consul/chromedriver_upgrade
Update chromeOptions for newer versions of chromedriver
2019-11-14 20:05:09 +07:00
Javier Martín
6c80da71ad Merge pull request #3853 from consul/fix_first_deployment
Fix secrets task on first deployments
2019-11-14 13:32:32 +01:00
Javier Martín
8ead74c59b Merge pull request #3850 from consul/puma_rb
Add puma configuration to version control
2019-11-14 13:31:11 +01:00
Julian Herrero
cb3a1f2860 Update chromeOptions for newer versions of chromedriver 2019-11-14 11:58:39 +07:00
Javi Martín
0c33c4061d Fix secrets task on first deployments
New CONSUL instances who didn't use the newest installer and haven't
done any deployments with capistrano would get an exception because the
`current` capistrano folder doesn't exist yet.
2019-11-14 00:15:19 +01:00
Javier Martín
70cc7dee73 Merge pull request #3851 from consul/security
Reduce false positives count in security reports
2019-11-13 20:15:18 +01:00
Javi Martín
a76ed31a94 Remove unneeded scope
In this case using `joins` doesn't prevent N+1 queries to get titles for
every record, and since we cannot order translations with just SQL due
to fallbacks, we don't need it.

Automatic SQL injection checks were showing a false positive in this
scope; there was no real vulnerability here because foreign keys, table
names and locales were under our control.
2019-11-13 19:52:15 +01:00
Javi Martín
e470ea1cc1 Avoid JavaScript execution in banner URLs
Using `sanitize` we make sure the `href` attribute does not execute any
dangerous code. The possibility of a banner pointing to a dangerous URL
was very reduced, though, since only administrators can edit this
attribute.
2019-11-13 19:52:15 +01:00
Javi Martín
6cb3047da2 Reuse partial to render a banner 2019-11-13 19:52:15 +01:00
Javi Martín
55d339572c Simplify setting tsvector values
We make the code easier to read and at the same time we remove a SQL
injection false positive regarding the use of `WHERE id = #{id}`.

We still get a warning about SQL injection regarding the `tsv =` part.
It's a false positive, since the value of that parameter does not
depend on user input.
2019-11-13 19:52:15 +01:00
Javi Martín
1e32455cd9 Add puma configuration to version control
We were using Capistrano's shared folder because it was the default
folder used by the capistrano-puma gem. However, it's easier to manage
it if it's under version control.

So we're moving the old `puma.rb` to `puma/development.rb`, and we use
the new `puma.rb` file for all environments except development. Anyone
installing CONSUL can change these files at will or change the specific
files for preproduction, production and staging environments.
2019-11-13 13:28:27 +01:00
Javi Martín
d746401862 Avoid a format validation security warning
This was actually a false positive, since our new regular expression
does the exact same thing. However, false positives generate noise and
make it harder to deal with real issues, so I'm changing it anyway.

We could add a more advanced regular expression, like
`URI::MailTo::EMAIL_REGEXP`. However, this expression marks emails with
non-English characters as invalid, when in practice it's possible to
have an email address with non-English characters.
2019-11-13 01:50:08 +01:00
Javi Martín
58157beb01 Add CSRF protection to management controllers 2019-11-13 01:33:56 +01:00
Javi Martín
0e7c3b4cc0 Remove redundant method to set order
It was being incorrectly detected as used in a dangerous send. We can
get rid of the warning by taking advantage of the `has_orders` method
and getting rid of this code.
2019-11-13 01:33:06 +01:00
João Lutz
f4ae9725c6 Allow create legislation proposals on process draft phase (Merge #3532) 2019-11-13 01:23:59 +01:00
Javi Martín
82e96edf1f Remove duplication in deploy environment files
Deploy environment files were loaded after config/deploy.rb was loaded,
meaning if we used settings like `deploy_to` or `current_path` to set
variables inside the config/deploy.rb file, we'd be using the default
settings instead of the ones dictated by the deploy environment files.
2019-11-12 20:20:45 +01:00
Javi Martín
1f4f70b4a9 Remove redundant stage settings
These files are only loaded when the stage already has the value set
inside them, so we don't need to set it again.

On the other hand, the `rails_env` setting is configured in the
`config/deploy.rb` file.
2019-11-12 20:20:45 +01:00
Javi Martín
58befabde5 Bump puma from 4.2.1 to 4.3.0 2019-11-12 20:20:45 +01:00
Javier Martín
e7842adb67 Merge pull request #3846 from consul/redirects
Avoid redirects with unprotected query params
2019-11-12 20:12:24 +01:00
Javi Martín
31c21ddd42 Keep current host in links to current path
This way we avoid a possible unprotected redirect.
2019-11-12 19:28:35 +01:00
Javi Martín
9065683216 Redirect to referer after destroying an image
The same way we do for documents. This way we avoid a possible
unprotected redirect.
2019-11-12 19:28:35 +01:00
Javi Martín
50bdfd5488 Avoid redirects with unprotected query params
In theory it's possible to add a `host` parameter to a URL, and we could
end up redirecting to that host if we just redirect using query
parameters.

Generating the path using `url_for` with `only_path` solves the issue.

Note in the tests I'm using the `get` method because the `patch` method
wouldn't send query parameters. This doesn't mean the action can be
accessed through GET requests, since controller tests don't check route
verbs. Using feature specs doesn't seem to work because `controller` and
`host` parameters are filtered automatically in feature specs.

Also note I'm not testing every hidden/moderation controller because
they basically use the same code.
2019-11-12 19:27:58 +01:00
Javi Martín
667797161b Extract method to redirect keeping query params 2019-11-12 19:27:58 +01:00
Javi Martín
941fc76884 Remove unused query parameters in redirect
These actions are never called with query parameters in our application,
so there's no need to use these parameters in a redirect.

Note in the test I'm using the `get` method because the `patch` method
wouldn't send query parameters. This doesn't mean the action can be
accessed through GET requests, since controller tests don't check route
verbs.
2019-11-12 19:27:58 +01:00
Javier Martín
aef4651f0d Merge pull request #3849 from consul/puma_socket
Make puma restarts work with systemd
2019-11-12 16:31:05 +01:00
Javi Martín
c4a97a3cf7 Clarify our puma.rb file is only used locally 2019-11-12 16:05:43 +01:00
Javi Martín
95d395343b Use two puma workers
This is the same configuration we had with unicorn.

With several workers, we've got two basic configuration options:

* Preload the application and use a hot restart
* Don't preload the application and use a phased restart

I've decided to preload the application because using a hot restart
changes are available immediately, while with a phased restart there are
a few seconds when both workers for the old code and workers for the new
code exist.

Using a phased restart also has advantages, so some forks might want to
disable the `puma_preload_app` setting in order to use it.
2019-11-12 15:32:04 +01:00
Javi Martín
d17b2523cf Make puma restarts work with systemd
Just like mentioned in puma's documentation:

https://github.com/puma/puma/blob/master/docs/systemd.md#socket-activation
2019-11-12 15:32:04 +01:00
Javier Martín
e9b9512254 Merge pull request #3695 from consul/smtp_secrets
Define SMTP settings in secrets file
2019-11-12 15:28:26 +01:00
Javi Martín
d7aab4c929 Check permissions for secrets file
Old versions of the installer created this file as root, making it
impossible to change it as a regular user.

So for old installations we need to make sure we've got write access to
this file.

We're using `sudo` because in these applications the installer gives
`sudo` access to the deploy user, so everything works fine with the
default configuration.
2019-11-12 14:58:35 +01:00
Javi Martín
a08d42d3f8 Enable/disable delayed jobs in the secrets file
While this is not a secret and in theory should be in a file under
version control, currently the CONSUL installer disables delayed jobs by
default, meaning we were keeping two versions of the delayed jobs
configuration file, and some existing configurations have their settings
defined in a file in capistrano's `shared` folder.

So we're moving existing settings to the secrets file.
2019-11-12 14:58:35 +01:00
Javi Martín
6ecd9e59dc Update secrets based on the previous release
We were copying the current SMTP and SSL settings to the secrets file
after overwriting them, but we need to copy them before overwriting
them.

The workaround I've found is to copy the tasks to the folder of the
previous release and execute them there.
2019-11-12 14:58:06 +01:00
Julian Herrero
d6130cf6e2 Add task to move force_ssl settings to secrets.yml
Existing installations having their configuration settings in the
capistrano shared folder needed this migration.
2019-11-12 14:58:05 +01:00
Julian Herrero
df4f8810c5 Define force_ssl configuration in secrets file
this is usually configured in the production.rb file (which is under
version control), the natural place to configure it is the secrets.yml
file.

Until now we were using the capistrano shared folder, but that's a bit
inconvenient since changes we've done to the production.rb file (like
changing eager_load_paths when we upgraded to Rails 5) won't take effect
after a deployment.
2019-11-12 14:47:28 +01:00
Javi Martín
03c4275525 Add task to move SMTP settings to secrets.yml
Existing installations having their configuration settings in the
capistrano shared folder needed this migration.

Note we can't just use `YAML.load` because we'd lose the anchors defined
in the file. So we have to parse the file the hard way.
2019-11-12 14:47:27 +01:00
dependabot-preview[bot]
18f8c96073 Bump sitemap_generator from 6.0.1 to 6.0.2
Bumps [sitemap_generator](https://github.com/kjvarga/sitemap_generator) from 6.0.1 to 6.0.2.
- [Release notes](https://github.com/kjvarga/sitemap_generator/releases)
- [Changelog](https://github.com/kjvarga/sitemap_generator/blob/master/CHANGES.md)
- [Commits](https://github.com/kjvarga/sitemap_generator/compare/v6.0.1...v6.0.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-11 14:12:26 +00:00
Javi Martín
bc9471b49e Define SMTP configuration in the secrets file
Since SMTP passwords should not be in a file under version control, and
they're usually configured in the production.rb file (which is under
version control), the natural place to configure it is the secrets.yml
file.

Until now we were using the capistrano shared folder, but that's a bit
inconvenient since changes we've done to the production.rb file (like
changing eager_load_paths when we upgraded to Rails 5) won't take effect
after a deployment.
2019-11-11 12:11:20 +01:00
Javier Martín
4b41ccf75d Merge pull request #3845 from consul/pagination_tests
Reduce number of records in pagination tests
2019-11-10 16:58:57 +01:00
Javi Martín
bd03e249ce Reduce number of records in pagination tests
Creating more than 25 records isn't necessary to test pagination; we can
stub the number of records per page in a test.

On my machine we save about one second per test with these changes.
2019-11-10 14:12:21 +01:00
Javier Martín
2228ac3781 Merge pull request #3844 from consul/hidden_tests
Split comments and debates admin tests
2019-11-10 13:00:47 +01:00
Javi Martín
a84cf54c73 Add tests for debates and comments admin index 2019-11-10 12:32:25 +01:00
Javi Martín
940f099505 Move tests for moderated content to their own files
When we renamed hidden controllers in the admin section in commit
85722eb7 we forgot to rename the test files as well.
2019-11-10 12:32:25 +01:00
Javier Martín
83e97cba55 Merge pull request #3843 from consul/remove_unused_code
Remove unused code
2019-11-10 01:04:42 +01:00
Javi Martín
216d9e61dc Remove unused Voter methods
AFAIK these methods were never used. In any case, the similar method
`set_demographic_info` was added in commit 6c34599e.
2019-11-10 00:34:45 +01:00
Javi Martín
497b087072 Remove obsolete model
It was replaced by Dashboard::AdministratorTask in commit e5f9cf67.
2019-11-10 00:34:45 +01:00
Javi Martín
3eda2de2d5 Remove unused helper methods
They aren't used since commits a6585361, 3752f3a5, 88a7a29d, eef8ad1b,
f67f058b, 04910fea and 9181610d. The method `image_bytes_to_megabytes`
was never used and is a duplicate of the method `bytes_to_megabytes`.
2019-11-10 00:34:45 +01:00
Javi Martín
23d132c3d3 Remove obsolete controller concern
It isn't used since commit 18f0697e.
2019-11-10 00:34:40 +01:00
Javi Martín
e0cb2047e6 Remove unused controller
It was probably added by accident in commit 85c08da7.
2019-11-09 23:24:54 +01:00
Javier Martín
b22ba4aff3 Merge pull request #3838 from PierreMesure/replace-spanish-text-with-app-name
Replace old Spanish text with org name
2019-11-09 21:39:35 +01:00