Commit Graph

15739 Commits

Author SHA1 Message Date
Samuel Williams
b505e2358c
The JavaScript mime-type was updated in Rack 3.1 to text/javascript. 2023-07-19 15:36:57 +12:00
Samuel Williams
56c416e7c3
The request rack.input is optional. 2023-07-19 15:36:57 +12:00
Henrik Nyh
cf166fb13c Doc and spec cookies.delete returning value 2023-07-12 12:08:35 +01:00
Guillermo Iguaran
1c0aeed2fb
Merge pull request #48575 from skipkayhil/hm-config-exception-level
Make the log level in DebugExceptions configurable
2023-06-27 10:17:45 -07:00
Xavier Noria
9294a55187 Fix indentation in ActionDispatch::Routing::RouteSet::Dispatcher 2023-06-27 16:15:09 +02:00
Carlos Antonio da Silva
d9af9f1023 Avoid creating match object when checking for illegal header value
We can use `match?` to check against the illegal header value regexp,
since we don't need the match data result.
2023-06-27 09:40:35 -03:00
Guillermo Iguaran
10b4bd597f
Merge branch 'main' into hm-config-exception-level 2023-06-26 19:07:08 -07:00
John Hawthorn
f1cdfc037f Fix rubocop warning 2023-06-26 15:17:43 -07:00
Zack Deveau
69e37c84e3 Added check for illegal HTTP header value in redirect_to
The set of legal characters for an HTTP header value is described
in https://datatracker.ietf.org/doc/html/rfc7230\#section-3.2.6.

This commit adds a check to redirect_to that ensures the
provided URL does not contain any of the illegal characters.

Downstream consumers of the resulting Location response header
may accidentally remove the header if it does not comply with the RFC
resulting in unexpected behavior.

Related to [CVE-2023-28362].
2023-06-26 14:51:39 -07:00
Hartley McGuire
519577ecc3
Make the log level in DebugExceptions configurable
This middleware has been logging at a FATAL level since the first
[commit][1] in Rails (the code originally lived in
actionpack/lib/action_controller/rescue.rb). However, FATAL is
documented in the Ruby Logger [docs][2] as being for "An unhandleable
error that results in a program crash.", which does not really apply to
this case since DebugExceptions is handling the error. A more
appropriate level would be ERROR, which the Ruby Logger docs describe as
"A handleable error condition."

This commit introduces a new configuration for the DebugExceptions log
level so that new apps will have it set to ERROR by default and ERROR
can eventually be made the default.

[1]: db045dbbf60b53dbe013ef25554fd013baf88134
[2]: https://ruby-doc.org/3.2.1/stdlibs/logger/Logger/Severity.html
2023-06-25 23:11:39 -04:00
zzak
dd89f600f7
🔗 Remove RDoc auto-link from Rails module everywhere 2023-06-23 10:49:30 +09:00
Guillermo Iguaran
c20f8eb6b6
Merge pull request #48471 from mdh/improve-naming-of-local-secret-generation
Improve naming of local secret generation
2023-06-21 00:04:32 -07:00
Mike Dalessio
2362f57cd8
Update Action View and Action Dispatch to use HTML5 when available 2023-06-19 16:34:33 -04:00
Marek de Heus
f75934f80d Improve naming of local secret generation
For local environments (def and test), we create a secret file. However this file is called development_secret.txt, which imho is confusing as it is used by both dev and test environments.

This commit renames the file and related code to local_secret.
2023-06-19 11:59:17 +02:00
zzak
9cfeedb718
💅 Wrap the AC::Meta::Streaming doc links
This way they look good on page, and in your editor.
2023-06-19 09:33:36 +09:00
zzak
fd2ac22b54
Fixes to AC::Streaming docs
* Unlink the Rails module automatically
* Inline the documentation links for unicorn and passenger
* Use RDoc fixed-width for passenger_buffer_response instead of markdown
* TIL: about linking to headings, so fixed that for "Middlewares" section
2023-06-16 16:36:53 +09:00
Guillermo Iguaran
84540a6289
Merge pull request #48455 from rails/action_controller-streaming-body
Remove dependency on deprecated Rack::Chunked
2023-06-12 15:55:18 -07:00
Guillermo Iguaran
af68c31d7f Remove dependency on deprecated Rack::Chunked
Import the used Rack::Chunked::Body as private AC::Streaming::Body
class and use it instead.
2023-06-11 20:48:37 -07:00
Joé Dupuis
7c3fc67c31 Test respond_to? :to_ary directly on RackBody
RackBody is the final body object returned by the Rack app
(`Rails.application`). This test that it conforms to the spec
instead of testing on the underlying response.
2023-06-11 19:42:22 -07:00
Guillermo Iguaran
0174283901 Undefine #to_ary in ActionController::Live::Buffer
ActionDispatch::Response delegates #to_ary to the internal ActionDispatch::Response::Buffer,
defining #to_ary is an indicator that the response body can be buffered and/or cached by
Rack middlewares, this is not the case for Live responses so we undefine it for this Buffer subclass.

