Commit Graph

948 Commits

Author SHA1 Message Date
Gannon McGibbon
8d4d0f3701 Fix assert_recognizes on mounted root routes.
Allow `assert_recognizes` routing assertions to work on mounted root routes.
2020-08-10 16:59:52 -04:00
Guo Xiang Tan
f1e53be508
Change default HTTP status to 308 for ActionDispatch::SSL.
308 status code introduced in https://tools.ietf.org/html/rfc7538
preserves the request method unlike 301 status code which would convert
POST requests to GET.
2020-07-06 14:51:24 +08:00
Guo Xiang Tan
e84c43844d
Update follow_redirect! to reuse same HTTP verb for 308 redirections. 2020-06-18 10:24:20 +08:00
Étienne Barrié
cf3736dce8
Add application config for URL-safe Base64 CSRF tokens
This allows applications to safely upgrade to Rails 6.1 without
breaking tokens while the deploy is still being rolled out.
2020-06-11 11:39:37 -04:00
Eugene Kenny
186115180e
Merge pull request #39557 from jonathanhefner/cookie-domains-strict-match
Strict match when choosing cookie domain for host
2020-06-10 09:18:25 +01:00
Jonathan Hefner
1704be74ee Strict match when choosing cookie domain for host
Prior to this commit, when multiple cookie domains were specified, the
first domain that was a substring of the request host was chosen.  This
allowed, for example, the "example.com" domain to be chosen when the
request host was "example.com.au" or even "myexample.com".

This commit ensures a domain is chosen only if it is equal to or is a
superdomain of the request host.

Fixes #37760.
2020-06-10 02:17:39 -05:00
Ryuta Kamizono
cfb7c16ac4 Fixup CHANGELOGs [ci skip] 2020-06-07 12:58:22 +09:00
Jeremy Daer
e3ef5911a1 Precompressed static file refactor 2020-06-01 08:57:05 -07:00
Ryan Hall
3d9a98b474 Allow rails to serve brotli encoded assets
When using an external build process (webpack, grunt) it's helpful for
rails to be able to serve those assets. Brotli has better compression
than gzip and should eventually replace it for static assets.

When using an external build process (webpack, grunt) it's helpful for
rails to be able to serve those assets. Brotli has better compression
than gzip and will eventually replace it for static assets.
2020-06-01 08:57:02 -07:00
fatkodima
6c4f3be929 Unify raise_on_missing_translations for views and controllers 2020-05-20 02:42:59 +03:00
Eugene Kenny
c84cc3a59c Add compact and compact! to ActionController::Parameters
This makes it safe to replace `reject { |k, v| v.nil? }` with `compact`,
even when the receiver is an `ActionController::Parameters`.
2020-05-17 11:04:25 +01:00
Eugene Kenny
1c4a7a0da3 Return enumerator from each_pair and each_value
This matches Hash's behaviour for those methods.
2020-05-12 14:22:23 +01:00
George Claghorn
25bc1c0134 Revert "Don’t ignore X-Forwarded-For IPs with ports attached"
Depends on newer Rack API.

This reverts commit fbf1d82e0db55a60610b1df56f531e4200cf1e26.
2020-05-12 08:07:17 -04:00
Duncan Brown
fbf1d82e0d
Don’t ignore X-Forwarded-For IPs with ports attached
Rack decided to tolerate proxies which choose to attach ports to
X-Forwarded-For IPs by stripping the port:
https://github.com/rack/rack/pull/1251. Attaching a port is rare in the
wild but some proxies (notably Microsoft Azure's App Service) do it.

Without this patch, remote_ip will ignore X-Forwarded-For IPs with ports
attached and the return value is less likely to be useful.

Rails should do the same thing. The stripping logic is already available
in Rack::Request::Helpers, so change the X-Forwarded-For retrieval
method from ActionDispatch::Request#x_forwarded_for (which returns the
raw header) to #forwarded_for, which returns a stripped array of IP
addresses, or nil. There may be other benefits hiding in Rack's
implementation.

