Commit Graph

15286 Commits

Author SHA1 Message Date
Jonathan Hefner
97bb0a9e37
Merge pull request #44449 from p8/docs/add-documentation-for-controller-csp
Add documentation for controller CSP methods [ci-skip]
2022-02-17 12:36:48 -06:00
Petrik
a134bd72aa Add documentation for controller CSP methods [skip-ci]
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-02-17 19:28:11 +01:00
Petrik
0b851183e0 Fix links in CSP documentation [ci-skip]
rdoc links use square brackets for the URL part.
2022-02-17 19:22:07 +01:00
Jonathan Hefner
5fb0ad335d Merge pull request #44451 from p8/docs/add-documentation-for-csp
Document some methods in ActionDispatch::ContentSecurityPolicy [skip-ci]
2022-02-17 11:55:49 -06:00
John Hawthorn
139ef8a0bc
Merge pull request #44174 from jguecaimburu/add_lowdash_support_to_path_parser_locale_regex
Add support to locales with lowdash in Resolver::PathParser
2022-02-17 08:27:34 -08:00
Petrik
92d877be22 Document some methods in ActionDispatch::ContentSecurityPolicy [skip-ci]
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-02-17 08:37:08 +01:00
Jean Boussier
2d63d60fa4 Fix setting trailing_slash: true in route definition
Ref: https://github.com/rails/rails/pull/43287
Fix: https://github.com/rails/rails/issues/44373

The `OptimizedUrlHelper` wasn't considering this option.
2022-02-15 10:44:33 +01:00
Gannon McGibbon
d9a38662bd Fix style and misspell in action dispatch executor test 2022-02-11 14:55:33 -05:00
Jean Boussier
10c64a472f
ActionDispatch::Executor don't fully trust body#close
Under certain circumstances, the middleware isn't informed that the
response body has been fully closed which result in request state not
being fully reset before the next request.

[CVE-2022-23633]
2022-02-11 10:08:04 -08:00
Petrik
c9cb1aa198 Silence uninitialized instance var warning in tests
Running the Action Pack tests outputs a warning:

    ./actionpack/test/controller/test_case_test.rb:1007: warning: instance variable @counter not initialized

Surrounding the line with silence_warnings cleans up the output.
2022-02-10 16:31:02 +01:00
David Heinemeier Hansson
41478f7074 Make #to_fs the default replacement for #to_s(:format)
#to_formatted_s is too cumbersome.
2022-02-07 12:41:21 +01:00
Matthew Draper
ea5d02be8b
Merge pull request #44345 from nvasilevski/delete-concerns_executes_block_in_context_of_current_mapper-test
Delete `concerns executes block in context of current mapper` test
2022-02-07 01:40:38 +10:30
Nikita Vasilevsky
e8076efd80 Delete concerns_executes_block_in_context_of_current_mapper test 2022-02-06 14:45:54 +00:00
Drew Bragg
2bdd29a6e4 Stringify keys in session.merge! 2022-02-05 11:23:45 +01:00
Jean Boussier
4f12bcd7f1 Remove the deprecated urlsafe_csrf_tokens configuration
Ref: https://github.com/rails/rails/pull/43817

Normally we remove deprecated code much later, but in this case
it's in the way of https://github.com/rails/rails/pull/44283
so I think it would make sense to remove it now.
2022-02-01 10:35:43 +01:00
Alberto Almagro
f906af86b9 Fix nested bullet list indentation [ci skip]
This patch fixes the indentation of a nested bullet list in the
documentation of `ActionController::Parameters` that appeared as inside
a box in api.rubyonrails.org documentation website.
2022-01-18 23:25:22 +01:00
Juan Guecaimburu
bd0753b396 Add support to locales with lowdash in Resolver::PathParser
In previous versions of Rails, a dynamic regex was built to find templates.
After that, PathParser started to be used to both match and sort templates.
With the dynamic regex, templates with lowdash locales (es_AR) were
found properly. But the PathParser regex does not match locales with this
format, only allowing dash (es-AR) or no dash (es). Templates with lowdash
locales have a wrong virtual path and get filtered.

In this commit the PathParser regex is extended to support the lowdash.
2022-01-14 15:11:58 -03:00
Rafael Mendonça França
9188b49883
Merge pull request #43968 from sabljak/sabljak/remove-x-download-options
Remove X-Download-Options default header
2022-01-06 10:39:14 -05:00
Harun Sabljaković
486be06ccb Remove X-Download-Options default header
Since X-Download-Options header is only used by the soon deprecated Internet Explorer, it makes sense to remove this header as a default one.
2022-01-06 10:03:17 +01:00
Ryuta Kamizono
65766ebcc8 Bump license years to 2022 [ci-skip] 2022-01-01 15:22:15 +09:00
Lachlan Sylvester
cfd992e225 dump the dynamic route segments deprication horizon as it was not removed for rails 7.0 2021-12-23 13:19:02 +11:00
Rafael Mendonça França
b03e1586cd
Merge pull request #43900 from yykamei/initialize-with-logging_context
Initialize `ActionController::Parameters` with `@logging_context`
2021-12-20 17:32:30 -05:00
Dino Maric
f8ac66ae6d Docs: Match example with the sentance. [ci-skip]
Match the code example with the description.

