3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen
Post on 15-Jan-2015
1.897 Views
Preview:
DESCRIPTION
TRANSCRIPT
Tietoturva Web-kehityksessä
&
Zend Frameworkissä PHP User Group Finland
24.11.2011
Kuka?
• Carl (Kalle) Vuorinen
– :ssa
vuodesta 2005
• PHP kehittäjä
• Tiiminvetäjä
• Osakas
• Matti Suominen
– :ssa
vuodesta 2007
• Tietoturvahörhö
• Osakas
Mitä?
• Tietoturva
– OWASP Top Ten
– 10 kriittisintä web
sovellusten
tietoturvariskiä
– Injektio, XSS, CSRF,
salasanojen suojaus https://www.owasp.org/index.php/Top_10_2010
• Zend Framework
– MVC framework
– Komponentti kirjasto
Extending the art & spirit of PHP, Zend
Framework is based on simplicity,
object-oriented best practices,
corporate friendly licensing, and a
rigorously tested agile codebase. http://framework.zend.com/about/overview
Miksi?
Miksi?
Miksi?
Miksi?
Miksi?
Tietoturva Zend
Frameworkissä
SQL injektio
• Erikoismerkkien muuntaminen
– Escaping
• Syötteiden tarkistukset
– Filtteröinti & validointi
• SQL lauseiden esikäsittely
– Prepared statements
Prepared statements
• Zend_Db_Adapter & Zend_Db_Statement
• Zend_Db_Select
• Zend_Db_Table
$table = new Bugs(); $rows = $table->find($bugId);
$sql = 'SELECT * FROM bugs WHERE bug_id = ?'; $result = $db->fetchAll($sql, $bugId);
$select = $db->select() ->from('products', array('product_id', 'product_name', 'price')) ->where('price > ?', $minimumPrice);
XSS
• Tulosteiden siistiminen
– Escape output
• Syötteiden tarkistukset
– Filtteröinti & validointi
• PHP session konfigurointi
– httpOnly cookie
Escape output
• Zend_View escape() metodi
<?php foreach ($this->books as $key => $val): ?> <tr> <td><?php echo $this->escape($val['author']) ?></td> <td><?php echo $this->escape($val['title']) ?></td> </tr> <?php endforeach; ?>
Filtteröinti & validointi
• Zend_Form ja Zend_Filter & Zend_Validate
• Zend_Filter_Input
$this->addElement( text', 'username', array( 'required' => true, 'label' => 'Username:', 'filters' => array('StringTrim', 'StringToLower'), 'validators' => array( 'Alnum', array('Regex', false, array('/^[a-z][a-z0-9]{2,}$/')) ) ));
Filtteröinti & validointi - HTML
• HTMLPurifier
– HTML Purifier defeats XSS with an audited
whitelist http://htmlpurifier.org/
– class My_Filter_HtmlPurifier
implements Zend_Filter_Interface
CSRF
• Piilotettu uniikki tunniste
– Hidden unique token
Piilotettu uniikki tunniste
• Zend_Form_Hash
• Automaattinen CSRF suojaus – Extend Zend_Form
• Linkkien suojaus – Javascript POST
$form->addElement('hash', 'no_csrf_foo', array('salt' => 'unique'));
Riittämätön salasanojen
suojaus • Hashing
– MD5 ei riitä
– bcrypt
– Hitaampi on parempi
Hashing
• PHPASS
– Portable PHP password hashing framework
http://www.openwall.com/phpass/
– class My_Auth_Adapter_DbTableHash
extends Zend_Auth_Adapter_DbTable
Kysymyksiä ?
Referenssit
• http://framework.zend.com/
• https://www.owasp.org/
• http://static.zend.com/topics/Webinar-Zend-Secure-Application-Development-with-
the-Zend-Framework.pdf
• http://htmlpurifier.org/
• http://blog.astrumfutura.com/2008/05/example-zend-framework-blog-application-
tutorial-part-8-creating-and-editing-blog-entries-with-a-dash-of-htmlpurifier/
• https://www.owasp.org/index.php/Cross-
Site_Request_Forgery_%28CSRF%29_Prevention_Cheat_Sheet
• http://www.openwall.com/phpass/
• http://www.openwall.com/articles/PHP-Users-Passwords
• http://codahale.com/how-to-safely-store-a-password/
top related