.htaccess question

tkerns used Ask the Experts™
Hi.  I have a cgi written in perl, that is accessing (opening/ writing to etc) a file in a directory called 'data'.  That directory is protected by htaccess.  I have noticed that that I get the password prompt when I try to access that directory via http, but when a cgi that is outside the 'data' directory accesses a file in 'data' I get no password prompt, and it retrieves the file.
Is this a problem inherent to .htaccess?  Or is there someway that I can protect the files in the 'data' directory from being accesses from a cgi that resides outside of it.
I realize I can just move the cgi into the 'data' dir, but I would like to avoid doing that.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You're right. .htaccess manages the access via your webbrowser. The cgi program is a normal program and can access all files a normal program can use.

However you can modify your cgi program so it can't access the protected file within your data directory. Or just delete the cgi? Do you need the cgi file? Maybe you can insert a authentication method into the cgi ...


Thanks.  I thought that might be the case, but wasnt sure... I had hoped htaccess managed all access...  I will probably just move the cgi into the protected directory, to control access.
I will accept your comment as an answer.
Have a great day!

You could access the files in your data directory from your cgi script via a HTTP request using the LWP module, rather than direct access via the filesystem.
( http://www.perldoc.com/perl5.6.1/lib/LWP.html )

This would mean that any requests to get the datafile from your cgi script would be subject to htaccess security, exactly the same as when you access the data directory via a browser. LWP also supports HTTPS requests if required.
The downside of this approach is that the overhead of an HTTP request makes access times much slower.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial