Commit Graph

15314 Commits

Author SHA1 Message Date
Jean Boussier
9feaf7eaae Fix a typo in http_basic_authenticate_with 2022-03-04 16:10:38 +01:00
Jean Boussier
9ebfb149ed Better handle basic authentication without a password
https://github.com/rails/rails/pull/43209 immediately rejects
the request if no password is passed, but there are legitimate
uses for accepting authentication without a password.
2022-03-04 14:40:04 +01:00
Jean Boussier
c6b6833ec4
Merge pull request #44586 from Shopify/action-view-eager-loading
Eager load controllers `view_context_class`
2022-03-02 09:22:50 +01:00
Jean Boussier
2fd34270eb Eager load controllers view_context_class
These classes are relatively small, however they include lots of
modules as helpers. And if any of the included module hold constants
including it cause the global constant cache to be invalidated
which is really bad for performance.

So when eager loading is enabled we create all the possible classes
as part of the application boot.
2022-03-02 08:47:54 +01:00
Edouard CHIN
cdccbb4818 Apply content security policy mapping when generated dynamically:
- Fix #44536
2022-03-01 13:15:50 +01:00
Brad Trick
880a1bedb9 Allow skip_forgery_protection if no protection set
Calling `skip_forgery_protection` without first calling
`protect_from_forgery`--either manually or through default
settings--raises an `ArgumentError` because `verify_authenticity_token`
has not been defined as a callback.

