Apache Server Web directories access restrictions

Multi tool use


Apache Server Web directories access restrictions
I have set up an apache server, hosting a website.
For example In my website you can play with an online javascript atari roms. Whenever you load a rom in the website, the javascript temporarily downloads it to your browsers cache.
If you for example write website.com/roms/atari.zip you can download this rom. I do not want this.
Is there a way to forbid direct access to this file but also whitelisting access from within the javascript requests?
Many thank you in advance.
yes no problem sounds great. but bacuse im a noob how to do this? as you cn see this one neptunjs.xyz/atari.html even though within his javascript you download the game when you go to neptunjs.xyz/roms/atari/E.T. - The Extra-Terrestrial.zip you cant download it.
– immeckro
40 mins ago
1 Answer
1
Requiring Authorization header is one way to do this.
Creating an authentication user:
/path/to/htpasswd -c /etc/htpasswd/.htpasswd downloaduser
And you'd supply the password. Note that the command above will create a new file, overwriting a previous one.
You would configure it in httpd.config like:
<Directory "/var/www/html/roms">
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/etc/htpasswd/.htpasswd"
Require valid-user
</Directory>
Then, with XHR request in javascript,
req.setRequestHeader('Authorization','Basic ' + Base64StringOfUserColonPassword);
base64StringOFUserColonPassword is what the name implies, you can get it like window.btoa(username + ":" + password))
, or with base64
command line command.
window.btoa(username + ":" + password))
base64
Further reading:
Edit: there are xampp specific instructions for example here: http://chandanpatra.blogspot.com/2013/08/basic-authentication-with-htpasswd-in.html. The process is as I outlined for xampp as well.
thank you for all of this but im running apache through xampp on windows..
– immeckro
7 mins ago
@immeckro only part of my answer that is not directly applicable to windows is htpasswd command. you can use web tool like htaccesstools.com/htpasswd-generator-windows instead of command line.
– eis
5 mins ago
@immeckro added xampp-specific link in my answer now
– eis
4 mins ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
you can require a specific request header, which you supply with javascript request, and forbid access without that header. However, if someone knows and provides that header, the file would be accessible with direct link as well. would that be what you want?
– eis
1 hour ago