We can't call ips_from with an array (and legislating for that inside
ips_from doesn't appeal), so refactor out the bit we need to apply in
both cases (verifying the IP is acceptable to IPAddr and that it's not a
range) to a separate method called #sanitize_ips which reduces an array of
maybe-ips to an array of acceptable ones.
2020-05-09 22:23:34 -04:00
Xavier Noria
8609a2d3f1 reminder for helper Module in CHANGELOG for helper [ci skip] 2020-05-08 18:52:43 +02:00
Edouard CHIN
beb7fba632 Use the file_fixture_path for fixture_file_upload:
- We used the `fixture_path` before `file_fixture_path` was a thing,
  but now that we have the latter we should use it.

  `fixture_path` is solely used by Active Record so it seems wrong
  to be using that in ActionPack.
2020-05-05 15:28:56 +02:00
Rafael Mendonça França
03351cd541
Remove deprecated force_ssl at the controller level. 2020-05-05 00:58:54 -04:00
Xavier Noria
5b28a0e972 Remove require_dependency usage in helper [Closes #37632]
Motivation is twofold:

  * We are gradually removing `require_dependency` from the framework.

  * Let `helper` work if `config.add_autoload_paths_to_load_path` is
    disabled.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2020-05-02 17:57:55 +02:00
Nick Soracco
8544c9c236
Minor fix to correctly identify the entire scope of the loopback address, per RFC-3330.
From #38142

[Rafael Mendonça França + Nick Soracco]
2020-04-08 20:56:36 -04:00
Jonathan Hefner
c7b7d83f70 Heed config.force_ssl when building URL
`url_for` will now use "https://" as the default protocol when
`Rails.application.config.force_ssl` is set to true.

Action Mailer already behaves this way, effectively.  This commit
extends that behavior application-wide.

Closes #23543.
2020-04-05 18:19:31 -05:00
Scott Blum
dabb587cbb
Accept and default to base64_urlsafe CSRF tokens (#18496)
Base64 strict-encoded CSRF tokens are not inherently websafe, which makes
them difficult to deal with. For example, the common practice of sending
the CSRF token to a browser in a client-readable cookie does not work properly
out of the box: the value has to be url-encoded and decoded to survive transport.

Now, we generate Base64 urlsafe-encoded CSRF tokens, which are inherently safe
to transport.  Validation accepts both urlsafe tokens, and strict-encoded tokens
for backwards compatibility.
2020-03-28 21:07:09 -07:00
Masaki Hara
5debcecdf1
Support rolling deploys for cookie serialization/encryption changes (#37628)
In a distributed configuration like rolling update, users may observe
both old and new instances during deployment. Users may be served by a
new instance and then by an old instance.

That means when the server changes `cookies_serializer` from `:marshal`
to `:hybrid` or the server changes `use_authenticated_cookie_encryption`
from `false` to `true`, users may lose their sessions if they access the
server during deployment.

We added fallbacks to downgrade the cookie format when necessary during
deployment, ensuring compatibility on both old and new instances.
2020-03-18 12:03:00 -07:00
Ryuta Kamizono
1d3eb7be13 Fixup CHANGELOGs [ci skip] 2020-02-25 14:14:54 +09:00
Rafael Mendonça França
7b29bc2179
Merge pull request #38150 from kbrock/all_trusted_ips
When all IPs are trusted, use the furthest away
2020-01-03 19:00:23 -03:00
Keenan Brock
b17aaae811 trusted IP changelog 2020-01-03 13:32:44 -05:00
Rafael Mendonça França
92ec9f270d
Fix possible information leak / session hijacking vulnerability.
The `ActionDispatch::Session::MemcacheStore` is still vulnerable
given it requires the gem dalli to be updated as well.

CVE-2019-16782
2019-12-18 17:01:09 -03:00
Ryuta Kamizono
72af0bbc3d Fix typos 2019-12-18 16:47:18 +09:00
Rafael Mendonça França
c135b922cf
Merge pull request #32143 from sambostock/bubble-up-session-assertions
Delegate child session assertions to parent session
2019-12-17 21:47:58 -03:00
Cédric Fabianski
7ccaa125ba
Add SameSite protection to every written cookie
Enabling `SameSite` cookie protection is an addition to CSRF protection,
where cookies won't be sent by browsers in cross-site POST requests when set to `:lax`.

`:strict` disables cookies being sent in cross-site GET or POST requests.

Passing `:none` disables this protection and is the same as previous versions albeit a `; SameSite=None` is appended to the cookie.

See upgrade instructions in config/initializers/new_framework_defaults_6_1.rb.

More info [here](https://tools.ietf.org/html/draft-west-first-party-cookies-07)

_NB: Technically already possible as Rack supports SameSite protection, this is to ensure it's applied to all cookies_
2019-12-15 01:37:24 +01:00
Edouard CHIN
33bf253282 Bring back feature that allows loading external route iles:
= This feature existed back in 2012 5e7d6bba79
  but got reverted with the incentive that there was a better approach.
  After discussions, we agreed that it's a useful feature for apps
  that have a really large set of routes.

  Co-authored-by: Yehuda Katz <wycats@gmail.com>
2019-12-06 14:20:12 +01:00
glaszig
769188e1c3 forward system test driver options configured
in initializer block to the selenium driver
for non-headless browsers

* refactored browser options initialization.
* improved method names in AD::SystemTesting::Browser
* improved AD::SystemTest driver tests
2019-12-04 15:57:00 +01:00
Austin Story
23b738225f Add request to the payload for notifications to redirect_to.action_controller.
This change will allow subscribers to the notification to report on anything related to the request that they might need
2019-12-01 08:31:41 -05:00
Ryuta Kamizono
214f439343 Fixup CHANGELOGs [ci skip] 2019-11-24 09:20:00 +09:00
Rafael Mendonça França
4fe767535d
Merge pull request #37617 from Edouard-chin/ec-respond-to-contenttype
Modify respond_to behaviour always setting the response's content type based on the request format
2019-11-22 14:28:42 -05:00
Edouard CHIN
42c515764a Modify respond_to behaviour always setting the request's content type:
- `respond_to any` doesn't allow to specify a content type and
  the content type in the response will be based on the request
  format.

  ```ruby
    def my_action
      respond_to do |format|
        format.html { render(html: 'hello') }
        format.any { render(json: { foo: 'bar'}) }
      end
    end

    get('my_action.csv')
    # Before this patch, content type was `text/csv'
    # Ather this patch, content type is correctly set to whateve we did in the `format.any` block
  ```

  If the client specify the type of data he wants but the server
  doesn't know how to handle it and return plain text (or whatever)
  I don't think it make sense to falsey claim that we are returning
  a `text/csv` a response where in fact we are returning something else.

  Fix #37345
2019-11-21 14:40:42 +01:00
Damir Zekić
3c3b80eb96 Remove slashes and backslashes from image paths
When a test method name includes a slash (e.g. `test "signup on the
/signup page"`) the screenshot is generated in the nested directory on
systems that use slash as a directory separator (e.g. a screenshot
called `signup_page.png` is generated within `failures_signup_on_the_`).

Nesting screenshots causes an issue with `tmp:clear` rake task:

```
== Removing old logs and tempfiles ==
rails aborted!
Errno::EISDIR: Is a directory @ apply2files - tmp/screenshots/failures_signup_on_the_
/var/lib/gems/2.5.0/gems/railties-5.2.3/lib/rails/tasks/tmp.rake:41:in `block (3 levels) in <top (required)>'
/var/lib/gems/2.5.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
...
Tasks: TOP => tmp:clear => tmp:screenshots:clear
```

While the error could be prevented by changing `tmp:clear` task, there's
no reason to generate deep directory structures for tests using slashes.

To prevent a similar problem on Windows, we'll also "sanitize"
backslashes.

Replacing the problamatic characters with dashes seems to be a safe
workaround, although dash is very arbitrary choice in this case.

Co-Authored-By: Louis-Michel Couture <louim_1@hotmail.com>
2019-11-19 20:06:47 +01:00
Younes SERRAJ
34b6e8c0ae Add params.member? to mimic Hash behavior 2019-11-19 16:03:01 +01:00
George Claghorn
b5c6f33f0d Provide the whole response 2019-11-16 08:17:01 -05:00
George Claghorn
32b99f9358 Provide the whole request 2019-11-04 18:32:03 -05:00
George Claghorn
8ec75a142e Add :uuid to process_action.action_controller payloads 2019-11-04 10:30:38 -05:00
George Claghorn
722259444a Add :location to process_action.action_controller payloads 2019-11-04 07:46:48 -05:00
norm
bf14a8e235 Updated ActionDispatch::Request.remote_ip=
Updated the setter to clear the value in the `@remote_ip` instance
variable before setting the header that the value is derived from in the
getter.
2019-10-06 14:33:04 -07:00
George Claghorn
75a53297c7
Add ActionController::Base.log_at
Allow setting a different log level per request.
2019-09-24 13:47:34 -04:00
Takayuki Nakata
1da65ab6ce Fix typo in actionpack changelog, a HTTP -> an HTTP [ci skip] 2019-09-24 08:33:10 +09:00
Ryuta Kamizono
36b32bb32e Revert "Merge pull request #36785 from shes50103/fix_typo_actionpack_changelog"
This reverts commit ac6f3c9299209ea4b2fa7c368ea1ff406735ca93, reversing
changes made to 5b0ea95a1a8acc5054f9a58d324070303cbd19b9.
2019-07-28 15:55:38 +09:00
shes50103
c3d5c9447a fix typo in actionpack CHANGELOG.md 2019-07-28 11:17:19 +08:00
Rafael Mendonça França
5b0ea95a1a
Merge pull request #36545 from tomfakes/screenshot-updates
HTML page save during screenshot and multiple shots per test
2019-07-27 22:48:24 -04:00
st0012
5745a3c092 Add Vary: Accept header when rendering
Problem description (quoted from @rafaelfranca's excellent explanation in https://github.com/rails/jquery-ujs/issues/318#issuecomment-88129005):

> Let say that we requested /tasks/1 using Ajax, and the previous page has the same url. When we click the back button the browser tries to get the response from its cache and it gets the javascript response. With vary we "fix" this behavior because we are telling the browser that the url is the same but it is not from the same type what will skip the cache.

And there's a Rails issue discussing about this problem as well https://github.com/rails/rails/issues/25842

Also, according to [RFC 7231 7.1.4](https://tools.ietf.org/html/rfc7231#section-7.1.4)

>  An origin server SHOULD send a Vary header field when its algorithm
>  for selecting a representation varies based on aspects of the request
>  message other than the method and request target

we should add `Vary: Accept` header when determining content based on the `Accept` header.

Although adding such header by default could cause unnecessary cache invalidation. But this PR only adds the header if:
- The format param is not provided
- The request is a `xhr` request
- The request has accept headers and the headers are valid

So if the user
- sends request with explicit format, like `/users/1.json`
- or sends a normal request (non xhr)
- or doesn't specify accept headers

then the header won't be added.

See the discussion in https://github.com/rails/rails/issues/25842 and
https://github.com/rails/rails/pull/36213 for more details.
2019-07-26 13:52:06 +08:00
Edouard CHIN
1969f40a3a fix follow_redirect! not using the same HTTP verb on 307 redirection:
- According to the HTTP 1.1 spec, the 307 redirection guarantees that
  the method and the body will not be changed during redirection.

  This PR fixes that since follow_redirect! would always follow the
  redirection my making a GET request.

  Ref https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307
2019-07-25 18:57:07 +02:00
George Claghorn
d415eb4f6d
Stop setting a default Capybara app host
It's intended not to be set if Capybara starts the app server itself. Base Rails-generated URLs off of Capybara.current_session.server_url instead.
2019-07-24 22:19:21 -04:00