...
1)要求がlocalhost
から来るということです。
2)User-Agent
は、aws-sqsd
を含みます。
3)リクエストはワーカーインスタンスでのみ処理する必要があります。
私はbefore_action
のフィルタを使用してこれらをコントローラに適用します。コードは次のようになります。
##
# Protect against abuse - requests must have the correct "User-Agent" header,
# come from localhost, and will only be handled by worker instances.
before_action :correct_user_agent
before_action :correct_source
before_action :worker_instance
...controller code here...
private
##
# Confirms the correct User-Agent header was sent.
def correct_user_agent
return if request.headers.env["HTTP_USER_AGENT"].include?("aws-sqsd")
head(:forbidden)
end
##
# Confirms the request is coming from localhost.
def correct_source
return if request.local? || Rails.env.development? || Rails.env.test?
head(:forbidden)
end
##
# Don't allow requests to be processed in the production web environment, since
# it has a worker instance associated with it.
def worker_instance
return unless Rails.env.production?
head(:forbidden)
end
確かに、要求がPOSTであることを確認できますか? –
@DanielRoseman悪意のあるユーザーの投稿を停止したい – Flash