Sha256: b04fe8dc7863f645bef3d835530e6b3de96a4f77cae9281c64afd09ad10a7ad2

Contents?: true

Size: 719 Bytes

Versions: 9

Compression:

Stored size: 719 Bytes

Contents

module Alchemy
  # Provides methods to secure your picture attributes against DOS attacks.
  #
  class PictureAttributes

    SECURE_ATTRIBUTES = %w(id size crop crop_from crop_size quality).freeze

    class << self

      # Secures given attributes
      #
      # @param attributes [Hash]
      # @return [String]
      #
      def secure(attributes)
        Digest::SHA1.hexdigest(joined_attributes(attributes))[0..15]
      end

      private

      # Takes attributes and joins them with the +security_token+ of your rails app.
      #
      def joined_attributes(attributes)
        attributes.stringify_keys.values_at(*SECURE_ATTRIBUTES, Rails.configuration.secret_token).join('-')
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
alchemy_cms-3.0.4 lib/alchemy/picture_attributes.rb
alchemy_cms-3.0.3 lib/alchemy/picture_attributes.rb
alchemy_cms-3.0.2 lib/alchemy/picture_attributes.rb
alchemy_cms-3.0.1 lib/alchemy/picture_attributes.rb
alchemy_cms-3.0.0 lib/alchemy/picture_attributes.rb
alchemy_cms-3.0.0.rc8 lib/alchemy/picture_attributes.rb
alchemy_cms-3.0.0.rc7 lib/alchemy/picture_attributes.rb
alchemy_cms-3.0.0.rc6 lib/alchemy/picture_attributes.rb
alchemy_cms-3.0.0.rc5 lib/alchemy/picture_attributes.rb