Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Here is the problem: I'm trying to make a web based proxy (ie the user doesn't have to add me as their proxy in the browser's settings).

I "absolutize" every link and redirect that link through my script (so that the user won't leave the proxy). But, alas my sole problem is javascript's relative path calls. I reason that there is no way that I can parse through javascript consistently and "absolutize" every link.

Any suggestions on how to absolutize any and all javascript paths in javascript code?

(Yes, I have considered the base tag and itI| not helpful).

Thanks in advance

Replies are listed 'Best First'.
Re: Path Fun
by spudzeppelin (Pilgrim) on Jun 24, 2000 at 00:50 UTC

    Your problem is akin to the following:

    You are trying to prevent the production of cheese by controlling the flow of milk to the producer. However, you have no control over the flow of cows to the producer, nor do you have knowlege/control over whether the producer has cows to begin with. And so you wonder why he can still make cheese....

    Javascript is a programming language executed at the client. It has facilities for manipulating strings and jamming them into URLs. Consequently, there is really NO effective way to guarantee that a client can't be passed a piece of javascript that will generate a URL which will point to a server other than your proxy -- in fact, since http://(long) is valid in many browsers, it is an almost trivial exercise to construct such a workaround. Unless you can control their physical access to the internet (putting the client's IP on a private network, for instance) there is no way you can force a client to use a proxy.

    You could simply have your proxy strip out ALL javascript, but that would have potentially undesirable side effects. And, it would still be no guarantee that the client couldn't be routed around your proxy by a URL generated in, say, a Java applet, or an ActiveX control, or RealPlayer, or one of countless other ways.

    Spud Zeppelin * spud@spudzeppelin.com

Re: Path Fun
by chromatic (Archbishop) on Jun 24, 2000 at 00:19 UTC
    You might be able to keep a cache of pages accessed, indexed by the IP of the requester. (If your proxy is on an intranet, this could work. If it's on the Internet, that'll likely screw things up, as IPs can be non-unique due to NAT, firewalls, or other proxies.)

    If a request comes in with a relative link, just prepend the last accessed request.

    That doesn't seem very robust, and it requires an idealistic situation where you can guarantee that IPs are unique to individual machines. If so, good luck.

    Updated: My esteemed colleague spudzeppelin implies one other thing -- with a web-based proxy, you'd have to scan *everything* in the datastream that might possibly be a link, and prepend your URL. That way lies madness.