HACKER Q&A
📣 elashri

How to Restrict Webpage Access with JavaScript Enabled Browsers


How can we prevent access to a webpage server-side if the browser has JavaScript enabled? I'm not asking for any specific or realistic reason, but rather as an interesting thought experiment to explore potential server-side solutions. So what would you do if you want to achieve that?


  👤 austin-cheney Accepted Answer ✓
If it's a normal page accessed from the public you cannot. The reason is because the client is completely unknown and anonymous to the server. Therefore the server cannot trust or make assumptions upon the security or state of the client.

The best you could hope for is to impose some manner of authentication scheme so that the client and server are known and uniquely identified to each other at each page request irrespective of session. Then and only then are all options on the table.

This becomes not trivial, but easily accomplished, if the browser were requesting the page from a localhost server.


👤 LinuxBender
One method I have seen on hobby sites is to use JavaScript to replace the contents of the page with obnoxious flashy seizure inducing effects. Hats off to 4chan... Maybe don't do that but I think one could replace the contents of the page with a message saying that JS must be disabled to access.

👤 salawat
Any answer to this question is ultimately going to end in an answer that ties into WEI, which is anti-user as all get out.

Therefore, this request for pondering is summarily denied!

422


👤 flaptrap
Can we count the ways...just look around the web. Start with msn and linkedin which now merrily spin in my browser but never show any content.