2016-08-29 26 views
0

我從Brakeman那裏得到這個警告。正如他們所說的那樣,依賴於用戶提供的值的重定向可以用來「欺騙」網站或隱藏惡意鏈接,使其看起來無害。如果目的地未經驗證,它們也可以允許訪問站點的受限區域。Brakeman對Rails,S3,Paperclip無保護的重定向

| Confidence | Class | Method | Warning Type | Message | High | DocumentsController | download | Redirect | Possible unprotected redirect near line 46: redirect_to(+Document.find(params[:id]).f

在我控制我創建了一個方法download,是以文件的URL(文件存儲在Amazon S3和我的數據庫感謝回形針的URL),並創建一個URL(即document_url),將持續3秒(供用戶下載)感謝.expiring_url(3)

def download 
    @document = Document.find(params[:id]) 
    document_url = @document.file.expiring_url(3) 
    if URI.parse(document_url).host.include? "domain.com" 
    redirect_to document_url, only_path: true 
    else 
    document_url = nil 
    end 
end 

我一直在試圖通過司閘員的驗證沒有成功。正如你在上面看到的,我試圖檢查我的域是否存在於URL中,但它沒有改變關於Brakeman的報告。

任何想法如何進行?

回答

0

我有類似的問題。我通過使用下面的強參數傳遞了警告,儘管我不確定它爲什麼有效。

redirect_to referer_param 

def referer_param 
    params.require(:referer) 
end