Securing admin pages with additional (htauth) password

By default, to view the admin pages, you need to enter an administrator username and password on the phpList admin login page. However, this is only a single layer of security. If your phpList database was to be compromised, or the routines used to validate passwords were discovered to be exploitable, an attacker could gain full control over your phpList installation.

To add an additional layer of security, we can configure an additional Apache mod_auth-based password to protect the admin page. This means that your web server (prior to phpList) will prompt the viewer for a user and password combination, before showing them the phpList login page.

Note

This also means that you need two passwords to administer your list!

Creating an htpasswd file

The mod_auth authentication scheme requires a file commonly called an htpasswd file, which contains pairs of usernames and encrypted passwords, one per line, to exist on the web server. The web server will use this file to validate your username and password when you browse to any URL underneath the /admin/ directory.

This file should be accessible to the web server (that is, on the web server's filesystem), but not accessible to the world (that is, not in a directory which is accessible via a web browser).

In many cases, web-facing files (such as phpList's .php files) are stored in a public_html folder on your web host. You may have other folders including log files, backups, and so on. Choose a location for the password file and make sure you know the filesystem path to this file. (For example, /home/webusers/myusername/htpasswd would be secure, if your web files are in /home/webusers/myusername/public_html/).

Creating an htpassword file online

The simplest way to generate an htpassword file is to generate the user-encrypted password pairs online. There are many online tools that use simple code to do this for you. You could search the web for "generate htpasswd file" or use a website like http://www.htaccesstools.com/htpasswd-generator/.

Once you have the user-encrypted password line, save it to a file named htpasswd, and upload it to the chosen directory on your web host. Remember, you need to know the filesystem path to this file.

Creating an htpasswd file in a Unix shell

Assuming you have access to your web host using a Unix shell (or to another Unix-like host), you can also create the password file directly on the web host, using the following command:

htpasswd -cb <filesystem path to password file> <username> <password>

For example, you may use:

[root@webhost myuser]# htpasswd -cb /home/webusers/myusername/passwd myuser mypassword
Adding password for user myuser
[root@webhost myuser]#

Note

The -c in the htpasswd command stands for "create". It assumes that the password file doesn't already exist. If you run this against an existing file, it will overwrite this file, so be careful! If you want to add additional usernames to this file, use the htpasswd command without the -c argument.

The contents of your password file should look something like this: myuser:CEZqTfQTUZhzw.

Amending admin/.htaccess

Having a file containing usernames and passwords is not enough to secure access—we need to tell the web server not to allow any visits to any URLs underneath the admin/ directory, unless the user has authenticated against our password file.

We put these instructions in a special file in the admin/ directory called .htaccess.

By default, this file contains the following lines, which restrict any access to important .php files under the admin/ directory:

<FilesMatch ".(php|inc)$">
Order allow,deny
deny from all
</FilesMatch>
<FilesMatch "(index.php|connector.php|upload.php)$">
Order allow,deny
allow from all
</FilesMatch>

We will add the following directives to this file either above or below the existing text:

# Restrict access to admin/ URLs
AuthUserFile <filesystem path to your htpasswd file>
AuthName "PHPList Admin Access"
AuthType Basic
require valid-user
# End access restriction directives

These lines tell the web server which password file to refer to, what the name of the authentication "realm" is, what type of authentication to use, and instruct it that a valid user match is required.

Tip

Comments

The lines starting with hash characters are comments and are included simply to improve readability. They can be excluded or customized and are ignored by the web server.

Having added the aforementioned lines, the entire admin/.htaccess file will look something like this:

<FilesMatch ".(php|inc)$">
Order allow,deny
deny from all
</FilesMatch>
<FilesMatch "(index.php|connector.php|upload.php)$">
Order allow,deny
allow from all
</FilesMatch>
# Restrict access to admin/ URLs
AuthUserFile <filesystem path to your htpasswd file>
AuthName "PHPList Admin Access"
AuthType Basic
require valid-user
# End access restriction directives

Having saved the changes to admin/.htaccess, refresh the admin page and your browser will pop up an authentication request as shown in the following screenshot:

Amending admin/.htaccess

Tip

Remembering passwords

Some web browsers will offer you the option of remembering this password for the future, which is suitable if you are using a browser on a trusted, private computer (that is, don't do this at an Internet cafe!).

Note

Note that using this method of restricting access doesn't allow you any means to log out again. Once you enter your username and password, your browser will keep you logged in (at the mod_auth level) until you restart your browser.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.226.66