class SecureCompareRotator

Ruby on Rails 6.1.7.10

Since v6.1.7.10

Available in: v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

The ActiveSupport::SecureCompareRotator is a wrapper around ActiveSupport::SecurityUtils.secure_compare and allows you to rotate a previously defined value to a new one.

It can be used as follow:

rotator = ActiveSupport::SecureCompareRotator.new('new_production_value')
rotator.rotate('previous_production_value')
rotator.secure_compare!('previous_production_value')

One real use case example would be to rotate a basic auth credentials:

class MyController < ApplicationController
  def authenticate_request
    rotator = ActiveSupport::SecureComparerotator.new('new_password')
    rotator.rotate('old_password')

    authenticate_or_request_with_http_basic do |username, password|
      rotator.secure_compare!(password)
    rescue ActiveSupport::SecureCompareRotator::InvalidMatch
      false
    end
  end
end

Inherits from

Object

Includes

Constants

Methods (defined here)

Private methods

(1) Implementation detail — not part of the public API.

Methods (inherited)

From ActiveSupport::SecurityUtils (2)
From Object (17)
From ActiveRecord::TestFixtures (4)
From ActiveSupport::Concern (3)

Type at least 2 characters to search.

↑↓ navigate · open · esc close