This is a discussion on Security in PHP within the PHP Programming forums, part of the Web Development category; The PHP safe mode is an attempt to solve the shared-server security problem. It is architecturally incorrect to try ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| The PHP safe mode is an attempt to solve the shared-server security problem. It is architecturally incorrect to try to solve this problem at the PHP level, but since the alternatives at the web server and OS levels aren't very realistic, many people, especially ISP's, use safe mode for now.
__________________ With, J. Jeyaseelan Everything Possible |
| Sponsored Links |
| |||
| Quote:
Code: -rw-rw-r-- 1 rasmus rasmus 33 Jul 1 19:20 script.php -rw-r--r-- 1 root root 1116 May 26 18:01 /etc/passwd PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| results in this error when safe mode is enabled: Code: Warning: SAFE MODE Restriction in effect. The script whose uid is 500 is not allowed to access /etc/passwd owned by uid 0 in /docroot/script.php on line 2
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| However, there may be environments where a strict UID check is not appropriate and a relaxed GID check is sufficient. This is supported by means of the safe_mode_gid switch. Setting it to On performs the relaxed GID checking, setting it to Off (the default) performs UID checking.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| If instead of safe_mode, you set an open_basedir directory then all file operations will be limited to files under the specified directory. For example (Apache httpd.conf example): Code: <Directory /docroot> php_admin_value open_basedir /docroot </Directory>
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| If you run the same script.php with this open_basedir setting then this is the result: Code: Warning: open_basedir restriction in effect. File is in wrong directory in /docroot/script.php on line 2
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| You can also disable individual functions. Note that the disable_functions directive can not be used outside of the php.ini file which means that you cannot disable functions on a per-virtualhost or per-directory basis in your httpd.conf file. If we add this to our php.ini file: Code: disable_functions readfile,system
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Quote:
Limit the files that can be opened by PHP to the specified directory-tree, including the file itself. This directive is NOT affected by whether Safe Mode is turned On or Off. When a script tries to open a file with, for example, fopen() or gzopen(), the location of the file is checked. When the file is outside the specified directory-tree, PHP will refuse to open it. All symbolic links are resolved, so it's not possible to avoid this restriction with a symlink. The special value . indicates that the working directory of the script will be used as the base-directory. This is, however, a little dangerous as the working directory of the script can easily be changed with chdir(). In httpd.conf, open_basedir can be turned off (e.g. for some virtual hosts) the same way as any other configuration directive with "php_admin_value open_basedir none". Under Windows, separate the directories with a semicolon. On all other systems, separate the directories with a colon. As an Apache module, open_basedir paths from parent directories are now automatically inherited. The restriction specified with open_basedir is actually a prefix, not a directory name. This means that "open_basedir = /dir/incl" also allows access to "/dir/include" and "/dir/incls" if they exist. When you want to restrict access to only the specified directory, end with a slash. For example: "open_basedir = /dir/incl/"
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| For more information on Captcha go the below link http://www.discussweb.com/php-progra...t-captcha.html http://www.discussweb.com/php-progra...php-error.html
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Captcha which contain security codes used for protecting a form from spam bots. By encoding a 'password' inside an image and asking the user to re-enter what they see you can verify the user is a human and not automated software submitting your form. Why not try out the following form with valid and invalid codes to see how it works.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Here is the sample script for captcha PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Data Filtering As stated previously, data filtering is the cornerstone of web application security, and this is independent of programming language or platform. It involves the mechanism by which you determine the validity of data that is entering and exiting the application, and a good software design can help developers to: * Ensure that data filtering cannot be bypassed,Opinions about how to ensure that data filtering cannot be bypassed vary, but there are two general approaches that seem to be the most common, and both of these provide a sufficient level of assurance.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| The Dispatch Method One method is to have a single PHP script available directly from the web (via URL). Everything else is a module included with include or require as needed. This method usually requires that a GET variable be passed along with every URL, identifying the task. This GET variable can be considered the replacement for the script name that would be used in a more simplistic design. For example: Code: http://example.org/dispatch.php?task=print_form * Implement some global security measures at the top of dispatch.php and be assured that these measures cannot
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| To further explain this, consider the following example dispatch.php script: PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| If this is the only public PHP script, then it should be clear that the design of this application ensures that any global security measures taken at the top cannot be bypassed. It also lets a developer easily see the control flow for a specific task. For example, instead of glancing through a lot of code, it is easy to see that end.inc is only displayed to a user when $form_valid is true, and because it is initialized as false just before process.inc is included, it is clear that the logic within process.inc must set it to true, otherwise the form is displayed again (presumably with appropriate error messages).
__________________ With, J. Jeyaseelan Everything Possible |