gpt4 book ai didi

ruby-on-rails - 如何修复 brakeman 生成的 rails 中的危险发送安全警告?

转载 作者:行者123 更新时间:2023-12-02 15:18:46 24 4
gpt4 key购买 nike

我在 Rails 4.2 的应用程序中使用 brakeman 进行安全扫描。它给出了置信度为的报告,警告类型为危险发送。以下是我遇到问题的 Controller 方法:

class AccountsController < ApplicationController
def new
@account_name = Rails.application.config.custom.accounts.send(params[:account_name]).name
@account_logo = Rails.application.config.custom.accounts.send(params[:account_name]).signup_logo
rescue
nil
end
end

请帮帮我。

最佳答案

直接通过用户输入调用方法,即通过 params 属性是危险的安全威胁,为了解决这个问题,我们必须在发送之前将参数列入白名单。

class AccountsController < ApplicationController
def new
method = params[:account_name] || :default_method
if ["method1", "method2", "method3"].include?(method)
@account_name = Rails.application.config.custom.accounts.send(method).name
@account_logo = Rails.application.config.custom.accounts.send(method).signup_logo
end
rescue
nil
end
end

关于ruby-on-rails - 如何修复 brakeman 生成的 rails 中的危险发送安全警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38846180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com