Commit Graph

8473 Commits

Author SHA1 Message Date
Dirkjan Bussink
ba9207f301
Change the default digest for new apps to SHA256
As mentioned in
https://github.com/rails/rails/pull/40770#issuecomment-748347066 we
should default to SHA256 where SHA1 is used today. This switches over
the ActiveSupport::Digest to use SHA256 for new applications.

It also updates the constants to always refer to and use the OpenSSL
constants as well, as also discussed in that PR.
2021-01-08 12:07:20 +01:00
Dirkjan Bussink
447e28347e
Allow configuration of the digest class used in the key generator
This change allows for configuration of the hash digest that is used in
the key generator for key derivation.

SHA1 is an outdated algorithm and security auditors tend to frown on
its usage. By allowing this to be configured, it becomes possible to
move to a more up to date hash mechanism.

While I don't think this has any current relevant security implications,
especially not with a proper random secret base, moving away from SHA1
makes conversations with auditors and FIPS compliance checks easier
since the best answer is always that an approved algorithm is used.

A rotation can be built using this change with an approach like the
following for encrypted cookies:

```ruby
Rails.application.config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256

Rails.application.config.action_dispatch.cookies_rotations.tap do |cookies|
  salt = Rails.application.config.action_dispatch.authenticated_encrypted_cookie_salt
  secret_key_base = Rails.application.secrets.secret_key_base

  key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000, hash_digest_class: OpenSSL::Digest::SHA1)
  key_len = ActiveSupport::MessageEncryptor.key_len
  secret = key_generator.generate_key(salt, key_len)

  cookies.rotate :encrypted, secret
end
```

This turns the default into using SHA256 but also still accepts secrets
derived using SHA1.

The defaults for new apps is here changed to use SHA256. Existing apps
will keep using SHA1.
2021-01-07 14:28:01 +01:00
Mike Dalessio
76bfda8f72
Remove leading whitespace from the XML under test
This test was originally written with the intention of asserting that
a runtime error related to XXE will be raised by the parser. However,
because initial whitespace is present before the doctype,
XmlMini_NokogiriSAX::HashBuilder has been raising an unrelated error
in this test.

Related to #41015

---

Using Nokogiri v1.10.10, the error being raised without this change
is:

> XML declaration allowed only at the start of the document

but with this change we see the expected exception from the libxml2
SAX parser:

> Entity 'a' not defined

