473,791 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10193
Rik
Nosferatum <Jo*********@gm ail.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.comwro te:
Nosferatum <John.Ola...@gm ail.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*********@gm ail.comwrote:
On 15 Mar, 08:27, Rik <luiheidsgoe... @hotmail.comwro te:
>Nosferatum <John.Ola...@gm ail.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.comwro te:
Nosferatum <John.Ola...@gm ail.comwrote:
On 15 Mar, 08:27, Rik <luiheidsgoe... @hotmail.comwro te:
Nosferatum <John.Ola...@gm ail.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*********@gm ail.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_unregis ter() 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
11058
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 (default was 755) then everything works ok. So apparently, the script is running under a different security context even though it's being run via my http session validated via .htaccess. 1) Do I have to be concerned about access to a protected...
0
1580
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 put the file into a .htaccess protected diretory and to build a "proxy" with PHP. I can also put a download limit (after n download per day the script
1
9532
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 put the file into a .htaccess protected diretory and to build a "proxy" with PHP. I can also put a download limit (after n download per day the script
3
1868
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
1975
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 lets me protect directories with htaccess, but this means an already authenticated user must enter credentials a second time in the pop up dialog that appears in the browser window when attempting to download something from an htaccess-protected...
4
1889
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 url was the referrer: http://www.catamarans.com/charter/bareboat/catatonic/?m=cw
7
3875
by: ABC | last post by:
How can I deny all users directly access image files from images folder?
32
4080
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 in the useragent so I can't filter them by that). My main issue is my site is PHP so if they hammer it, it gets all the PHP files executing and overwhelms the CPU. I'd like to be able to after a certain amount of hits on my index.php per second,...
6
2998
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 special page on my server. Only those who access my page from one particulary URL are allowed to see my file. All others are denied. Is it possible to solve this with a .htaccess file, or do I need a php solution?
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.