This is a discussion on Security in PHP within the PHP Programming forums, part of the Web Development category; Hi Buddies Numeric Data Validation All data passed to PHP (GET/POST/COOKIE) ends up being a string. Using strings ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi Buddies Numeric Data Validation All data passed to PHP (GET/POST/COOKIE) ends up being a string. Using strings where integers are needed is not only inefficient but also dangerous. Casting is a simple and very efficient way to ensure that variables contain numeric values. Example of floating point number validation PHP Code: Falcon ![]() |
| Sponsored Links |
| |||
| Hi Buddies String Validation PHP comes with a ctype, extension that offers a very quick mechanism for validating string content. PHP Code: Regards Falcon ![]() |
| |||
| Hi Buddies Cross Site Scripting (XSS) Cross Site Scripting (XSS) is a situation where by attacker injects HTML code, which is then displayed on the page without further validation. Can lead to embarrassment Session take-over Password theft User tracking by 3rd parties Regards Falcon ![]() |
| |||
| Hi, Prevention of XSS is as simple as filtering input data via one of the following: htmlspecialchars() Encodes ‘, “, <, >, & htmlentities() Convert anything that there is HTML entity for. strip_tags() Strips anything that resembles HTML tag. Tag allowances in strip_tags() are dangerous, because attributes of those tags are not being validated in any way.
__________________ Regards, Senraj.A |
| |||
| Hi, Prevention of XSS $str = strip_tags($_POST['message']); // encode any foreign & special chars $str = htmlentities($str); // strip tags can be told to "keep" certain tags $str = strip_tags($_POST['message'], '<b><p><i><u>'); // tag allowance problems <u onmouseover="alert('JavaScript is allowed');"> <b style="font-size: 500px">Lot's of text</b> </u>
__________________ Regards, Senraj.A |
| |||
| Hi, SQL injection is similar to XSS, in the fact that not validated data is being used. But in this case this data is passed to the database. Arbitrary query execution Removal of data. Modification of existing values. Denial of service. Arbitrary data injection. PHP Code:
__________________ Regards, Senraj.A Last edited by senraj : 03-21-2008 at 06:33 AM. |
| |||
| Hi, If your database extension offers a specific escaping function then always use it; instead of other methods MySQL mysql_escape_string() mysql_real_escape_string() PostgreSQL pg_escape_string() pg_escape_bytea() SQLite sqlite_escape_string()
__________________ Regards, Senraj.A |
| |||
| Hi, Sql Escaping PHP Code:
__________________ Regards, Senraj.A |
| |||
| Hi, When un-quoted integers are passed to SQL queries, escaping functions won’t save you, since there are no special chars to escape. http://example.com/db.php?id=0;DELETE%20FROM%20users PHP Code:
__________________ Regards, Senraj.A |
| |||
| Hi, Security in PHP Prepared Statements Prepared statements are a mechanism to secure and optimize execution of repeated queries. Works by making SQL “compile” the query and then substitute in the changing values for each execution. Increased performance, one compile vs one per query. Better security, data is “type set” will never be evaluated as separate query. Supported by most database systems. MySQL users will need to use version 4.1 or higher. SQLite extension does not support this either.
__________________ Regards, Senraj.A |
| |||
| Hi, Security in PHP Prepared Statements PHP Code: between persistent connections.
__________________ Regards, Senraj.A |
| |||
| Hi, Code Injection is the execution of arbitrary local or remote code. The two of the most common sources of code injection are: Dynamic paths/files used in require/include statements eval(): A major source of code injection is the improper validation of eval().
__________________ Regards, Senraj.A |
| |||
| Hi, Avoid using dynamic or relative paths/files in your code. Although somewhat less convenient; always use full paths, defined by constants, which will prevent attacks like these: PHP Code:
__________________ Regards, Senraj.A |
| |||
| Hi, work with a white-list of acceptable values. //create an array of acceptable file names $tmpl = array(); foreach(glob("templates/*.tmpl") as $v) { $tmpl[md5($v)] = $v; } if (isset($tmpl[$_GET['path']])) { $fp = fopen($tmpl[$_GET['path']], "r"); }
__________________ Regards, Senraj.A |
| |||
| Hi Buddies Session Security
Falcon ![]() |
| |||
| Hi Buddies Securing Session ID
PHP Code:
Regards Falcon ![]() |
| |||
| Hi Buddies Session Validation
PHP Code: Falcon ![]() |
| |||
| Hi Buddies Safer Session Storage
Regards Falcon ![]() |
| |||
| Hi, Shared Hosting
__________________ Regards, Senraj.A |
| |||
| Hi, The PHP Solution
__________________ Regards, Senraj.A |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |