473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Limit access with referrer/htaccess?

I am in need of a solution on how to solve this problem:

I need to limit access to six different folders. My users are
validated in a system which check their prescence with a couple of
variables in a db and then forwards them if they exist. Based upoen
their status they are redirected to one of six folders.
Users belonging to group A shall get access to folder A, but not B, C
etc. It must be possible to limit access in this order by referrer,
but I really don't knwo how to do this. Perhaps in a combination with
a .htaccess file?
Right now it's not a big deal for for.example users from group C to
explore the folders belonging to group A,B,D etc. And that's my big
problem, since each folder should be accessible to ONLY one group.

Anyone with any idea? Code?

Mar 15 '07 #1
5 10171
Rik
Nosferatum <Jo*********@gmail.comwrote:
I am in need of a solution on how to solve this problem:

I need to limit access to six different folders. My users are
validated in a system which check their prescence with a couple of
variables in a db and then forwards them if they exist. Based upoen
their status they are redirected to one of six folders.
Users belonging to group A shall get access to folder A, but not B, C
etc. It must be possible to limit access in this order by referrer,
but I really don't knwo how to do this. Perhaps in a combination with
a .htaccess file?
Right now it's not a big deal for for.example users from group C to
explore the folders belonging to group A,B,D etc. And that's my big
problem, since each folder should be accessible to ONLY one group.
Do _NOT_ use referer for this. If there's something that is easily forged
it's that. I'm not entirely clear what you mean by 'folders'. Do you mean
they can simply get to the contents? You say the users are validated, so
let's say a session is started, ad you;ve saved a variable like
$_SESSION['group'] = 'A'. Now check in folder 'A' wether they belong to
this group, and refuse access to them if this isn't the case. In a
..htaccess file this isn't possible. I'd force a single point of entry in
the folder, which checks this value, sends a forbidden header and exits if
they aren't validated or belong to the wrong group. If they are valid
visitors, let it continue and serve the requested files.
--
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel
Mar 15 '07 #2
On 15 Mar, 08:27, Rik <luiheidsgoe...@hotmail.comwrote:
Nosferatum <John.Ola...@gmail.comwrote:
I am in need of a solution on how to solve this problem:
I need to limit access to six different folders. My users are
validated in a system which check their prescence with a couple of
variables in a db and then forwards them if they exist. Based upoen
their status they are redirected to one of six folders.
Users belonging to group A shall get access to folder A, but not B, C
etc. It must be possible to limit access in this order by referrer,
but I really don't knwo how to do this. Perhaps in a combination with
a .htaccess file?
Right now it's not a big deal for for.example users from group C to
explore the folders belonging to group A,B,D etc. And that's my big
problem, since each folder should be accessible to ONLY one group.

Do _NOT_ use referer for this. If there's something that is easily forged
it's that. I'm not entirely clear what you mean by 'folders'. Do you mean
they can simply get to the contents? You say the users are validated, so
let's say a session is started, ad you;ve saved a variable like
$_SESSION['group'] = 'A'. Now check in folder 'A' wether they belong to
this group, and refuse access to them if this isn't the case. In a
.htaccess file this isn't possible. I'd force a single point of entry in
the folder, which checks this value, sends a forbidden header and exits if
they aren't validated or belong to the wrong group. If they are valid
visitors, let it continue and serve the requested files.
--
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions:http://tinyurl.com/anel
But I thought that limiting one special url as referrer and deny
everybody else in .htaccess in the target folder was the most secure
way to solve this?
Like:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?my-domain-here.com/the-
folder/the-only-allowed-page.php [NC]
RewriteRule (.*) http://www.my-domain-here.com/path/to/redirect/
Mar 15 '07 #3
Rik
Nosferatum <Jo*********@gmail.comwrote:
On 15 Mar, 08:27, Rik <luiheidsgoe...@hotmail.comwrote:
>Nosferatum <John.Ola...@gmail.comwrote:
I am in need of a solution on how to solve this problem:
I need to limit access to six different folders. My users are
validated in a system which check their prescence with a couple of
variables in a db and then forwards them if they exist. Based upoen
their status they are redirected to one of six folders.
Users belonging to group A shall get access to folder A, but not B,C
etc. It must be possible to limit access in this order by referrer,
but I really don't knwo how to do this. Perhaps in a combination with
a .htaccess file?
Right now it's not a big deal for for.example users from group C to
explore the folders belonging to group A,B,D etc. And that's my big
problem, since each folder should be accessible to ONLY one group.

Do _NOT_ use referer for this. If there's something that is easily
forged
it's that.