Puma raises an exception trying to call #to_ary in Live::Buffer
expecting it to return an array if defined:

188f5da192/lib/puma/request.rb (L183-L186)
2023-06-11 04:07:48 -07:00
Joé Dupuis
45c90b7bd3 Rack spec requires mutable headers
The rack spec requires the header object to be an unfrozen hash.
c8e9822183/SPEC.rdoc (L240)

Rack::ETag was buffering and making a copy of the response,
so the freeze was not effective anyway.

Plus we are freezing the hash too early, preventing middlewares
from modifying it. It causes crash with gems like rack-livereload.
I started having crashes on some pages (like the internal
http://localhost:3000/rails/info/routes) because of rack-livereload
hitting the frozen hash after the rack 3 upgrade.

Also we're not consistent with the protection. We're not preventing
users from adding cookies. The cookie jar is already flushed,
therefore it doesn't try to change the headers and never triggers the
frozen hash error.
2023-06-11 01:32:31 -07:00
Hartley McGuire
f7c6e2c8aa
Fix duplicate Content-Type header with Rack 2
Previously, `ActionDispatch::Static` would always merge a "content-type"
header into the headers returned from `Rack::Files`. However, this would
potentially lead to both a "Content-Type" header and a "content-type"
header when using Rack 2.

This commit fixes the issue by using `Rack::CONTENT_TYPE` to determine
which version of the header to set in `ActionDispatch::Static`. In both
versions of Rack it will use the same version of the header as
`Rack::Files`.

The tests added have to use `@app.call` instead of
`get()`/`Rack::MockRequest` because `Rack::Response` actually does the
correct thing already by using `Rack::Util::HeaderHash` so it covers up
the issue in tests.
2023-06-09 18:49:37 -04:00
Joé Dupuis
efce114dde Force turbo reload on error.
Turbo frames on turbo-rails 1.4 (current default in Rails 7) don't
break out of the frame to load the error response from the DebugView
middleware like they used to. It requires the turbo-visit-control meta set to reload or it
fails silently.
2023-06-06 22:01:35 -07:00
Andrew Novoselac
37f3ce9930 Create a class level #with_routing helper.
Before each test, the helper creates a new RouteSet instance and yields it to the passed black. The routes are then reset after the test is completed.
2023-06-06 14:13:24 -04:00
Rafael Mendonça França
0e1800396d
Merge pull request #48397 from ThunderKey/improve-mime-regex
improve quoted parameters in mime types
2023-06-05 12:56:17 -04:00
Nicolas Erni
1071a39020 improve quoted parameters in mime types
Accept headers allow parameters to be passed. They can contain quotes
that need to be handled differently. These quoted strings can contain
commas, which are not considered as delimiters of accept headers.

Additionally, all parameters before the q-parameter should be used to
lookup the media-type as well. If no media-type with the parameters is
found, a fallback is introduced to the media-type without any parameters
to keep the same functionality as before.

Fix #48052
2023-06-05 12:53:08 +02:00
Petrik de Heus
a84ef12221
Merge pull request #48383 from p8/fix/link-to-cookies
Fix link to ActionController::Cookies#cookies [ci-skip]
2023-06-02 18:13:54 +02:00
Petrik
f492d51795 Fix link to ActionController::Cookies#cookies
The `cookies` method was not defined on ActionController::Base making the
permalink to the method not work.
Changing it to ActionController::Cookies make the reference a link.
2023-06-02 16:53:38 +02:00
Marek de Heus
39156c8812
Update actionpack/lib/action_controller/metal.rb
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-06-02 15:10:49 +02:00
Marek de Heus
0da0fc8979 Add missing docs for request.session 2023-06-02 15:04:21 +02:00
Jeremy Beker
c34d1f0a68
Base case with our checks last in conditional 2023-05-30 20:49:45 +00:00
Jeremy Beker
d00843aa13
Test case with our checks first in conditional 2023-05-30 20:49:44 +00:00
Jeremy Beker
f1889f139d
Indentation correction via rubocop. 2023-05-30 20:49:41 +00:00
Jason Meller
1904a3031a
Re-order conditional for maybe better perf 2023-05-30 20:48:11 +00:00
Jason Meller
afb847f1b7
Fix spelling error 2023-05-30 20:48:08 +00:00
Jason Meller
1bca0dc586
PR feedback 2023-05-30 20:47:52 +00:00
Jason Meller
4370293a68
Implement PR suggestions 2023-05-30 20:47:30 +00:00
Jason Meller
e388ebe0f2
Attempt to fix rubocop warnings 2023-05-30 20:47:29 +00:00
Jason Meller
a78d3e3207
Enable bind_params option in url_for helper
The url_for helper now supports a new option called `bind_params`.
This is very useful in situations where you only want to add a required
param that is part of the route's URL but for other route not append an
extraneous query param.

Given the following router...
```ruby
Rails.application.routes.draw do
  scope ":account_id" do
    get 'dashboard' => 'pages#dashboard', as: :dashboard
    get 'search/:term' => 'search#search', as: :search
  end
  delete 'signout' => 'sessions#destroy', as: :signout
end
```

And given the following `ApplicationController`
```ruby
  class ApplicationController < ActionController::Base
    def default_url_options
      { bind_params: { account_id: "foo" } }
    end
  end
```

The standard URLHelpers will now behave as follows:

```ruby
dashboard_path # => /foo/dashboard
dashboard_path(account_id: "bar") # => /bar/dashboard
signout_path # => /signout
signout_path(account_id: "bar") # => /signout?account_id=bar
search_path("quin") # => /foo/search/quin
```
2023-05-30 20:47:26 +00:00
Rafael Mendonça França
7eeaadb7fc
Merge pull request #48199 from JoeDupuis/remove-url-rewriter-tests
Remove UrlRewriter tests
2023-05-30 16:03:43 -04:00
Rafael Mendonça França
54de0cb2ee
Merge pull request #48293 from flavorjones/flavorjones-support-html5-sanitizer
Update Action View to use HTML5 standards-compliant sanitizers
2023-05-30 16:00:13 -04:00
zzak
7a014c07e2
Add a tiny more detail about the middleware stack 2023-05-29 16:43:34 +09:00
zzak
2b637b6850
Fix RDoc autolinks in ActionController::Metal 2023-05-29 16:01:00 +09:00
zzak
722d4f6582
Unlink Rails constant from READMEs 2023-05-29 15:14:44 +09:00
zzak
7765a693ee
Fix links for Renderers.add and Renderers.remove 2023-05-29 14:24:10 +09:00
Mike Dalessio
500ccaaeea
Update dependency on rails-html-sanitizer to ~>1.6
for HTML5 sanitizer support
2023-05-28 14:00:35 -04:00
Joé Dupuis
acdfef2097 Remove UrlRewriter tests
UrlRewriter has been deleted in 2010 e68bfaf1fe1a7890a67af6f444281185f507cf9e
The url_rewriter_test is really testing url_for. Most of the tests are
identical.

This also move a couple tests that were not present in
`url_for_test.rb`.
2023-05-27 17:01:21 -07:00
Aaron Patterson
861795ed92
Refactor error highlight detection
Before this commit, some calls to render were hard-coding error
highlight as "not available".  This was causing some error pages to show
the "you should install error highlight" message even though the right
version of error highlight was installed.

This commit adds a delegate method to the DebugView class so that the
debugging related templates can just ask whether or not error highlight
is available via a method call.  That way we don't need to rely on
passing locals everywhere.  The down side is that this change requires
all "rescue" templates to be rendered within the context of a DebugView
class (but I think that's OK)
2023-05-25 09:27:35 -07:00
zzak
073269c9b9
Merge pull request #48288 from zzak/rdoc-fixed-width-namespaces
Use short-form fixed-width RDoc form for namespaces
2023-05-25 07:14:47 +09:00
zzak
e3c73fd183
Replace all occurrences of '<tt>(\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>ActiveRecord::Base</tt> -> +ActiveRecord::Base+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-05-25 06:52:32 +09:00