Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save graste/ac77854b06ef8375d8a1e0938f1a9668 to your computer and use it in GitHub Desktop.
Save graste/ac77854b06ef8375d8a1e0938f1a9668 to your computer and use it in GitHub Desktop.
A Cloudflare worker to redirect image requests from dickhead content scraper's site to a Rick Roll
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request))
})
async function fetchAndApply(request) {
let response = await fetch(request)
let referer = request.headers.get('Referer')
let contentType = response.headers.get('Content-Type') || ''
if (referer && contentType.startsWith('image/')) {
if (new URL(referer).hostname === new URL('https://laptrinhx.com/').hostname) {
return Response.redirect('https://files.troyhunt.com/RickRoll.gif', 302)
}
}
return response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment