Last active
September 20, 2021 17:37
-
-
Save bemobtrk/1e36fdd2334888a232e46e6bb71e2c8d to your computer and use it in GitHub Desktop.
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
<!-- THIS METHOD IS VERY INSECURE, USE IT IF NO OTHER OPTIONS IS AVAILABLE --> | |
<!-- Paste this code to head section --> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script> | |
<script> | |
function check(secretKey, ttl, signature) { | |
try { | |
let sign = atob(signature); | |
sign = JSON.parse(sign); | |
if (!sign.timestamp || !sign.hash) return false; | |
const signedHash = CryptoJS.HmacSHA1(sign.timestamp, secretKey).toString(); | |
if (signedHash !== sign.hash || sign.timestamp < (((new Date().getTime() / 1000) | 0) - ttl).toString()) return false; | |
return true; | |
} catch (err) { | |
return false; | |
} | |
} | |
const secretKey = 'PASTE_HERE_YOUR_SECRET_KEY'; // Your secret key | |
const fallbackUrl = 'https://www.google.com/'; // Redirect URL for users who didn't pass the check | |
const ttl = 60; | |
const signature = new URL(document.location.href).searchParams.get('key'); | |
if(!check(secretKey, ttl, signature)) | |
document.location.href = fallbackUrl; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment