Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Thu Mar 08, 2012 2:35 am 
Offline
Senior Newbie

Joined: Wed Dec 14, 2011 8:55 pm
Posts: 12
Website: http://www.dreamphysix.com
Location: Atlanta, Georgia
I want to use Apache mod_rewrite or PHP to redirect specific pages (regardless of query) to HTTPS, but force all other pages to be HTTP. I tried using mod_rewrite, but I usually ended up with a redirect loop. Same issue with PHP.

Basically, login.php admin.php reset.php (and any queries on those) to redirect to HTTPS version. All other pages should redirect to HTTP if they are accessed on HTTPS. Not sure how to accomplish this efficiently. Any help?


Top
   
 Post subject:
PostPosted: Thu Mar 08, 2012 4:22 am 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
jbenamy wrote:
login.php admin.php reset.php (and any queries on those) to redirect to HTTPS version.

If you're getting a redirect loop, RewriteCond is your friend.

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off  # The following rules only take effect if HTTPS is off
RewriteCond $1 ^(login|admin|reset)\.php
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L]

I'm not sure if these exact rules will work in your case, because there are lots of other things that might affect Apache's behavior. But your rules should look something like that.

jbenamy wrote:
All other pages should redirect to HTTP if they are accessed on HTTPS.

Nope, I'm not going to tell you how to do that, because that would be irresponsible.

If you access your site over an insecure wifi connection, log in over HTTPS, and then access even a single page on the same domain over plain HTTP (like testing something while doing admin tasks in another tab), you've just eliminated the benefit of logging in over HTTPS. The only way your server can tell whether or not you've logged in is with a cookie. That cookie can be stolen if you access the same domain over plain HTTP after logging in. If an attacker has the cookie, they don't even need to know your password.

So, unless you want to use a secure cookie that keeps logging you out whenever you hit an HTTP page, the only solution is to keep using HTTPS until you log out. In other words, it's perfectly OK to redirect from HTTP to HTTPS, but very dangerous to redirect from HTTPS to HTTP. The only place where it's OK to redirect from HTTPS to HTTP is the logout page.


Top
   
 Post subject:
PostPosted: Thu Mar 08, 2012 11:10 am 
Offline
Senior Member

Joined: Fri Jan 20, 2012 11:19 am
Posts: 100
Quote:
If an attacker has the cookie, they don't even need to know your password.


And chances are they'll be able to change your password from the interface anyway after they've authenticated using your cookie.

The only redeeming effect is in the case where you use the same password in different places. In that case, at least the attacker won't know your password.

But yeah, hybinet is spot on.

_________________
If all else fails, reboot...
PHP Tutorials and MySQL Tutorials


Top
   
 Post subject:
PostPosted: Thu Mar 08, 2012 2:54 pm 
Offline
Senior Newbie

Joined: Wed Dec 14, 2011 8:55 pm
Posts: 12
Website: http://www.dreamphysix.com
Location: Atlanta, Georgia
hybinet wrote:
jbenamy wrote:
login.php admin.php reset.php (and any queries on those) to redirect to HTTPS version.

If you're getting a redirect loop, RewriteCond is your friend.

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off  # The following rules only take effect if HTTPS is off
RewriteCond $1 ^(login|admin|reset)\.php
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L]

I'm not sure if these exact rules will work in your case, because there are lots of other things that might affect Apache's behavior. But your rules should look something like that.

jbenamy wrote:
All other pages should redirect to HTTP if they are accessed on HTTPS.

Nope, I'm not going to tell you how to do that, because that would be irresponsible.

If you access your site over an insecure wifi connection, log in over HTTPS, and then access even a single page on the same domain over plain HTTP (like testing something while doing admin tasks in another tab), you've just eliminated the benefit of logging in over HTTPS. The only way your server can tell whether or not you've logged in is with a cookie. That cookie can be stolen if you access the same domain over plain HTTP after logging in. If an attacker has the cookie, they don't even need to know your password.

So, unless you want to use a secure cookie that keeps logging you out whenever you hit an HTTP page, the only solution is to keep using HTTPS until you log out. In other words, it's perfectly OK to redirect from HTTP to HTTPS, but very dangerous to redirect from HTTPS to HTTP. The only place where it's OK to redirect from HTTPS to HTTP is the logout page.

Thank you for this information. This was immensely helpful.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group