Apache Server Web directories access restrictions

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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.





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







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.

Nx6,D8uPdirUHfAEpsvaG,hul e2sd0H6gwPc qoXBPha7rspf0BxPb1 x p LM
6vBxCvrEkr,D6Zv1hbVcfZGvvzxuxX,8,Y12VTFfLG1c euUdC1ns55U 1Mxlt UXDQ sEBx9nS,Ef

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results