Since Rails 7.0 adds `skip_forgery_protection` to the
`Rails::WelcomeController` (PR #42864), this behavior means that setting
`default_protect_from_forgery` to false and visiting the Rails Welcome
page (`/`) raises an error.

This behavior also created an issue for `ActionMailbox` that was
previously fixed in the Mailbox controller by running
`skip_forgery_protection` only if `default_protect_from_forgery` was
true (PR #35935).

This PR addresses the underlying issue by setting the `raise` option for
`skip_before_action` to default to false inside
`skip_forgery_protection`.

The fix is implemented in `request_forgery_protection.rb`. The change to
`ActionMailbox`'s `base_controller.rb` removes the now-unnecessary
check of `default_protect_from_forgery`.

The tests added in `request_forgery_protection_test.rb` and
`routing_test.rb` both raise an error when run against the current
codebase and pass with the changes noted above.
2022-02-27 21:58:42 -05:00
Rafael Mendonça França
eaccffaa8c
Merge pull request #44523 from SValkanov/apidocs_edit_actioncontroller_doc
Edit ActionController Base API docs [ci-skip]
2022-02-25 14:50:20 -05:00
Jon Dufresne
c2e756a944 Remove body content from redirect responses
Modern browsers don't render this HTML so it goes unused in practice.
The delivered bytes are therefore a small waste (although very small)
and unnecessary and could be optimized away.

Additionally, the HTML fails validation. Using the W3C v.Nu, we see the
following errors:

    Warning: Consider adding a lang attribute to the html start tag to declare the language of this document.

    Error: Start tag seen without seeing a doctype first. Expected <!DOCTYPE html>.

    Error: Element head is missing a required instance of child element title.

These errors may surface in site-wide compliance tests (either internal
tests or external contractual tests). Avoid the false positives by
removing the HTML.

While these warnings and errors could be resolved, it would be simpler
on future maintenance to remove the body altogether (especially as it
isn't rendered by the browser). As the same string is copied around a
few places, this removes multiple touch points to resolve the current
validation errors as well as new ones.

Many other frameworks and web servers don't include an HTML body on
redirect, so there isn't a reason for Rails to do so. By removing the
custom Rails HTML, there are fewing "fingerprints" that a malicious bot
could use to identify the backend technologies.

Application controllers that wish to add a response body after calling
redirect_to can continue to do so.
2022-02-25 13:31:54 -04:00
Jean Boussier
e3c9d566ae Add missing ruby2_keywords in RoutingAssertions 2022-02-24 12:10:37 +01:00
allergo
3ad9e57eda Edit ActionController Base API docs [ci-skip]
Fix information on Sessions - CookieStore
2022-02-24 00:02:44 +02:00
Jonathan Hefner
497ab719d0
Merge pull request #44509 from jonathanhefner/apidocs-cross-link-docs
Cross-link API docs [ci-skip]
2022-02-23 12:08:41 -06:00
Jonathan Hefner
8e080d04ce
Merge pull request #44505 from jonathanhefner/apidocs-improve-http-authentication-doc
Improve HTTP authentication API docs [ci-skip]
2022-02-23 12:06:56 -06:00
Jonathan Hefner
9b857799eb
Merge pull request #44511 from p8/docs/permission-policy
Move docs to ActionDispatch::HTTP::PermissionsPolicy [ci-skip]
2022-02-22 17:08:19 -06:00
Petrik
94050d7dde Move PermissionsPolicy docs to ActionDispatch::HTTP::PermissionsPolicy [ci-skip]
As most of the PermissionsPolicy is defined in
ActionDispatch::HTTP::PermissionsPolicy, it should include most of the
documentation. ActionController::Metal::PermissionsPolicy should
describe controller overrides.

This PR also makes the documentation more similar to the
ActionDispatch::HTTP::ContentSecurityPolicy documentation.

Note:
The Feature-Policy header has been renamed to Permissions-Policy
in the specification. The Permissions-Policy requires a different
implementation and isn't yet supported by all browsers. To avoid
having to rename this middleware in the future we use the new
name for the middleware but keep the old header name in the
documentation for now.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-02-22 21:27:39 +01:00
Sam Bostock
c56abcd6a9
Stop capturing subdomain in HostAuthorization
This also extracts a constant, giving a name to a "magic regex".
2022-02-22 13:00:24 -05:00
Jean Boussier
ce1517ea52 Fix CHANGELOG typos 2022-02-22 18:53:52 +01:00
Petrik
646c631869 Remove fixed TODO ActionController::Metal::ContentSecurityPolicy [ci-skip]
The ActionController::Metal::ContentSecurityPolicy has documentation so
the TODO for documentation can be removed.
2022-02-21 21:10:47 +01:00
Jonathan Hefner
a199aaedb8 Cross-link API docs [ci-skip]
RDoc will automatically format and link API references as long as they
are not already marked up as inline code.

This commit removes markup from various API references so that those
references will link to the relevant API docs.
2022-02-21 11:45:25 -06:00
Jonathan Hefner
eb7a0fcec0 Improve HTTP authentication API docs [ci-skip]
This adds docs for a few public methods, and fixes a handful of
formatting issues.
2022-02-21 11:45:01 -06:00
Jonathan Hefner
75a9e1be75 Improve Flash API docs [ci-skip]
This cross-links the `flash` method doc to the `Flash` and `FlashHash`
class docs, and fixes a code snippet formatting issue.
2022-02-21 11:11:11 -06:00
Jonathan Hefner
9dbf7a58a2 Fix formatting of parameters doc [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner
a801aa7cde Mark up inline code [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner
e37adfed4e Add Oxford commas [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner
07bee949c4 Replace backticks with RDoc markup [ci-skip]
RDoc does not support backticks the way that Markdown does.  Instead,
inline code must be wrapped with `+` or `<tt>`.
2022-02-21 11:11:11 -06:00
Jonathan Hefner
0d3effc97e Replace "overwrite" with "override" [ci-skip]
"Overwrite" means "destructively replace", and is more suitable when,
for example, talking about writing data to a location.

"Override" means "supersede", and is more suitable when, for example,
talking about redifining methods in a subclass.
2022-02-21 11:11:11 -06:00
Jonathan Hefner
5fdbd217d1 Fix typos [ci-skip] 2022-02-21 11:11:11 -06:00
Jean Boussier
d32767884d Copy over the IsolatedExecutionState in AC::Live
Fix: https://github.com/rails/rails/issues/44496

It's really unfortunate, but since thread locals were copied
since a decade and we moved most of them into IsolatedExecutionState
we now need to copy it too to keep backward compatibility.

However I think it's one more sign that AC::Live should be
rethought.
2022-02-21 11:40:52 +01:00
Petrik
b588ceb44f Improve Content Security Policy documentation [ci-skip]
- Use "HTTP Content-Security-Policy response header" instead of "Content
  Security Policy", to make it clear the header will be set.
- Instead of having a long list of examples in the guide, add a
  description to each example.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-02-18 10:39:11 +01:00
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