Live data from Hacker News

Wondering what to do (if anything) about hotlinking

kryogenix.org

1–10 of 49 posts

Re: Wondering what to do (if anything) about hotlinking

#3
Can't you disallow external links that will redirect to a dynamic error page?

Things like HTTP Referrer, coupled with a set of rolling dynamic headers so actual site visitors aren't impacted, or significant rate limiting, or a simple non-malicious HTTP widget injection that sends a simple message, stop the unauthorized hotlinking.

You could even take it a step further by evaluating at the packet header level but that's a bit of a setup.

Re: Wondering what to do (if anything) about hotlinking

#4
> It’s a bit of an anti-social practice, to be honest

Isn't so-called "hot" linking an intended and useful feature of the web? Linking to something directly so that you don't need to copy it to a new server and pollute the URL space with duplicate objects?

Maybe someone can invent a way of caching or replicating web content so it doesn't overload the original server and its internet connection. There might even be a business opportunity, "Caching Distribution Nodes" or something....

> There are many CDNs, and using resources served from them is not a bad thing. That’s not what I’m talking about

I see.

That being said, I like the idea of hierarchical URLs that could address anything on a web page, including items that are linked from elsewhere. Maybe something like:

https://example.org/page.html/resourcename.ext

Then you could easily reference a page where the original item is located, and browsers could easily go there.

Re: Wondering what to do (if anything) about hotlinking

#5
post #2

HTTP header checks? In script check if window.location is not your site? I’m surprise CORS did not put an end to this.

CORS is not a magic blocking mechanism.

The same origin policy restricts any load that would provide JS with data from a different origin. Note that I did not say it blocks all loads: this is specifically restricting JS access to content from other services. CORS was introduced so that it was possible to selectively provide JS with access to such data - previously you had to use JSONP which has bad security properties for the client and server. CORS is what lets JS on your site make an XHR to a remote API provider. Nothing stops you from simply creating an arbitrary element with an arbitrary src attribute (if relevant of course), and triggering a network load. It’s just that most such elements don’t convert the server response into data that can be subsequently accessed in JS, the ones that do (img, etc) can only be read via APIs that themselves enforce same origin restrictions (eg I can create an image element and point it to a remote server, then draw that image into a canvas. At that point the canvas element’s various read APIs will stop working as the canvas knows that it’s been tainted).

If you were to make non-same origin loads fail in the general case you would break everything.

Re: Wondering what to do (if anything) about hotlinking

#6
post #3

Can't you disallow external links that will redirect to a dynamic error page? Things like HTTP Referrer, coupled with a set of rolling dynamic headers so actual site visitors aren't impacted, or significant rate limiting, or a simple non-malicious HTTP widget injection that sends a simple message, stop the unauthorized hotlinking. You could even take it a step further by evaluating at the packet header level but that…

In general the "best" solution here is to have URLs with a time-limited token. S3 and the likes make this pretty easy to set up, but there's no reason you couldn't roll your own solution.

Re: Wondering what to do (if anything) about hotlinking

#7
post #4

> It’s a bit of an anti-social practice, to be honest Isn't so-called "hot" linking an intended and useful feature of the web? Linking to something directly so that you don't need to copy it to a new server and pollute the URL space with duplicate objects? Maybe someone can invent a way of caching or replicating web content so it doesn't overload the original server and its internet connection. There might even be a…

I read your comment and I thought this was going to be about "links"... but it isn't: it is about embedded resources like scripts or stylesheets. I am with the author on this one: it is really annoying and definitely "anti-social".

I've had people do this to me and then I go to update my stylesheet on my website and suddenly a ton of other websites I use are broken and I was like "wtf". After trying to get people to stop directly embedding it and realizing the problem was just too widespread, I ended up having to freeze an old copy of my stylesheet at the fixed URL that everyone was using and now I generate random URLs for my new stylesheet updates (that both look like something you shouldn't rely on and which do disappear later).

(FWIW, I will say that the random URLs are probably a better solution anyway as if you are going to have a stylesheet used by various pages of yours it is difficult to do an atomic upgrade of the resource and the pages that use it without momentarily breaking some content. My "random" URLs are actually hashes and it is honestly better than what I had before.)

Re: Wondering what to do (if anything) about hotlinking

#8
Instead of a nasty console message or popup, modify the script to ping back more detailed and useful information about where its being used. Then contact the developers.

Edit: you don't even need to write anything dynamic to receive the ping back, just have the script load an image from yoursite.com/specialprefix/the useresencodedbrowserurl/anythingelseinteresting/1.png then look in your server logs for any 404 errors with the prefix?

Re: Wondering what to do (if anything) about hotlinking

#9
The article proposes one solution as being to essentially serve up different content to whoever is hotlinking the script, but then says "Obviously, I don't wanna do this." It seems like the clearest solution to me, so I don't know why it's a bad option.

The replacement solution worked for 3D Realms many years ago after a bunch of journalists, fansites, and forums would link to their game screenshots. When someone did, their image would be replaced with Duke Nukem dressed up as Uncle Sam, pointing at the screen, and captioned with something like "Duke wants you to host your own images"

Re: Wondering what to do (if anything) about hotlinking

#10
post #4

> It’s a bit of an anti-social practice, to be honest Isn't so-called "hot" linking an intended and useful feature of the web? Linking to something directly so that you don't need to copy it to a new server and pollute the URL space with duplicate objects? Maybe someone can invent a way of caching or replicating web content so it doesn't overload the original server and its internet connection. There might even be a…

> Linking to something directly so that you don't need to copy it to a new server and pollute the URL space with duplicate objects?

1. Only if bandwidth is free. Which is not the case if you're sufficiently popular.

2. It makes you responsible for other people's web sites working correctly. Would you personally like to have that burden? The original article's poster isn't too happy about it.

3. It's bad practice because if the original host does not care about other people's web sites working correctly, who knows what your viewers will download next time? Perhaps a new and improved version that includes a bitcoin miner? Ok that's out of fashion. Perhaps a 0day exploit then?

4. Even if no bitcoin miner or 0day exploit, you're allowing a 3rd party to interact with your viewer. This is a privacy risk if you hotlink from the likes of Google or Facebook isn't it?

Post reply on HN