Created
February 27, 2016 23:43
-
-
Save evanleck/2179d7f101a1a2a3013d 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 is a naive attempt to protect against transparent proxies. | |
* - We pass the request host and path in from Rack and compare it against what JS sees. | |
* - If they don't match, put them where they should be. | |
* | |
*/ | |
(function(location) { | |
if (location.hostname !== proxyCheck.hostname || location.pathname !== proxyCheck.pathname) { | |
/* Use an anchor tag as a parser. */ | |
var redirectParser = document.createElement('a'); | |
/* Grab the current, browser-side URL */ | |
redirectParser.href = location.href; | |
/* Then munge the hostname, pathname, and port to match the server. */ | |
redirectParser.hostname = proxyCheck.hostname; | |
redirectParser.pathname = proxyCheck.pathname; | |
redirectParser.port = ''; | |
/* And redirect away. */ | |
window.top.location.replace(redirectParser.href); | |
} | |
})(window.location); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment