0
我提出以下POST請求some_action
在ApiController
:如何過濾掉POST請求的所有參數?
HTTParty.post('https://example.com/api/some_action.json?token=foo',
headers: {'Content-Type' => 'application/json'},
body: {some_key: 'some_value'}.to_json
)
我試圖篩選出提交正文的內容,因爲它包含敏感信息。然而,我的日誌中寫道:
Started POST "/api/some_action.json?token=[FILTERED]" for 127.0.0.1 at 2016-11-28 12:30:32 +0100
Processing by ApiController#some_action as JSON
Parameters: {"some_key"=>"[FILTERED]", "token"=>"[FILTERED]", "api"=>{"some_key"=>"[FILTERED]"}}
當我想到PARAMS我得到的PARAMS我得到:
def some_action
Rails.logger.error params
# => {"some_key"=>"some_value", "token"=>"foo", "controller"=>"api", "action"=>"some_action", "format"=>"json", "api"=>{"some_key"=>"some_value"}}
end
似乎有一個多餘的PARAM稱爲api
,我想指的是控制器名稱。但我無法過濾它。我可以過濾some_key參數,但不是整個api
參數。任何想法如何過濾api
以及如何避免在日誌中寫入兩次參數?我曾嘗試以下沒有成功:
config.filter_parameters += [:api, :some_key]