Commit Graph

903 Commits

Author SHA1 Message Date
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
Rafael Mendonça França
a115a4cc79
Merge pull request #31634 from afcapel/reduce-routing-error-log-noise
Reduce log noise handling ActionController::RoutingErrors
2019-07-16 14:16:28 +01:00
Jacob Bednarz
6c5acd5bc1
Use reserved domain for example configuration
Updates the generator output to use a reserved domain[1] instead of a
potentially real world domain.

[1]: https://tools.ietf.org/html/rfc2606#section-3
2019-07-15 08:16:51 +10:00
Jacob Bednarz
bf19b8774e Adds support for configuring HTTP Feature Policy (#33439)
A HTTP feature policy is Yet Another HTTP header for instructing the
browser about which features the application intends to make use of and
to lock down access to others. This is a new security mechanism that
ensures that should an application become compromised or a third party
attempts an unexpected action, the browser will override it and maintain
the intended UX.

WICG specification: https://wicg.github.io/feature-policy/

The end result is a HTTP header that looks like the following:

```
Feature-Policy: geolocation 'none'; autoplay https://example.com
```

This will prevent the browser from using geolocation and only allow
autoplay on `https://example.com`. Full feature list can be found over
in the WICG repository[1].

As of today Chrome and Safari have public support[2] for this
functionality with Firefox working on support[3] and Edge still pending
acceptance of the suggestion[4].

#### Examples

Using an initializer

```rb
# config/initializers/feature_policy.rb
Rails.application.config.feature_policy do |f|
  f.geolocation :none
  f.camera      :none
  f.payment     "https://secure.example.com"
  f.fullscreen  :self
end
```

In a controller

```rb
class SampleController < ApplicationController
  def index
    feature_policy do |f|
      f.geolocation "https://example.com"
    end
  end
end
```

Some of you might realise that the HTTP feature policy looks pretty
close to that of a Content Security Policy; and you're right. So much so
that I used the Content Security Policy DSL from #31162 as the starting
point for this change.

This change *doesn't* introduce support for defining a feature policy on
an iframe and this has been intentionally done to split the HTTP header
and the HTML element (`iframe`) support. If this is successful, I'll
look to add that on it's own.

Full documentation on HTTP feature policies can be found at
https://wicg.github.io/feature-policy/. Google have also published[5] a
great in-depth write up of this functionality.

[1]: https://github.com/WICG/feature-policy/blob/master/features.md
[2]: https://www.chromestatus.com/feature/5694225681219584
[3]: https://bugzilla.mozilla.org/show_bug.cgi?id=1390801
[4]: https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer/suggestions/33507907-support-feature-policy
[5]: https://developers.google.com/web/updates/2018/06/feature-policy
2019-07-10 15:33:15 -07:00
Tom Fakes
c699a877ca Add code to save the HTML of the page being screenshotted during the take_screenshot method
that is enabled by a new environment variable - RAILS_SYSTEM_TESTING_SCREENSHOT_HTML=1

Add the ability to call `take_screenshot` more than once in a single test by prefixing the name of
the image file with a counter that is incremented on every `take_screenshot` call.  This allows a
developer to see their pages in sequence when trying to debug test errors.  This does not affect
the failure case where the prefix remains 'failures'
2019-06-25 21:04:30 -07:00
yuuji.yaginuma
09d55b3022 Add the ability to set the CSP nonce only to the specified directives
I changed to set CSP nonce to `style-src` directive in #32932.
But this causes an issue when `unsafe-inline` is specified to `style-src`
(If a nonce is present, a nonce takes precedence over `unsafe-inline`).

So, I fixed to nonce directives configurable. By configure this, users
can make CSP as before.

Fixes #35137.
2019-06-22 12:44:37 +09:00
Ryuta Kamizono
cc27e9988f Unify to use 4 spaces indentation in CHANGELOGs [ci skip]
Especially, somehow `CHANGELOG.md` in actiontext and activestorage in
master branch had used 3 spaces indentation.
2019-06-05 05:53:49 +09:00
Alberto Fernández Capel
c8f4c53d55 Reduce log noise handling ActionController::RoutingErrors
Each time a missing route is hit 32 lines of internal rails traces
are written to the log. This is overly verbose and doesn't offer
any actionable information to the user.

With this change we'll still write an error message showing the
route error but the trace will be omitted.
2019-05-28 20:39:10 +01:00
Alberto Almagro
fb9117e190 Keep part when scope option has value
When a route was defined within an optional scope, if that route didn't
take parameters the scope was lost when using path helpers. This patch
ensures scope is kept both when the route takes parameters or when it
doesn't.

Fixes #33219
2019-05-22 23:03:54 +02:00
Gustavo Gutierrez
bc7e94503a
Implemented deep_transform_keys/! for ActionController::Parameters 2019-05-22 16:04:31 +02:00
Eugene Kenny
46e84d5b10 Return parameters enumerator from transform_keys/!
Previously calling `ActionController::Parameters#transform_keys/!`
without passing a block would return an enumerator for the underlying
hash, which was inconsistent with the behaviour when a block was passed:

    ActionController::Parameters.new(foo: "bar").transform_keys { |k| k }
    => <ActionController::Parameters {"foo"=>"bar"} permitted: false>
    ActionController::Parameters.new(foo: "bar").transform_keys.each { |k| k }
    => {"foo"=>"bar"}

An enumerator for the parameters is now returned instead, ensuring that
evaluating it produces another parameters object instead of a hash:

    ActionController::Parameters.new(foo: "bar").transform_keys.each { |k| k }
    => <ActionController::Parameters {"foo"=>"bar"} permitted: false>
2019-05-18 22:49:32 +01:00
L.Fexon
858c63a0a4 fixed usage of Parameters when a non-numeric key exists
test for non-numeric key in nested attributes

test: extra blank line between tests removed

test for non-numeric key fixed (by Daniel)

Update according to feedback
2019-05-13 15:03:27 +08:00
Ryuta Kamizono
8024179d60 Remove forward ported CHANGELOG [ci skip] 2019-05-08 19:19:08 +09:00
Eileen M. Uchitelle
d155f61b64 Merge pull request #36196 from st0012/fix-29947
Hide malformed parameters from error page

Accidentally merged this to 6-0-stable so forward porting it to master
here instead.
2019-05-07 15:14:14 -04:00
Rafael Mendonça França
9834be6565
Start Rails 6.1 development 2019-04-24 15:57:14 -04:00
Richard Macklin
ef12ccfd8b Make system tests take failed screenshots in before_teardown hook
Previously we were calling the `take_failed_screenshot` method in an
`after_teardown` hook. However, this means that other teardown hooks
have to be executed before we take the screenshot. Since there can be
dynamic updates to the page after the assertion fails and before we
take a screenshot, it seems desirable to minimize that gap as much as
possible. Taking the screenshot in a `before_teardown` rather than an
`after_teardown` helps with that, and has a side benefit of allowing
us to remove the nested `ensure` commented on here:
https://github.com/rails/rails/pull/34411#discussion_r232819478
2019-04-20 19:32:30 -07:00
Genadi Samokovarov
45f1c7a3e1 Introduce Actionable Errors
Actionable errors let's you dispatch actions from Rails' error pages. This
can help you save time if you have a clear action for the resolution of
common development errors.

The de-facto example are pending migrations. Every time pending migrations
are found, a middleware raises an error. With actionable errors, you can
run the migrations right from the error page. Other examples include Rails
plugins that need to run a rake task to setup themselves. They can now
raise actionable errors to run the setup straight from the error pages.

Here is how to define an actionable error:

```ruby
class PendingMigrationError < MigrationError #:nodoc:
  include ActiveSupport::ActionableError

  action "Run pending migrations" do
    ActiveRecord::Tasks::DatabaseTasks.migrate
  end
end
```

To make an error actionable, include the `ActiveSupport::ActionableError`
module and invoke the `action` class macro to define the action. An action
needs a name and a procedure to execute. The name is shown as the name of a
button on the error pages. Once clicked, it will invoke the given
procedure.
2019-04-19 14:14:06 +09:00
Ryuta Kamizono
51ab5cb043 Follow up tweaks b89a3e7e638a50c648a17d09c48b49b707e1d90d [ci skip]
* use backticks instead of `+`
* and more (e.g. missed replacing `Array#excluding` and
`Enumerable#excluding` in b89a3e7e638a50c648a17d09c48b49b707e1d90d)
2019-03-31 09:52:02 +09:00
Josua Schmid
25f2e0c39d
Raise if resource custom params contain colons
After this change it's not possible anymore to configure routes
like this:

    routes.draw do
      resources :users, param: "name/:sneaky"
    end

Fixes #30467.
2019-03-26 13:53:41 +01:00
eileencodes
7c87fd5635 Prep release
* Update RAILS_VERSION
* Bundle
* rake update_versions
* rake changelog:header
2019-03-11 11:58:15 -04:00
Rafael Mendonça França
5e6e505083
Preparing for 6.0.0.beta2 release 2019-02-25 17:45:04 -05:00
George Claghorn
44232b4854
Merge pull request #35139 from 7coAim/fix_debug_exceptions
Fix NameError : Make debug exceptions works in an environment where ActiveStorage is not loaded.
2019-02-05 08:36:31 -05:00
kurosawat
a0c57775e2 fix NameError
NameError: uninitialized constant ActionView::CompiledTemplates::ActiveStorage
2019-02-05 20:13:23 +09:00
Gannon McGibbon
5da63c1d56
Merge pull request #35086 from gsamokovarov/cleanup-whitelisting-refs
Cleanup the whitelisting references after #33145
2019-02-04 11:09:46 -05:00
Genadi Samokovarov
ca62dfeede Cleanup the whitelisting references after #33145
During the development of #33145, I have named a few concepts in the
code as `whitelisted`. We decided to stay away from the term and I
adjusted most of the code afterwards, but here are the cases I forgot to
change.

I also found a case in the API guide that we could have cleaned up as
well.

[ci skip]
2019-02-03 10:58:10 +02:00
Edouard CHIN
5936bd9a20 driver_option -> driver_options 2019-01-29 08:50:29 -05:00
Edouard CHIN
01a26e581f Implement a way to add browser capabilities:
* There is currently no way to define specific browser capabilities since our SystemTest driver override the `option` key [Ref](a07d068078/actionpack/lib/action_dispatch/system_testing/driver.rb (L35))
  This option key is used internally by selenium to add custom capabilities on the browser.

  Depending on the Browser, some option are allowed to be passed inside a hash, the driver takes care of setting whatever you passed on the driver option. An example [here](a07d068078/actionpack/lib/action_dispatch/system_testing/driver.rb (L35)) where you are allowed to pass args such as `--no-sandbox` etc
  However this behavior was only meant for backward compatibility and as you can see it's deprecated.
  The non-deprecated behavior is to create a `<Driver>::Option` object containing all the capabilities we want. This is what we [currently do](a07d068078/actionpack/lib/action_dispatch/system_testing/browser.rb (L34-L36)) when chrome or firefox are in headless mode.

  This PR allows to pass a block when calling `driven_by`, the block will be pased a `<Driver>::Option` instance. You can modify this object the way you want by adding any capabilities. The option object will be then passed to selenium.

  ```ruby
    driven_by :selenium, using: :chrome do |driver_option|
      driver_option.add_argument('--no-sandbox')
      driver_option.add_emulation(device: 'iphone 4')
    end
  ```
2019-01-29 08:50:29 -05:00
Rafael França
afbab2822a
Merge pull request #35018 from gmcgibbon/revert_redirect_to_allow_other_host
Revert ensure external redirects are explicitly allowed
2019-01-22 15:35:57 -05:00
alkesh26
78cf58b765 1. Replaced unused variables by _.
2. Typo fixes.
2019-01-22 22:27:01 +05:30
Gannon McGibbon
2e0ca9284a Revert ensure external redirects are explicitly allowed 2019-01-22 11:40:13 -05:00
Rafael Mendonça França
5a0230c67f
Preparing for 6.0.0.beta1 release 2019-01-18 15:42:12 -05:00
Rafael Mendonça França
e70d3df7c9
Remove deprecated fragment_cache_key helper in favor of combined_fragment_cache_key 2019-01-17 16:08:31 -05:00
Rafael Mendonça França
13ddc92e07
Remove deprecated methods in ActionDispatch::TestResponse
`#success?`, `missing?` and `error?` were deprecated in Rails 5.2 in favor of
`#successful?`, `not_found?` and `server_error?`.
2019-01-17 16:08:31 -05:00
Gannon McGibbon
9dde7d8de0 Ensure external redirects are explicitly allowed
Add `fallback_location` and `allow_other_host` options to `redirect_to`.
2019-01-17 13:28:14 -05:00
Rafael Mendonça França
17e4b49292
Revert "Don't handle params option in a special way in url_for helper"
This reverts commit e385e4678fc64be6e176c3bdac6641db9fe48d85.

While this option was undocumented it exists to make possible to pass
parameters to the route helpers that are reserved like `:domain`.

While `url_for(domain: 'foo.com')` would generate a URL in the `foo.com`
domain `url_for(params: { domain: 'foo.com' })` would generate a URL
with `?domain=foo.com`.
2019-01-16 11:12:49 -05:00
Kasper Timm Hansen
1b7c3222e8
Require Ruby 2.5 for Rails 6.
Generally followed the pattern for https://github.com/rails/rails/pull/32034

* Removes needless CI configs for 2.4
* Targets 2.5 in rubocop
* Updates existing CHANGELOG entries for fewer merge conflicts
* Removes Hash#slice extension as that's inlined on Ruby 2.5.
* Removes the need for send on define_method in MethodCallAssertions.
2018-12-19 21:47:50 +01:00
Kasper Timm Hansen
3b68b404a4
[ci skip] Remove needless changelog entry, as bug fix was backported to 5.2. 2018-12-18 21:13:11 +01:00
r7kamura
eb37fd0aec Allow nil params on controller HTTP test methods 2018-12-18 21:44:05 +09:00
Eileen M. Uchitelle
02b931c764
Merge branch 'master' into host-authorization 2018-12-17 10:24:38 -05:00
Tobias Bühlmann
8246a8139c
Allow using parsed_body in ActionController::TestCase
… by switching the initialzation of an appropriate response parser
in `ActionDispatch::TestResponse` from eagerly to lazily.

By doing so, the response parser can be correctly set for
`ActionController::TestCase`, which doesn't include
the content type header in the constructor but only sets it at
a later time.

Fixes #34676.
2018-12-16 12:27:37 +01:00
Genadi Samokovarov
07ec8062e6 Introduce a guard against DNS rebinding attacks
The ActionDispatch::HostAuthorization is a new middleware that prevent
against DNS rebinding and other Host header attacks. By default it is
included only in the development environment with the following
configuration:

    Rails.application.config.hosts = [
      IPAddr.new("0.0.0.0/0"), # All IPv4 addresses.
      IPAddr.new("::/0"),      # All IPv6 addresses.
      "localhost"              # The localhost reserved domain.
    ]

In other environments, `Rails.application.config.hosts` is empty and no
Host header checks will be done. If you want to guard against header
attacks on production, you have to manually permit the allowed hosts
with:

    Rails.application.config.hosts << "product.com"

The host of a request is checked against the hosts entries with the case
operator (#===), which lets hosts support entries of type RegExp,
Proc and IPAddr to name a few. Here is an example with a regexp.

    # Allow requests from subdomains like `www.product.com` and
    # `beta1.product.com`.
    Rails.application.config.hosts << /.*\.product\.com/

A special case is supported that allows you to permit all sub-domains:

    # Allow requests from subdomains like `www.product.com` and
    # `beta1.product.com`.
    Rails.application.config.hosts << ".product.com"
2018-12-15 20:18:51 +02:00
Gannon McGibbon
dde9c48839 Raise an error on root route naming conflicts.
Raises an ArgumentError when multiple root routes are defined in the
same context instead of assigning nil names to subsequent roots.
2018-11-20 14:55:47 -05:00
Gannon McGibbon
6b3faf8e50 Allow rescue from parameter parse errors
[Gannon McGibbon + Josh Cheek]
2018-11-13 18:05:05 -05:00
Maxim Perepelitsa
59895db44b Reset sessions on failed system test screenshot
Reset Capybara sessions if `take_failed_screenshot` raise exception
in system test `after_teardown`.
2018-11-13 03:30:41 +07:00
Ryuta Kamizono
5df4efd2fd Fix broken CHANGELOG markup [ci skip]
And remove trailing spaces.
2018-11-08 09:28:42 +09:00