Created
August 19, 2020 07:41
-
-
Save troyhunt/bc89905862398ce0d2984858a9f3a8b5 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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