By Dave Cohen on
Can I force all users with administrative priveleges to always use SSL (HTTPS)?
Let's say that http://mysite and https://mysite both point to the same drupal installation. Can I somehow enforce this logic?
if (access over HTTP (not HTTPS)) {
if (current user has admin role) {
either goto https site or deny access
}
}
I can come up with the exact PHP code, but where do I put it?
Similarly, could I restrict access to user 1 (the "superuser") to only be from a certain machine (or only via http://localhost/...)?
I saw this conversation related to HTTP vs HTTPS: http://drupal.org/node/9309, but it does not address this question.
Thanks for any help.
Comments
The Answer
I'm going to answer my own question. I've been playing with the HTTPS only functionality, and here's what I have so far. This module assumes you have a drupal site visible both over HTTP and HTTPS. (See http://drupal.org/node/6554).
To restrict some users to HTTPS only, enable this module, then go to settings->user_deny and really enable it. Then any user with 'HTTPS login only' permission will be able to log in over HTTPS only. To be safe, you should be accessing the site by HTTPS when you do all this (otherwise you may be denying yourself access).
I may add more functionality to the user_deny module. For instance allowing some users to access the site only from some IP addresses. If there is much interest I will post updates here and/or move the project into cvs.
Re: Allow admin access only via HTTPS
It seems to me that this module does not really help in improving security of a Drupal site. The main advantage of restricting users to HTTPS access could be that they login through a secure channel. However ... if a user loads the login page through HTTP and submits the login form, then the username and password is already sent through the network in cleartext at the time this module is called. So what's the point of the module? What additional security is gained by using this module?
The other problem that I found is in the implementation. I didn't actually test it, but the reference to the variable $_SERVER['HTTPS'] is not safe. It is not assured that the $_SERVER variable has an element with an index "HTTPS". Eg. on my site the admin has installed a separate Apache for serving HTTP requests and a separate Apache for serving HTTPS requests. The former has no mod_ssl and as such the $_SERVER variable does not have an element with index "HTTP". My site is available both through HTTP and HTTPS, but in case of HTTP an access to the $_SERVER['HTTPS'] variable raises an error.
So you should check for existence of that index in the array before referencing it.
Something like this: