1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Convert remaining usage of whitelist and blacklist

This commit is contained in:
Kevin Deisz 2018-08-24 16:16:41 -04:00
parent cac2bb7f44
commit 0efecd913c
No known key found for this signature in database
GPG key ID: D78C2D8FB232C59C
5 changed files with 14 additions and 14 deletions

View file

@ -86,7 +86,7 @@ module ActionController
# Note: SSEs are not currently supported by IE. However, they are supported # Note: SSEs are not currently supported by IE. However, they are supported
# by Chrome, Firefox, Opera, and Safari. # by Chrome, Firefox, Opera, and Safari.
class SSE class SSE
WHITELISTED_OPTIONS = %w( retry event id ) PERMITTED_OPTIONS = %w( retry event id )
def initialize(stream, options = {}) def initialize(stream, options = {})
@stream = stream @stream = stream
@ -111,7 +111,7 @@ module ActionController
def perform_write(json, options) def perform_write(json, options)
current_options = @options.merge(options).stringify_keys current_options = @options.merge(options).stringify_keys
WHITELISTED_OPTIONS.each do |option_name| PERMITTED_OPTIONS.each do |option_name|
if (option_value = current_options[option_name]) if (option_value = current_options[option_name])
@stream.write "#{option_name}: #{option_value}\n" @stream.write "#{option_name}: #{option_value}\n"
end end

View file

@ -553,10 +553,10 @@ module ActionDispatch
# #
# match 'json_only', constraints: { format: 'json' }, via: :get # match 'json_only', constraints: { format: 'json' }, via: :get
# #
# class Whitelist # class PermitList
# def matches?(request) request.remote_ip == '1.2.3.4' end # def matches?(request) request.remote_ip == '1.2.3.4' end
# end # end
# match 'path', to: 'c#a', constraints: Whitelist.new, via: :get # match 'path', to: 'c#a', constraints: PermitList.new, via: :get
# #
# See <tt>Scoping#constraints</tt> for more examples with its scope # See <tt>Scoping#constraints</tt> for more examples with its scope
# equivalent. # equivalent.

View file

@ -24,16 +24,16 @@ module ActiveJob
module Arguments module Arguments
extend self extend self
# :nodoc: # :nodoc:
TYPE_WHITELIST = [ NilClass, String, Integer, Float, BigDecimal, TrueClass, FalseClass ] PERMITTED_TYPES = [ NilClass, String, Integer, Float, BigDecimal, TrueClass, FalseClass ]
# Serializes a set of arguments. Whitelisted types are returned # Serializes a set of arguments. Permitted types are returned
# as-is. Arrays/Hashes are serialized element by element. # as-is. Arrays/Hashes are serialized element by element.
# All other types are serialized using GlobalID. # All other types are serialized using GlobalID.
def serialize(arguments) def serialize(arguments)
arguments.map { |argument| serialize_argument(argument) } arguments.map { |argument| serialize_argument(argument) }
end end
# Deserializes a set of arguments. Whitelisted types are returned # Deserializes a set of arguments. Permitted types are returned
# as-is. Arrays/Hashes are deserialized element by element. # as-is. Arrays/Hashes are deserialized element by element.
# All other types are deserialized using GlobalID. # All other types are deserialized using GlobalID.
def deserialize(arguments) def deserialize(arguments)
@ -64,7 +64,7 @@ module ActiveJob
def serialize_argument(argument) def serialize_argument(argument)
case argument case argument
when *TYPE_WHITELIST when *PERMITTED_TYPES
argument argument
when GlobalID::Identification when GlobalID::Identification
convert_to_global_id_hash(argument) convert_to_global_id_hash(argument)
@ -88,7 +88,7 @@ module ActiveJob
case argument case argument
when String when String
GlobalID::Locator.locate(argument) || argument GlobalID::Locator.locate(argument) || argument
when *TYPE_WHITELIST when *PERMITTED_TYPES
argument argument
when Array when Array
argument.map { |arg| deserialize_argument(arg) } argument.map { |arg| deserialize_argument(arg) }

View file

@ -31,7 +31,7 @@ module ActiveRecord
end end
} }
BLACKLISTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass) RESTRICTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass)
class GeneratedAttributeMethods < Module #:nodoc: class GeneratedAttributeMethods < Module #:nodoc:
include Mutex_m include Mutex_m
@ -123,7 +123,7 @@ module ActiveRecord
# A class method is 'dangerous' if it is already (re)defined by Active Record, but # A class method is 'dangerous' if it is already (re)defined by Active Record, but
# not by any ancestors. (So 'puts' is not dangerous but 'new' is.) # not by any ancestors. (So 'puts' is not dangerous but 'new' is.)
def dangerous_class_method?(method_name) def dangerous_class_method?(method_name)
BLACKLISTED_CLASS_METHODS.include?(method_name.to_s) || class_method_defined_within?(method_name, Base) RESTRICTED_CLASS_METHODS.include?(method_name.to_s) || class_method_defined_within?(method_name, Base)
end end
def class_method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc: def class_method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc:

View file

@ -5,7 +5,7 @@ require "models/post"
require "models/comment" require "models/comment"
module ActiveRecord module ActiveRecord
module DelegationWhitelistTests module DelegationPermitListTests
ARRAY_DELEGATES = [ ARRAY_DELEGATES = [
:+, :-, :|, :&, :[], :shuffle, :+, :-, :|, :&, :[], :shuffle,
:all?, :collect, :compact, :detect, :each, :each_cons, :each_with_index, :all?, :collect, :compact, :detect, :each, :each_cons, :each_with_index,
@ -38,7 +38,7 @@ module ActiveRecord
end end
class DelegationAssociationTest < ActiveRecord::TestCase class DelegationAssociationTest < ActiveRecord::TestCase
include DelegationWhitelistTests include DelegationPermitListTests
include DeprecatedArelDelegationTests include DeprecatedArelDelegationTests
def target def target
@ -47,7 +47,7 @@ module ActiveRecord
end end
class DelegationRelationTest < ActiveRecord::TestCase class DelegationRelationTest < ActiveRecord::TestCase
include DelegationWhitelistTests include DelegationPermitListTests
include DeprecatedArelDelegationTests include DeprecatedArelDelegationTests
def target def target