Co-authored-by: Louis-Michel Couture <louim_1@hotmail.com>
2021-12-16 17:50:23 +01:00
Yutaka Kamei
0b7f37fbed
Initialize ActionController::Parameters with @logging_context
`params` contains `@logging_context` in its instance to notify
unpermitted parameters including the context through Rails
Instrumentation API. However, the logging context disappeared when
`params` is updated with some methods, such as `require`, `slice`,
`merge`, etc, so the subscriber of `unpermitted_parameters` could not
get the information.

This patch tries to initialize `Parameters` with `@logging_context`
where it makes sense to pass the information. The following methods will
be affected with this patch:

* `require`
* `deep_dup`
* `slice`
* `except`
* `extract!`
* `transform_values`
* `transform_keys`
* `deep_transform_keys`
* `select`
* `reject`
* `compact`
* `merge`
* `reverse_merge`
2021-12-16 23:11:49 +09:00
Guillermo Iguaran
87d65e9b12 Update request.path_parameters docs: returned hash keys are symbols
Closes #43808
2021-12-15 23:36:13 -08:00
Aaron Patterson
8159996ea0
Dup arrays that get "converted"
We don't want to expose these cache keys to users because users can
mutate the key causing the cache to behave inconsistently.

Fixes: #43681
2021-12-15 14:30:27 -08:00
Rafael Mendonça França
3a4275fa31
Allow IPs with port in the HostAuthorization middleware
When a host was an IP with a port, the IPAddr object comparisson was
raising an exception which was making the middleware reject the request.

Now we extract the hostname out of the host when comparing with IPAddr
objects.
2021-12-15 21:41:50 +00:00
Rafael Mendonça França
c681aaba81
Allow any allowed host with port
All allowed host should be allowed if they are being accessed using a
port.

Fixes #43870.
2021-12-15 02:50:13 +00:00
Rafael Mendonça França
eb80dd39dc
Fix ruby warnings 2021-12-15 02:48:55 +00:00
Rafael Mendonça França
ab754e95d8
Merge pull request #43817 from etiennebarrie/deprecate-non-url-safe-csrf-tokens
Deprecate non-URL-safe CSRF tokens
2021-12-15 01:48:51 +00:00
Rafael Mendonça França
8d982a7cfe
Merge pull request #43836 from donv/patch-1
Don't start the server for the failure screenshot
2021-12-14 20:41:53 -05:00
Aaron Patterson
2366fee77a
Allow localhost with a port by default in development
Only "localhost" and ".localhost" were allowed by default in
development, but the port is also part of the header that is sent.  It
is a bad idea to try parsing whatever stuff is in the HTTP header, so
this commit specifically adds localhost with a port in the "allowed
hosts" list in development.
2021-12-14 14:30:54 -08:00
John Hawthorn
2cb536abdd
Merge pull request #43487 from TooManyBees/raise-error-on-missing-only-unless
Raise error on missing only unless
2021-12-14 12:43:57 -08:00
Stef Schenkelaars
0fccfb9a30
Fix invalid forwarded host vulnerability
Prior to this commit, it was possible to pass an unvalidated host
through the `X-Forwarded-Host` header. If the value of the header
was prefixed with a invalid domain character (for example a `/`),
it was always accepted as the actual host of that request.

Since this host is used for all url helpers, an attacker could change
generated links and redirects. If the header is set to
`X-Forwarded-Host: //evil.hacker`, a redirect will be send to
`https:////evil.hacker/`. Browsers will ignore these four slashes
and redirect the user.

[CVE-2021-44528]
2021-12-14 12:25:10 -08:00
Jess Bees
60f7d49033 Raise error when callback's only/unless symbols aren't methods
When `before_action :callback, only: :action_name` is declared on a
controller that doesn't respond to `action_name`, raise an exception
at request time. This is a safety measure to ensure that typos or
forgetfulness don't prevent a crucial callback from being run when it
should.

Include names of filters for more useful error messages

The error message of the raised exception will be more useful if it
indicates the names of the callbacks that have the missing conditinoal
action.

The way the callbacks get shoehorned into `_normalize_callback_options`
options parameter is a little awkward, but done this way to avoid
changing the method's signature, since it is a publicly documented
method.
2021-12-14 15:22:08 -05:00
Uwe Kubosch
1dfcffb583
Don't start the server for the failure screenshot
When `before_setup` fails, for example with fixture errors, the failure is stored, `setup` is skipped, and `take_failed_screenshot` is called.  Taking a screenshot triggers starting the server which will probably fail since fixtures are not properly loaded.  This generates another failure and makes it harder to debug the fixture failure.

