Sha256: 42f3e561d56c3da3605a60963e962f612049cf30a43380f436393a6731940f92

Contents?: true

Size: 725 Bytes

Versions: 22

Compression:

Stored size: 725 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 upsample).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

22 entries across 22 versions & 1 rubygems

Version Path
alchemy_cms-3.6.7 lib/alchemy/picture_attributes.rb
alchemy_cms-3.6.6 lib/alchemy/picture_attributes.rb
alchemy_cms-3.6.5 lib/alchemy/picture_attributes.rb
alchemy_cms-3.6.4 lib/alchemy/picture_attributes.rb
alchemy_cms-3.6.3 lib/alchemy/picture_attributes.rb
alchemy_cms-3.6.2 lib/alchemy/picture_attributes.rb
alchemy_cms-3.6.1 lib/alchemy/picture_attributes.rb
alchemy_cms-4.0.0.beta lib/alchemy/picture_attributes.rb
alchemy_cms-3.6.0 lib/alchemy/picture_attributes.rb
alchemy_cms-3.5.0 lib/alchemy/picture_attributes.rb
alchemy_cms-3.4.2 lib/alchemy/picture_attributes.rb
alchemy_cms-3.5.0.rc2 lib/alchemy/picture_attributes.rb
alchemy_cms-3.5.0.rc1 lib/alchemy/picture_attributes.rb
alchemy_cms-3.4.1 lib/alchemy/picture_attributes.rb
alchemy_cms-3.3.3 lib/alchemy/picture_attributes.rb
alchemy_cms-3.3.2 lib/alchemy/picture_attributes.rb
alchemy_cms-3.4.0 lib/alchemy/picture_attributes.rb
alchemy_cms-3.4.0.rc1 lib/alchemy/picture_attributes.rb
alchemy_cms-3.3.1 lib/alchemy/picture_attributes.rb
alchemy_cms-3.3.0 lib/alchemy/picture_attributes.rb