But I thought that limiting one special url as referrer and deny
everybody else in .htaccess in the target folder was the most secure
way to solve this?
Like:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?my-domain-here.com/the-
folder/the-only-allowed-page.php [NC]
RewriteRule (.*) http://www.my-domain-here.com/path/to/redirect/
No, it isn't. I can still access that page directly without ever being on
'the-only-allowed-page.php'. The 'referer' is just a header browsers may
or may not send (I usually don't send one, and many firewalls block it),
with arbitrary data the current UA deems fit for it. Fun for statistics
(allthough there is something called referer-spam), totally unsuited for
security.

If you want this for security, you might as well ask a user directly:'Are
you a registered user (yes/no)?', and trust their answer without question.

To give you an example:
$handle = fsockopen('www.example.com',80);
$request = "GET /your/secured/folder/ HTTP/1.1\r\nHost:
www.example.com\r\nReferer:
http://www.example.com/i/just/claim/...r\nConnection:
close\r\n\r\n";
fwrite($handle,$request);
while (!feof($handle)) {
echo fgets($handle);
}
--
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel
Mar 15 '07 #4
On 15 Mar, 09:33, Rik <luiheidsgoe...@hotmail.comwrote:
Nosferatum <John.Ola...@gmail.comwrote:
On 15 Mar, 08:27, Rik <luiheidsgoe...@hotmail.comwrote:
Nosferatum <John.Ola...@gmail.comwrote:
I am in need of a solution on how to solve this problem:
I need to limit access to six different folders. My users are
validated in a system which check their prescence with a couple of
variables in a db and then forwards them if they exist. Based upoen
their status they are redirected to one of six folders.
Users belonging to group A shall get access to folder A, but not B, C
etc. It must be possible to limit access in this order by referrer,
but I really don't knwo how to do this. Perhaps in a combination with
a .htaccess file?
Right now it's not a big deal for for.example users from group C to
explore the folders belonging to group A,B,D etc. And that's my big
problem, since each folder should be accessible to ONLY one group.
Do _NOT_ use referer for this. If there's something that is easily
forged
it's that.
But I thought that limiting one special url as referrer and deny
everybody else in .htaccess in the target folder was the most secure
way to solve this?
Like:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?my-domain-here.com/the-
folder/the-only-allowed-page.php [NC]
RewriteRule (.*)http://www.my-domain-here.com/path/to/redirect/

No, it isn't. I can still access that page directly without ever being on
'the-only-allowed-page.php'. The 'referer' is just a header browsers may
or may not send (I usually don't send one, and many firewalls block it),
with arbitrary data the current UA deems fit for it. Fun for statistics
(allthough there is something called referer-spam), totally unsuited for
security.

If you want this for security, you might as well ask a user directly:'Are
you a registered user (yes/no)?', and trust their answer without question.

To give you an example:
$handle = fsockopen('www.example.com',80);
$request = "GET /your/secured/folder/ HTTP/1.1\r\nHost: www.example.com\r\nReferer: http://www.example.com/i/just/claim/...r\nConnection:
close\r\n\r\n";
fwrite($handle,$request);
while (!feof($handle)) {
echo fgets($handle);}

--
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions:http://tinyurl.com/anel- Skjul sitert tekst -

- Vis sitert tekst -
Oh, I get your point. Thanks for stopping me from doing something
really stupid... :-) (*blush*)
I have to learn how to use sessions.

By the way: Is it advicable to add a session unregister event upon
page leave, or timeout?

Mar 15 '07 #5
Rik
Nosferatum <Jo*********@gmail.comwrote:
Oh, I get your point. Thanks for stopping me from doing something
really stupid... :-) (*blush*)
I have to learn how to use sessions.

By the way: Is it advicable to add a session unregister event upon
page leave, or timeout?
Well, session_unregister() doesn't have to be used anymore.

If you're users can be bothered to click a logout button, by all means
destory the session immediately on that logout page. Most of your users
won't bother, so set the timeout on sessions to something that suits you
so they will be trashed by the garbage collector. Keep in mind that simply
having a started session doesn't mean it's valid, keep track of valid
sessions by either a $_SESSION variable or possibly a file/database/etc.

--
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel
Mar 15 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JW | last post by:
I have a directory protected with .htaccess / .htpasswd. After I'm validated, I run a php script which bombs out when trying to write a file to that directory. If I chmod 777 on the directory...
0
by: Nicolas C. | last post by:
Hello, I'd like to make some download speed limitation on some of my files using PHP. I know that an Apache module can do that, but i cannot access my ISP Apache configuration. My idea was to...
1
by: Nicolas C. | last post by:
Hello, I'd like to make some download speed limitation on some of my files using PHP. I know that an Apache module can do that, but i cannot access my ISP Apache configuration. My idea was to...
3
by: mrbog | last post by:
As a security measure, I'd like .php files to only execute on my web site if they're owned by a certain user. (Linux server). Can I do that?
12
by: deko | last post by:
I have a login script that creates a SESSION for authenticated users. But authenticated users still need access to particular directories (which contain files for download). My hosting provider...
4
by: jason | last post by:
Hi Guys, I have an interesting challenge: We are about to begin building magazine adverts with specific query string urls attached to a particular boat page which let us know which magazine...
7
by: ABC | last post by:
How can I deny all users directly access image files from images folder?
32
by: Nu | last post by:
I want to protect myself from if someone with a fast connection hammers my site. It's not denial of service attacks, but offline downloaders (of course that don't show they're offline downloaders...
6
by: Nosferatum | last post by:
Hi, on my Apache server I want to limit access to a certain file ouput (from php/MySQL) to just one IP. The idea is that users from another site should click a link whic redirects them to my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.