25
Tietoturva Web-kehityksessä & Zend Frameworkissä PHP User Group Finland 24.11.2011

3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Tietoturva Web-kehityksessä

&

Zend Frameworkissä PHP User Group Finland

24.11.2011

Page 2: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Kuka?

• Carl (Kalle) Vuorinen

– :ssa

vuodesta 2005

• PHP kehittäjä

• Tiiminvetäjä

• Osakas

• Matti Suominen

– :ssa

vuodesta 2007

• Tietoturvahörhö

• Osakas

Page 3: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

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

Page 4: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Miksi?

Page 5: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Miksi?

Page 6: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Miksi?

Page 7: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Miksi?

Page 8: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Miksi?

Page 9: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Tietoturva Zend

Frameworkissä

Page 10: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

SQL injektio

Page 11: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

SQL injektio

• Erikoismerkkien muuntaminen

– Escaping

• Syötteiden tarkistukset

– Filtteröinti & validointi

• SQL lauseiden esikäsittely

– Prepared statements

Page 12: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

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);

Page 14: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

XSS

• Tulosteiden siistiminen

– Escape output

• Syötteiden tarkistukset

– Filtteröinti & validointi

• PHP session konfigurointi

– httpOnly cookie

Page 15: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

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; ?>

Page 16: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

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,}$/')) ) ));

Page 17: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Filtteröinti & validointi - HTML

• HTMLPurifier

– HTML Purifier defeats XSS with an audited

whitelist http://htmlpurifier.org/

– class My_Filter_HtmlPurifier

implements Zend_Filter_Interface

Page 19: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

CSRF

• Piilotettu uniikki tunniste

– Hidden unique token

Page 20: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

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'));

Page 21: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Riittämätön salasanojen

suojaus

Page 22: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Riittämätön salasanojen

suojaus • Hashing

– MD5 ei riitä

– bcrypt

– Hitaampi on parempi

Page 23: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Hashing

• PHPASS

– Portable PHP password hashing framework

http://www.openwall.com/phpass/

– class My_Auth_Adapter_DbTableHash

extends Zend_Auth_Adapter_DbTable

Page 24: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

Kysymyksiä ?

Page 25: 3.w3 php user group 24112011 tietoturva web-kehityksessa-&-zend-frameworkissa carl vuorinen

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/