跳至内容 跳至搜索

Action Dispatch HTTP 过滤器 Parameters

允许您指定要从请求日志中过滤的敏感查询字符串和 POST 参数。

# Replaces values with "[FILTERED]" for keys that match /foo|bar/i.
env["action_dispatch.parameter_filter"] = [:foo, "bar"]

有关过滤器行为的更多信息,请参阅 ActiveSupport::ParameterFilter.

方法
E
F
N
P

类公共方法

new()

# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 24
def initialize
  super
  @filtered_parameters = nil
  @filtered_env        = nil
  @filtered_path       = nil
  @parameter_filter    = nil
end

实例公共方法

filtered_env()

返回 request.env 的哈希值,其中所有敏感数据都被替换。

# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 40
def filtered_env
  @filtered_env ||= env_filter.filter(@env)
end

filtered_parameters()

返回参数的哈希值,其中所有敏感数据都被替换。

# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 33
def filtered_parameters
  @filtered_parameters ||= parameter_filter.filter(parameters)
rescue ActionDispatch::Http::Parameters::ParseError
  @filtered_parameters = {}
end

filtered_path()

使用所有敏感 GET 参数被替换的路径重新构建路径。

# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 45
def filtered_path
  @filtered_path ||= query_string.empty? ? path : "#{path}?#{filtered_query_string}"
end

parameter_filter()

返回用于在此请求中过滤的 ActiveSupport::ParameterFilter 对象。

# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 51
def parameter_filter
  @parameter_filter ||= if has_header?("action_dispatch.parameter_filter")
    parameter_filter_for get_header("action_dispatch.parameter_filter")
  else
    NULL_PARAM_FILTER
  end
end

实例私有方法

env_filter()

# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 60
def env_filter # :doc:
  user_key = fetch_header("action_dispatch.parameter_filter") {
    return NULL_ENV_FILTER
  }
  parameter_filter_for(Array(user_key) + ENV_MATCH)
end

filtered_query_string()

# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 71
def filtered_query_string # :doc:
  parts = query_string.split(/([&;])/)
  filtered_parts = parts.map do |part|
    if part.include?("=")
      key, value = part.split("=", 2)
      parameter_filter.filter(key => value).first.join("=")
    else
      part
    end
  end
  filtered_parts.join("")
end

parameter_filter_for(filters)

# File actionpack/lib/action_dispatch/http/filter_parameters.rb, line 67
def parameter_filter_for(filters) # :doc:
  ActiveSupport::ParameterFilter.new(filters)
end