Jump to content

Recommended Posts

Was looking for a starting point on protecting our site.

What we need:

If someone comes to our site (directly, or by click) to force them to goto https://site.com/

UNLESS

The refurrel is from itself (site.com) or approved domains (subdomain.site.com, subdomain.site2.com)/IPs (10.1.1.1,5.5.5.1)

 

Make sense?

 

Thanks for helping out.

Link to comment
https://forums.phpfreaks.com/topic/286774-referral-locking/
Share on other sites

General redirect for HTTPS only:

if ($_SERVER['HTTPS']!="on") {
   header("location: https://site.com");
}



I am not a security expert; I don't know if this ($_SERVER['HTTPS']) can be faked.

For the rest, it's a tad more complex.  You would probably want an array of approved IP's, and an array of approved domains.  You could check the IPs with an in_array() call against $_SERVER['REMOTE_ADDR'].  Since they could be coming from a presumably large number of pages on the "approved sites" list, you'd probably need to loop through that array and do something like stristr() for each value (I'm hoping you don't have thousands of approved domains ;) )

For those, you'd likely want to set a boolean variable for whether or not they would need to be redirected.

I do know enough about security to warn you on the IP's and "approved sites".  IP's can be spoofed, and $_SERVER['HTTP_REFERER'] should probably *not* be trusted, as it's fairly trivial to spoof and usually is where the bad guyz are concerned...

HTH,

Edited by dalecosp
Link to comment
https://forums.phpfreaks.com/topic/286774-referral-locking/#findComment-1471683
Share on other sites

 

If someone comes to our site (directly, or by click) to force them to goto https://site.com/

 

Is your site the "site.com" in the example? So, what you are really saying, is if someone tries to access a page - other than the index - you want to verify their referrer status correct? If you were to include the index page then you could create an infinite loop (although the header redirect might solve that).

 

I will add the following to dalecosp's response:

 

You should store the white-listed value in a database. Much easier to do a SELECT query on a value (or partial value) than looping through an array. Plus, you will likely want to build the functionality to include sub-domains by default. So, you will pull the referred domain apart to just get the root domain and the TLD.

 

Plus, you should only run this logic the first time the user hits your site in a session. Once you have verified that they are allowed to navigate to other pages, then you should set a session value. Then, check that first on every page load. If OK, then continue on. If not, then use the logic to check the referrer.

Link to comment
https://forums.phpfreaks.com/topic/286774-referral-locking/#findComment-1471685
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.