Skip to content

Instantly share code, notes, and snippets.

@evanleck
Created February 27, 2016 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanleck/2179d7f101a1a2a3013d to your computer and use it in GitHub Desktop.
Save evanleck/2179d7f101a1a2a3013d to your computer and use it in GitHub Desktop.
/*
* 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