safe_mode) feature attempts to enforce read/write permissions on shared hosting environments for PHP. Ordinarily, a PHP script can open and modify any file on the filesystem. Enabling safe_mode causes PHP to check the user ID (UID) of the script as it attempts to open a file against that file's (or directory's) UID. If the user IDs do not match, the script cannot open or modify the file or directory. This prevents users from accessing files via PHP that do not belong to them. In effect, this prevents attackers from exploiting read/write insecurities and injecting malicious code into other scripts via PHP.
You can relax safe mode's file check to a group ID (GID) rather than a UID check (safe_mode_gid). This can be useful if safe_mode is too restrictive for use in your environment. For example, if several developers with different user IDs require the ability to open and modify the same file or directory via PHP, you can enable safe_mode_gid. This causes PHP to check the group IDs of the script and file, rather than the user IDs. In effect, this will allow several developers with different UIDs to open and modify the same set of files as long as each of the developers is in the same group.
In addition to enabling safe_mode or safe_mode_gid, you may also choose to restrict which directories can contain included or executable files. Under default conditions, any directory on the filesystem could contain included or executable PHP files. This is a danger.
/etc/passwd file using a PHP inclusion vulnerability, in effect acquiring some basic information about every account associated with your web server.
To help prevent local include vulnerabilities, you can set the open_basedir parameter in your PHP configuration to a specific directory. This will limit an attacker's access via local includes to a single directory. In most cases, you will want to set the open_basedir parameter to a public_html directory, allowing PHP to open and modify HTTP-accessible (public) files contained within the specified directory while limiting access to more sensitive information contained outside of the specified directory.
Remote file include attacks occur when an attacker is able to pull files from a remote location onto your server. When remote includes are used, an attacker will write a PHP script and host it on his or her own server, then use a remote inclusion method to upload and execute the script on your server. If your PHP configuration is insecure, an attacker does not need to have read/write permissions on your server to upload and execute the offending script. To prevent remote file inclusion attacks, set the allow_url_fopen and allow_url_include parameters to Off.
display_errors is disabled, your developers are still able to retrieve debugging information from the appropriate PHP logs.
upload_tmp_dir parameter.
Many administrators also choose to limit the maximum file size users can upload using the upload_max_filesize parameter. Setting this parameter is generally not intended to improve the security of your PHP configuration. Administrators choose to set this parameter to help manage the server's PHP load.
session.cookie_httponly parameter to On. This directive prevents JavaScript from accessing a PHP application's session cookies. If your developers require that JavaScript have access to session cookies, do not enable this option.
You may also wish to allow PHP to check HTTP referrer values. This ensures that sensitive session information is only passed internally during a user's session. In effect, this will prevent users from accidentally publishing sensitive session information by sharing a URL.
Copyright © cPanel 2000–2011.