Closed (won't fix)
Project:
Secure Pages
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
15 Jan 2009 at 12:30 UTC
Updated:
25 Oct 2010 at 20:13 UTC
This module could be used to resolve the age old user login block issue, by allowing extra pages to be defined for anonymous users. Then users could specify all pages that the login block resides on to be secured. Once logged in, the extra pages are ignored.
The use case for this was to secure a site using an embedded login block on the front page.
My patches keep failing, so here is the code that I implemented from version 6.x-1.7-beta1.
<?php
function securepages_uninstall() {
variable_del('securepages_enable');
variable_del('securepages_switch');
variable_del('securepages_secure');
variable_del('securepages_pages');
variable_del('securepages_ignore');
variable_del('securepages_anonymous_pages');
}
?>
<?php
/**
* Implementation of hook_settings().
*/
function securepages_settings() {
// ...
$form['securepages_pages'] = array(
'#type' => 'textarea',
'#title' => t('Pages'),
'#default_value' => variable_get('securepages_pages', "node/add*\nnode/*/edit\nuser/*\nadmin*"),
'#cols' => 40,
'#rows' => 5,
'#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em><front></em>' is the front page."),
);
$form['securepages_anonymous_pages'] = array(
'#type' => 'textarea',
'#title' => t('Additional anonymous pages'),
'#default_value' => variable_get('securepages_anonymous_pages', ''),
'#cols' => 40,
'#rows' => 5,
'#description' => t("Additional pages to secure for anonymous users. Enter one page per line as."),
);
// ...
}
function securepages_match($path) {
global $user;
/**
* Check to see if the current menu item has a preference and ignore the
* secure pages settings
*/
if (function_exists('menu_get_item')) {
$item = menu_get_item($path);
if (isset($item['secure'])) {
return $item['secure'];
}
}
/**
* Check to see if the page matches the current settings
*/
$secure = variable_get('securepages_secure', 1);
$pages = variable_get('securepages_pages', "node/add*\nnode/*/edit\nuser/*\nadmin*");
if (!$user->uid) {
$anonymous_pages = variable_get('securepages_anonymous_pages', '');
$pages .= $anonymous_pages ? "\n". $anonymous_pages : '';
}
// ...
}
?>
Comments
Comment #1
alan d. commentedThe last thing that I had to lock down a URL that was show to both anonymous users and members. A custom 404/403 page (front page). Both of these had the login block to secure.
To do this I created a custom menu callback and assigned the error handler pages to this.
And then made this callback function:
Now I can flick the front page from HTTP to HTTPS depending on the user status and also assign the 404/403 pages here as well. The login block to the front page will always be secure. :)
If anyone has a better approach to this, I would be interested in it.
Comment #2
alan d. commentedbump. This is a cool feature that fixes a security hole in Drupal - transmission of user passwords via HTTP
Comment #3
grendzy commentedIMHO, the best solution is to use http://drupal.org/project/securepages_prevent_hijack , which ensures passwords are sent over SSL. Securing the login form by itself has almost no value, because you're still vulnerable to session hijacking.