FIX: Cache failed onebox URL request server-side (#8421)

We already cache failed onebox URL requests client-side, we now want to cache this on the server-side for extra protection. failed onebox previews will be cached for 1 hour, and any more requests for that URL will fail with a 404 status. Forcing a rebake via the Rebake HTML action will delete the failed URL cache (like how the oneboxer preview cache is deleted).
This commit is contained in:
Martin Brennan
2019-11-28 07:48:29 +10:00
committed by GitHub
parent e7c7a05097
commit 901054fd75
4 changed files with 50 additions and 4 deletions

View File

@@ -19,6 +19,8 @@ class OneboxController < ApplicationController
invalidate = params[:refresh] == 'true'
url = params[:url]
return render(body: nil, status: 404) if Oneboxer.recently_failed?(url)
hijack do
Oneboxer.preview_onebox!(user_id)
@@ -34,6 +36,7 @@ class OneboxController < ApplicationController
Oneboxer.onebox_previewed!(user_id)
if preview.blank?
Oneboxer.cache_failed!(url)
render body: nil, status: 404
else
render plain: preview