200 likes | 467 Views
Security. Khaled Al-Sham’aa. What Is Security?. Security is a measurement, not a characteristic. Security must be balanced with expense. Security must be balanced with usability. Security must be part of the design. Basic Steps. Consider illegitimate uses of your application.
E N D
Security Khaled Al-Sham’aa
What Is Security? • Security is a measurement, not a characteristic. • Security must be balanced with expense. • Security must be balanced with usability. • Security must be part of the design.
Basic Steps • Consider illegitimate uses of your application. • Educate yourself. • If nothing else: FILTER ALL INPUT DATA ESCAPE ALL OUTPUT DATA
Cross-Site Scripting (XSS) 3 • htmlentities() • strip_tags() • utf8_decode()
SQL Injection (example 1) <form method="post" action="http://www.example.com/login.php"> <input name="user" type="text"> <input name="pwd" type="password"> </form>
SQL Injection (example 1) con. • SELECT `id` FROM `logins` WHERE `username` = '$user' AND `password` = '$pwd' • $user = “Khaled”; • $pwd = “anything' OR 'x'='x”; • SELECT `id` FROM `logins` WHERE `username` = 'Khaled' AND `password` = 'anything' OR 'x'='x'
SQL Injection (example 2) • $query = “UPDATE usertable SET pwd='$pwd' WHERE uid='$uid' ”; • $pwd = “abc”; • $uid = “anything' or uid='admin'; -- ”; • $query = “UPDATE usertable SET pwd='abc' WHERE uid= 'anything' or uid='admin'; -- ' ”;
Avoiding SQL Injection • mysql_real_escape_string() • for PHP version < 4.3.0 use addslashes() • Prepared Statements