Home page / PHP Tips'n'tricks

Security

Non la voglio menare con la sicurezza, ma utilizzare delle funzioni che consentano di verficare e volendo sanitizzare i flussi di dati e' da sempre una comune esigenza. In questo senso abbiamo preso in esame una libreria sviluppata dall' OWASP.org (Open Web Application Security Project) per php4 ma valida anche per il 5.

Utilizzo:

 

  1. Controllo:
    if(check_int($_REQUEST['nomevar']),1,100){ /* e' un intero positivo compreso tra 0 e 100 */ } 
  2. Sanitizzazione:
    $nomevar = sanitize_int($_REQUEST['nomevar']);

Controllare l' input consente di evitare la riuscita di numerosi attacchi tipo SQL Injection, Directory trasversal, Cross Site Scripting ecc...

 

Funzioni:

function nice_addslashes($string)  // addslashes wrapper to check for gpc_magic_quotes - gz

function nice_stripslashes($string// stripslashes wrapper to check for gpc_magic_quotes - gz

function sanitize_paranoid_string($string$min=''$max=''// paranoid sanitization -- only let the alphanumeric set through

function sanitize_system_string($string$min=''$max='') // sanitize a string in prep for passing a single argument to system() (or similar)

function sanitize_sql_string($string$min=''$max=''// sanitize a string for SQL input (simple slash out quotes and slashes)

function sanitize_ldap_string($string$min=''$max=''// sanitize a string LDAP

function sanitize_html_string($string)// sanitize a string for HTML (make sure nothing gets interpretted!)

function sanitize_string($string$min=''$max='')// make string string!

function sanitize_int($integer$min=''$max='') // make int int!

function sanitize_float($float$min=''$max='') // make float float!

function sanitize($input$flags$min=''$max=''// glue together all the other functions

function check_paranoid_string($input$min=''$max=''

function check_int($input$min=''$max='')

function check_float($input$min=''$max=''

function check_html_string($input$min=''$max=''

function check_sql_string($input$min=''$max='')

function check_ldap_string($input$min=''$max='')

function check_system_string($input$min=''$max='')

function check($input$flags$min=''$max='')// glue together all the other functions

function slash_quotes($string)
function 
unslash_quotes($string)
function 
slash_dblquotes($string)
function 
unslash_dblquotes($string)
 

OWASP Sanitize.lib.php

Autore: #ffffff (10-02-2007 00:00:00)

07-01-2009 - PM 03:15