If the server was not already started, it makes no sense to take a screenshot since it is not relevant.

This commit skips taking a failure screenshot if no browser session has been started.
2021-12-11 11:58:51 +01:00
Rafael Mendonça França
e4547052b9
Remove CHANGELOG entry that was already applied to 7.0 2021-12-10 17:13:06 +00:00
Alex Ghiculescu
054fa96bac ActionController::TestCase: reset instance variables after each request
`ActionController::TestCase` keeps a `@controller` instance variable, which represents the controller being tested. At the end of each request inside a test, its [params and format](https://github.com/rails/rails/blob/main/actionpack/lib/action_controller/metal/testing.rb) are reset. But any other instance variables set in the test aren't reset. This creates a problem if you do something like this:

```ruby
class UserController
  def show
    @user ||= User.find(params[:id])
    render plain: @user.name
  end
end
```

```ruby

test "gets the user" do
  get :show, params: { id: users(:one).id }
  assert "one", response.body

  get :show, params: { id: users(:two).id }
  assert "two", response.body
end
```

The second assertion will fail, because `@user` won't be re-assigned in the second test (due to `||=`). This example is a bit contrived, but it shows how instance variables persisting between requests can lead to surprising outcomes.

This PR fixes this by clearing all instance variables that were created on the controller while a request was processed.

It explicitly excludes instance variables that were created *before* any requests were run. And it leaves the instance variable around until the *next* request in the test. This means that you can still do this:

```ruby

test "gets the user" do
  @controller.user = users(:one) # assuming `Controller#user` users an ivar internally, you can set the ivar here...

  get :show_current
  assert "one", response.body

  assert_equal users(:one), @controller.user # and you can read the ivar here
end
```
2021-12-09 16:22:54 -06:00
Rafael Mendonça França
7160f46a9e
Merge pull request #43368 from FestaLab/render-hash-syntax
Replaces the hash rocket operator in favor of the newer Ruby syntax on render
2021-12-08 18:13:44 -05:00
Rafael Mendonça França
ac90d5a32c
Merge pull request #43787 from skyksandr/better-proc-route-inspection
Better proc/lambda route representation in `bin/rails routes`
2021-12-07 11:46:10 -05:00
Rafael Mendonça França
83d85b2207
Start Rails 7.1 development 2021-12-07 15:52:30 +00:00
Aleksandr Kunin
9f7d9d10c9 Better proc/lambda route representation in inspector
Before:
<Proc:RandomObjectId "/full/path/to/config/routes">
After:
"Inline handler (Proc/Lambda)"
2021-12-07 10:33:56 +03:00
Rafael Mendonça França
58ecdd0cf2
Deprecate to_s(format) in favor of to_formatted_s(format)
Ruby 3.1 is going to introduce an [optimization][] that makes interpolation
of some types of objects faster, unless there is a custom implementation
of to_s. Since Rails is overriding `to_s` for a bunch of core classes it
means that this optimization in Rails applications will be disabled.

In order to allow Rails applications to use this optimization in
the future we are deprecating all the reasons we override `to_s` in
those core classes in favor of using `to_formatted_s`.

[optimization]: b08dacfea3
2021-12-06 19:22:05 +00:00
Alex Ghiculescu
39cde506c6 Fix crash in ActionController::TestCase in rspec
Fixes https://github.com/rails/rails-controller-testing/issues/70
2021-11-30 14:01:33 -06:00
Alex Ghiculescu
5046d1cce9 Wrap ActionController::TestCase with Rails executor
Update actionpack/lib/action_controller/test_case.rb

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2021-11-26 17:54:47 -06:00
Rafael Mendonça França
6f8aa2b17d
Move the least common check to the end of the conditional 2021-11-26 20:43:40 +00:00
Justin Tracey
5055ac29d6 Consider onion services secure for cookies 2021-11-26 14:52:09 -05:00
Rafael Mendonça França
481343ed91
Merge PR #41769 2021-11-25 19:27:09 +00:00
Rafael Mendonça França
9606aa70b1
Merge pull request #43703 from p8/actionpack/fix-params-inspect-in-docs
Update inspect output of ActionController::Parameters in docs [skip-ci]
2021-11-23 15:44:54 -05:00
Petrik
9ee8b08aec Update inspect output of ActionController::Parameters in docs [skip-ci]
In 74cb9a6f3823cc64ef97ed6d9250a4d743abf426 a `#` was added to the
inspect of ActionController::Parameters.
This change adds `#` to the inspect output of
ActionController::Parameters in the documentation.
2021-11-23 21:36:28 +01:00