mohamida
mohamida

Reputation: 804

Avoid loading my js/css files from others sites

I'm developing a Java EE app (JSF + Richfaces + Tomcat).

What I want to do, is to not allow others sites from using my js/css files.

For example, the site www.other-domain.com can use this:

<img src="http://www.my-domain.com/ph/hello.jpg"/>

which i want to avoid it ( it can overload my server)

Is there a way to avoid loading my js/css/photos files to other domains ?

Upvotes: 2

Views: 480

Answers (3)

Piskvor left the building
Piskvor left the building

Reputation: 92752

TL;DR: There is no surefire way to do this (but if you can live with false negatives and false positives, it is doable).

You could serve your JS and CSS through a script, and check if the HTTP request has a Referer field from your domain - this will prevent most of this so-called "hot-linking". If you wanted to be Evil, you could serve a different JS/CSS file instead, e.g. one that shows a "do not hotlink" message - note that this will be displayed to the other site's users, not those who built it.

Note that although most people don't mess with that header, some people turn it off altogether, some AV/firewall suites remove them, and it is trivial to spoof. If it is acceptable for you that some people will see your site as it would look without JS and CSS, you could do this.

Either way, your site will still have to respond to these "hotlinked" requests, so you won't see bandwidth/processing savings right away - you'll only see them after people (hopefully) stop hotlinking to your files (as it will be inconvenient for them).

Upvotes: 2

Erwin
Erwin

Reputation: 639

What is described is so called 'hotlinking' depending if the Apache Tomcat comes with a set of mod_rewrite rules you might want to go for these resources:

Upvotes: 1

Pete Wilson
Pete Wilson

Reputation: 8694

There is no way that works 100%. It's always possible to get your JS/CSS. You can obfuscate it and compress it, but you can't protect it from being copied.

-- pete

Upvotes: 0

Related Questions