1. Browser visits http://a.com/pages/3?privacy_leaking_param=1
2. User clicks on an outbound link: http://b.com/
3. Browser gets redirected to redirector at:
http://a.com/redirect?canonical_url=http%3A%2F%2Fa.com%2Fpages%2F3&outbound_url=http%3A%2F%2Fb.com%2F
"canonical_url" is set to "http://a.com/pages/3"
"outbound_url" is set to "http://b.com/"
4. Redirector logs the request and redirects browser to canonical_url (i.e. "http://a.com/pages/3)5. Code behind http://a.com/pages/3 checks the referrer to see if it came from the redirector.
5a. If it is, parse the outbound_url from the referrer URL and redirect the browser to that URL.
5b. If it isn't, serve normal content.
Basically, every content page needs to also act as a redirector and only redirects when the referrer indicates that the previous request came from the redirector.
www.example.com/redirect?url=http%3A%2F%2Fwww.example.net
www.example.com/redirect should record url and return 302 with Location set to www.example.net.
Another option would be to link to the real URL, and make a synchronous XHR from JavaScript (to your server) when the link is clicked.
$("a").bind("mousedown", function(e) {
$(this).data("href", $(this).attr("href"));
$(this).attr("href","http://example.com/redirect?url=" + $(this).attr("href"));
});
$("a").bind("mouseup",function(e) {
var el = $(this);
setTimeout(function() {
el.attr("href", el.data("href"));
},10);
});
This works by switching the url when a user clicks a link to your redirect url, then switching it back a fraction of a second after they mouse up. This means that your redirect works even if the user right clicks and opens in a new window / tab and when a user hovers over a link, they still see the normal URL in the status bar.On the /redirect url just log any data you need and send a 301 or 302 redirect. The destination site will see your original page as a referrer, not your redirect url.
Seems like the original link following the `url=` should be processed by encodeURIComponent or else any original urls with chars like ""&" will break.