Using Nokogiri v1.11.0, in which error handling is broken (see
sparklemotion/nokogiri#2168), without this change we see an exception
being raised by HashBuilder because `characters` is called before
`start_element` and so the content hash isn't initialized (see

The error being raised with this change is:

> Parse stack not empty!

which is not the error we want (because of
sparklemotion/nokogiri#2168), but the test still passes.

Using Nokogiri with the fix from sparklemotion/nokogiri#2169, the
error being raised without this change is:

> XML declaration allowed only at the start of the document

but with this change will be:

> Entity 'a' not defined

and we're back to the expected behavior.
2021-01-05 22:29:25 -05:00
Ryuta Kamizono
2b0b5a75c0 Bump license years to 2021 [ci skip] 2021-01-01 12:21:20 +09:00
Alec Clarke
f5afc1a5ad Clarify use of rescue_from [ci skip]
`rescue_from` works for rescuing exceptions in controller actions, but it's not specific to ActionController.

This change updates the docs to clarify the specifics of how `rescue_from` is used and that its use goes beyond controller actions.

Note: I believe the original addition of this documentation was added as part of the move from [`ActionController::Rescue` to `ActiveSupport::Rescuable`](259a7a844b (diff-2276a3674b84e1262c94cc36346f9fbd8d00e0a4542bb991a8846c06d86335b1R12))
2020-12-30 11:51:13 -05:00
Rafael França
50073df569
Merge pull request #40929 from ritikesh/redis_info
add ActiveSupport::Cache::RedisCacheStore#info
2020-12-29 14:29:14 -05:00
Ritikesh
c8934f3c02 add stats method on RedisCacheStore similar to MemCacheStore 2020-12-29 13:22:24 +05:30
Rafael França
12a3ac1e08
Merge pull request #40964 from mrpinsky/expires-in-aliases
Support aliases to expires_in for cache stores
2020-12-28 20:34:32 -05:00
Nate Pinsky
fd8c36707f Support aliases to expires_in for cache stores
The `expires_in` option is easy to misremember or mistype as `expire_in`
or `expired_in`, with potentially harmful results. If a developer wants
to cache a value for only 2 seconds but mistakenly types
`expire_in: 2.seconds`, that value will instead be cached for the
default time, likely 6 hours, meaning that users of the site will see
the same data for much longer than they should, and the only recovery
(short of waiting for the 6 hours to elapse) is to manually expire all
relevant keys. This commit allows cache stores to recognize these common
typos as aliases by normalizing them before consuming the options.

In general, we should be careful about adding too many aliases for
options to the cache stores, since each option key used by the base
Cache::Store class is one fewer key that each cache implementation can
customize for itself. This case was approved because of the similarity
of the aliases to the root key and the potential damage caused by
mistaking them.

Fixes #39850.
2020-12-28 17:15:43 -08:00
Rafael Mendonça França
dbf6dbb147
Add CHANGELOG entry for #39626 2020-12-29 00:30:40 +00:00
Rafael França
78bf8f83b2
Merge pull request #39626 from vipulnsward/as-notification-args
Raise error when passing invalid arguments on subscription instead of failing silently
2020-12-28 19:30:02 -05:00
Rafael Mendonça França
e7d207f02f
Change IPAddr#to_json to match the behavior of the json gem
Returning the string representation instead of the instance
variables of the object.

    Before:

    ```ruby
    IPAddr.new("127.0.0.1").to_json
    # => "{\"addr\":2130706433,\"family\":2,\"mask_addr\":4294967295}"
    ```

    After:

    ```ruby
    IPAddr.new("127.0.0.1").to_json
    # => "\"127.0.0.1\""
    ```

Fixes #40932.
2020-12-28 05:46:09 +00:00
John Bampton
9a2b6667e3 Fix spelling 2020-12-27 04:09:49 +10:00
Ivan Giuliani
66f8a2ea7f Include file path in invisible space warning
While the warning is useful in itself, it doesn't tell you what file is
specifically causing the issue which can make resolving it harder than
it should be. As we've got the path already, we can simply include the
location of the problematic file in the warning message.
2020-12-23 10:07:38 +00:00
Ritikesh
5d1eeea84b consume dalli's cache_nils configuration as ActiveSupport::Cache's skip_nil when using MemCacheStore. 2020-12-18 13:10:33 +05:30
Michael Ziwisky
74ab4d930d require "time" where we depend on Time#xmlschema
The docs for Time#xmlschema note "You must require 'time' to use this
method." -- see
https://ruby-doc.org/stdlib-2.7.2/libdoc/time/rdoc/Time.html#method-i-xmlschema

Apparently in most cases, by the time `core_ext/time/conversions.rb` is
loaded, "time" has already been required, however that is not a
guarantee. If it isn't, you'll get a "NameError (undefined method
`xmlschema' for class `Time')". A simple repro is to launch `irb` and
do:

    > require 'active_support'
    > require 'active_support/core_ext/date_time'

This can even happen on some systems with just a:

    > require 'active_support'
    > require 'active_support/core_ext'

That is because `active_support/core_ext.rb` uses `Dir.glob` to
enumerate and then require all ruby files in the `core_ext` directory,
but "the order in which the results are returned [from Dir.glob]
depends on your system" -- see
https://ruby-doc.org/core-2.7.2/Dir.html#method-c-glob

Therefore this commit also sorts those results to make the load order
deterministic and system-agnostic.
2020-12-16 00:50:05 -08:00
T.J. Schuck
fe861bbdd2 Fix code formatting
The `+` is insufficient for the parens inside — needs the full `<tt>` treatment.

[ci skip]
2020-12-15 10:54:26 -05:00
Rafael França
aeea158d95
Merge pull request #40774 from stevecrozz/inflection-locale-defaults-and-fallbacks
Fix :en-GB pluralization test (day -> days)
2020-12-09 13:45:34 -05:00
Stephen Crosby
fc61648249
Fix :en-GB pluralization test (day -> days) 2020-12-09 10:33:20 -08:00
Rafael França
d3ccc920e7
Merge pull request #38659 from stevecrozz/inflection-locale-defaults-and-fallbacks
Inflection support default_locale and fallbacks
2020-12-09 13:30:34 -05:00
Stephen Crosby
ea27ff3d62
Inflection support default_locale and fallbacks 2020-12-09 10:06:05 -08:00
Rafael França
eebde10693
Merge pull request #40759 from orhantoy/broadcast-tagged-logging
Clone to keep extended Logger methods for tagged logger
2020-12-08 14:01:53 -05:00
KapilSachdev
a908d06c85
feat(rubocop): Add Style/RedundantRegexpEscape
- This cop will help in removing unnecessary escaping inside Regexp literals.
2020-12-08 18:57:09 +00:00
Rafael França
ccefd5ce7f
Merge pull request #40201 from Shopify/symbol-name
Use Symbol#name if available in HashWithIndifferentAccess
2020-12-08 13:45:16 -05:00
Orhan Toy
70af536b5d Clone to keep extended Logger methods for tagged logger
`#dup` resets the extended Logger methods that could come from enabling broadcasting. That would mean if we create a tagged logger from a Logger with broadcasting enabled (usually to stdout), the new tagged logger will not perform broadcasting.
2020-12-07 14:43:37 +01:00
Rafael Mendonça França
59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
Rafael França
366df0397f
Merge pull request #40721 from d12/optimize_hash_with_indifferent_access_initializer
55% speedup for HashWithIndifferentAccess.new when no args provided
2020-12-01 14:56:56 -05:00
Nathaniel Woodthorpe
0841cdf268 Optimize HashWithIndifferentAccess.new when no args are provided 2020-12-01 13:25:11 -05:00
Akira Matsuda
6f9d4a000b
Merge pull request #40663 from amatsuda/keep_safe_buffer
Let AS::SafeBuffer#[] and * return value be an instance of SafeBuffer in Ruby 3.0
2020-12-01 17:42:37 +09:00
Akira Matsuda
4cb20843eb Mark scrub as an unsafe method on SafeBuffer 2020-12-01 17:40:17 +09:00
Nathaniel Woodthorpe
f5e5976388 Fix the return value of #deep_transform_keys from a Hash to a HashWithIndifferentAccess 2020-11-30 17:13:53 -05:00
alvir
b96f4ae1d5 Use application time zone when gets time as String. 2020-11-26 11:35:23 +03:00
Bibek Sharma Chapagain
fde2d644b1
Grammer correction on ActiveSupport en.yml 2020-11-22 14:12:26 +11:00
Akira Matsuda
a4d2493b26 Let AS::SafeBuffer#[] and * return value be an instance of SafeBuffer in Ruby 3
Ruby 3 introduces an incompatibility that String methods return String instances when called on a subclass instance.
https://bugs.ruby-lang.org/issues/10845
https://github.com/ruby/ruby/pull/3701
2020-11-21 16:32:18 +09:00
Petrik
332a2909d4 Fix ForkTracker on ruby <= 2.5.3
Making the fork method private by calling `private :fork` raises a
"no superclass method `fork'" error when calling super in a subclass on
ruby <= 2.5.3. The error doesn't occur on ruby 2.5.4 and higher.
Making the method private by redefining doesn't raise the error.

The possible fix on 2.5.4 is 75aba10d7a

The error can be reproduced with the following script on ruby 2.5.3:
```
class Cluster
  def start
    fork { puts "forked!" }
  end
end

module CoreExt
  def fork(*)
    super
  end
end

module CoreExtPrivate
  include CoreExt
  private :fork
end

::Object.prepend(CoreExtPrivate)
Cluster.new.start
```

Fixes #40603
2020-11-17 21:22:12 +01:00
Akshay Birajdar
888d8c7063 [ci skip] Fix rdoc formatting 2020-11-17 18:49:19 +05:30
Jonathan Hefner
b20ac9a1d3 Document Regexp#multiline? [ci-skip]
`Regexp#multiline?` has been publicized in the Active Support Core
Extensions guide for a while now.  This commit adds matching API docs.
2020-11-11 16:03:02 -06:00
Daniel Colson
4e646bb281
Allow subscribing with a single argument callable
Fixes #39976

Prior to this commit it was possible to pass a single argument block to
`ActiveSupport::Notifications.subscribe`, rather than 5 separate
arguments:

```rb
ActiveSupport::Notifications.subscribe('some_event') do |event|
  puts "Reacting to #{event.name}"
end
```

But it was not possible to do the same with a lambda, since the lambda
parameter is a required (`:req`) parameter, but we were checking only
for an optional (`:opt`) parameter.

```rb
listener = ->(event) do
  puts "Reacting to #{event.name}"
end

ActiveSupport::Notifications.subscribe('some_event', &listener)
```

It was also not possible to do this with a custom callable object, since
the custom callable does not respond directly to `:parameters` (although
it's `:call` method object does).

```rb
class CustomListener
  def call(event)
    puts "Reacting to #{event.name}"
  end
end

ActiveSupport::Notifications.subscribe('some_event', CustomListener.new)
```

Prior to this commit these examples would have raised `ArgumentError:
wrong number of arguments (given 5, expected 1)`.

With this commit the single argument lambda and custom callable work
like the single argument block.
2020-11-09 22:26:21 -05:00
Rafael França
e71b4a5e04
Merge pull request #40588 from etiennebarrie/activesupport-currentattributes-testhelper-teardown
Allow access to CurrentAttributes in test teardown
2020-11-09 16:04:42 -05:00
Étienne Barrié
0400be279b Allow access to CurrentAttributes in test teardown 2020-11-09 15:15:42 -05:00
Rafael Mendonça França
0a59de2d2a
Don't require event to be passed to read_entry
This will make sure this method is backward compatible with stores that
don't pass the intrumentation payload to the method.
2020-11-09 20:11:36 +00:00
Rafael França
53e97f0fa0
Merge pull request #40490 from kirs/cache-instrument-store-local
Instrument cache entries from local cache
2020-11-05 16:36:50 -05:00
Kir Shatrov
c88205613b Instrument cache entries from local cache 2020-11-04 23:12:21 +00:00
maxgurewitz
55501549cb disable compression for MemoryStore's by default
- Compression has reduced effectiveness for MemoryStore, which does not
send data over a network.
2020-11-04 12:20:24 -05:00
Eugene Kenny
bc524f16ee
Merge pull request #40517 from eugeneius/depend_on_message
Use LoadError#original_message if available in depend_on
2020-11-03 18:12:24 +00:00
Tahsin Hasan
a52ca5fddc Create unit test to use to_time for timestamp in string 2020-11-03 18:51:43 +06:00
Rafael Mendonça França
8389f9902c
Preparing for 6.1.0.rc1 release 2020-11-02 21:12:47 +00:00
Eugene Kenny
94ab712585 Use LoadError#original_message if available in depend_on
did_you_mean 1.5.0 will add suggestions to `LoadError`. This means that
`LoadError#message` will now return a new string on each invocation, and
mutating the result will no longer modify the error's message.
2020-11-02 20:54:29 +00:00
Rafael Mendonça França
81ee5dcdf4
Merge pull request #39538.
Closes #39538.
2020-11-02 20:42:40 +00:00
Vipul A M
fdfac8760f
Although libraries support both formats of sign before and after DIGITS(ex: https://github.com/moment/luxon/pull/683, https://github.com/moment/moment/issues/2408), many do not.
For example PG refers to https://www.ietf.org/rfc/rfc3339.txt when converting(Ref: https://www.postgresql.org/docs/current/datatype-datetime.html)

According to the ref there is no explicit mention of allowing sign before the parts, which reads as below:

 Durations:

    dur-second        = 1*DIGIT "S"
    dur-minute        = 1*DIGIT "M" [dur-second]
    dur-hour          = 1*DIGIT "H" [dur-minute]
    dur-time          = "T" (dur-hour / dur-minute / dur-second)
    dur-day           = 1*DIGIT "D"
    dur-week          = 1*DIGIT "W"
    dur-month         = 1*DIGIT "M" [dur-day]
    dur-year          = 1*DIGIT "Y" [dur-month]
    dur-date          = (dur-day / dur-month / dur-year) [dur-time]

    duration          = "P" (dur-date / dur-time / dur-week)

We should not attempt to move sign forward in this case.
2020-11-02 20:41:48 +00:00