cvs: pear /HTML_Form package.xml /HTML_Form/HTML Form.php
| From: | Daniel Convissor | Date: | Sun, 16 Oct 2005 18:57:36 +0000 |
| Subject: | cvs: pear /HTML_Form package.xml /HTML_Form/HTML Form.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35603@lists.php.net to get a copy of this message | ||
danielc Sun Oct 16 14:57:36 2005 EDT
Modified files:
/pear/HTML_Form package.xml
/pear/HTML_Form/HTML Form.php
Log:
* This release resolves all of the security issues
and fixes some unreported bugs. In addition, the
documentation block comment for the display()
method now accurately reflects how it works.
http://cvs.php.net/diff.php/pear/HTML_Form/package.xml?r1=1.23&r2=1.24&ty=u Index: pear/HTML_Form/package.xml diff -u pear/HTML_Form/package.xml:1.23 pear/HTML_Form/package.xml:1.24 --- pear/HTML_Form/package.xml:1.23 Fri Mar 18 09:06:38 2005 +++ pear/HTML_Form/package.xml Sun Oct 16 14:57:33 2005 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> <package version="1.0"> - <!-- $Id: package.xml,v 1.23 2005/03/18 14:06:38 danielc Exp $ --> + <!-- $Id: package.xml,v 1.24 2005/10/16 18:57:33 danielc Exp $ --> <name>HTML_Form</name> <summary>Simple HTML form package</summary> <description> @@ -25,15 +25,20 @@ </maintainer> </maintainers> <release> - <version>1.2.0</version> + <version>1.3.0</version> <state>stable</state> - <date>2005-03-18</date> + <date>2005-10-16</date> <notes><![CDATA[ -* Add methods for password rows without - confirmation fields. Request 3867. -* Have docblocks for Select methods indicate - defaults must match data type of entries. - Bug 3870. +MAJOR SECURITY FIXES + +Prior versions of this package had major +vulnerabilities when using the add*() methods to +build your forms. + +This release resolves all of the security issues +and fixes some unreported bugs. In addition, the +documentation block comment for the display() +method now accurately reflects how it works. ]]> </notes> <filelist> @@ -51,6 +56,20 @@ <changelog> <release> + <version>1.2.0</version> + <state>stable</state> + <date>2005-03-18</date> + <notes><![CDATA[ +* Add methods for password rows without + confirmation fields. Request 3867. +* Have docblocks for Select methods indicate + defaults must match data type of entries. + Bug 3870. + ]]> + </notes> + </release> + + <release> <version>1.1.3</version> <state>stable</state> <date>2005-03-07</date> http://cvs.php.net/diff.php/pear/HTML_Form/HTML/Form.php?r1=1.21&r2=1.22&ty=u Index: pear/HTML_Form/HTML/Form.php diff -u pear/HTML_Form/HTML/Form.php:1.21 pear/HTML_Form/HTML/Form.php:1.22 --- pear/HTML_Form/HTML/Form.php:1.21 Fri Mar 18 09:06:38 2005 +++ pear/HTML_Form/HTML/Form.php Sun Oct 16 14:57:35 2005 @@ -5,6 +5,9 @@ /** * HTML form utility functions * + * Release 1.3.0 introduces very important security fixes. + * Please make sure you have upgraded. + * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license @@ -20,7 +23,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License - * @version $Id: Form.php,v 1.21 2005/03/18 14:06:38 danielc Exp $ + * @version $Id: Form.php,v 1.22 2005/10/16 18:57:35 danielc Exp $ * @link http://pear.php.net/package/HTML_Form */ @@ -109,12 +112,15 @@ /** * HTML form utility functions * + * Release 1.3.0 introduces very important security fixes. + * Please make sure you have upgraded. + * * @category HTML * @package HTML_Form * @author Stig Bakken <ssb@fast.no> * @author Urs Gehrig <urs@circle.ch> * @author Daniel Convissor <danielc@php.net> - * @copyright 1997-2004 The PHP Group + * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License * @version Release: @package_version@ * @link http://pear.php.net/package/HTML_Form @@ -172,6 +178,53 @@ */ var $attr; + /** + * an array indicating which parameter to an add*Row() method contains + * the the field's $default value + * + * @var array + * @access private + * @since Property available since Release 1.3.0 + */ + var $_default_params = array( + 'blank' => false, + 'checkbox' => 3, + 'file' => false, + 'hidden' => false, + 'image' => false, + 'password' => 3, + 'passwordOne' => 3, + 'plaintext' => false, + 'radio' => 4, + 'reset' => false, + 'select' => 4, + 'submit' => false, + 'text' => 3, + 'textarea' => 3, + ); + + /** + * allow $_GET/$_POST data to show up in fields when a $default + * hasn't been set? + * + * @var boolean + * @access private + * @see HTML_Form::setDefaultFromInput() + * @since Property available since Release 1.3.0 + */ + var $_default_from_input = true; + + /** + * escape the $_GET/$_POST data that shows up in fields when a $default + * hasn't been set? + * + * @var boolean + * @access private + * @see HTML_Form::setEscapeDefaultFromInput() + * @since Property available since Release 1.3.0 + */ + var $_escape_default_from_input = true; + // }}} // {{{ constructor @@ -204,6 +257,42 @@ $this->attr = $attr; } + /** + * Enables/Disables $_GET/$_POST user input data showing up in fields + * when a $default hasn't been set + * + * The default is TRUE. + * + * @param boolean $bool TRUE to use $_GET/$_POST for the default, + * FALSE to default to an empty string + * + * @return void + * + * @see HTML_Form::setEscapeDefaultFromInput() + * @since Method available since Release 1.3.0 + */ + function setDefaultFromInput($bool) { + $this->_default_from_input = $bool; + } + + /** + * Enables/Disables escaping of the $_GET/$_POST data that shows up in + * fields when a $default hasn't been set + * + * The default is TRUE. + * + * Uses htmlspecialchars() for the escaping. + * + * @param boolean $bool TRUE to escape, FALSE to disable escaping + * + * @return void + * + * @see HTML_Form::setDefaultFromInput() + * @since Method available since Release 1.3.0 + */ + function setEscapeDefaultFromInput($bool) { + $this->_escape_default_from_input = $bool; + } // =========== ADD =========== @@ -2468,7 +2557,15 @@ * Prints a complete form with all fields you specified via * the add*() methods * - * If the $_GET/$_POST supreglobal don't exist, then + * If you did not specify a field's default value (via the $default + * parameter to the add*() method in question), this method will + * automatically insert the user input found in $_GET/$_POST. This + * behavior can be disabled via setDefaultFromInput(false). + * + * The $_GET/$_POST input is automatically escaped via htmlspecialchars(). + * This behavior can be disabled via setEscapeDefaultFromInput(false). + * + * If the $_GET/$_POST superglobal doesn't exist, then * $HTTP_GET_VARS/$HTTP_POST_VARS is used. * * NOTE: can NOT be called statically. @@ -2481,19 +2578,33 @@ * @return void * * @access public - * @see HTML_Form::end(), HTML_Form::end() + * @see HTML_Form::end(), HTML_Form::returnEnd(), + * HTML_Form::setDefaultFromInput(), + * HTML_Form::setEscapeDefaultFromInput() */ function display($attr = '', $caption = '', $capattr = '') { - $arrname = '_' . strtoupper($this->method); - if (isset($$arrname)) { - $arr =& $$arrname; + // Determine where to get the user input from. + + if (strtoupper($this->method) == 'POST') { + if (!empty($_POST)) { + $input =& $_POST; + } else { + if (!empty($HTTP_POST_VARS)) { + $input =& $HTTP_POST_VARS; + } else { + $input = array(); + } + } } else { - $arrname = 'HTTP' . $arrname . '_VARS'; - if (isset($GLOBALS[$arrname])) { - $arr =& $GLOBALS[$arrname]; + if (!empty($_GET)) { + $input =& $_GET; } else { - $arr = array(); + if (!empty($HTTP_GET_VARS)) { + $input =& $HTTP_GET_VARS; + } else { + $input = array(); + } } } @@ -2505,87 +2616,52 @@ print "\n </caption>\n"; } + /* + * Go through each field created through the add*() methods + * and pass their arguments on to the display*Row() methods. + */ + $hidden = array(); - foreach ($this->fields as $i => $data) { - /* - * $params = the number of arguments the add*() methods have - * $defind = the number of them that have default values - */ - switch ($data[0]) { + foreach ($this->fields as $field_index => $field) { + $type = $field[0]; + $name = $field[1]; + + switch ($type) { case 'hidden': - $hidden[] = $i; - $defind = 1; - continue 2; - case 'reset': - $params = 4; - $defind = 4; - break; - case 'submit': - $params = 5; - $defind = 5; - break; - case 'blank': - $params = 4; - $defind = 3; - break; - case 'image': - $params = 6; - $defind = 3; - break; - case 'checkbox': - $params = 6; - $defind = 4; - break; - case 'file': - case 'text': - $params = 8; - $defind = 6; - break; - case 'password': - case 'passwordOne': - $params = 8; - $defind = 5; - break; - case 'radio': - $params = 7; - $defind = 4; - break; - case 'textarea': - $params = 9; - $defind = 6; - break; - case 'select': - $params = 10; - $defind = 7; - break; - case 'plaintext': - $params = 4; - $defind = 3; - break; - default: - // unknown field type + // Deal with these later so they don't mess up layout. + $hidden[] = $field_index; continue 2; } - $str = '$this->display' . ucfirst($data[0]) . 'Row('; - for ($i = 1; $i <= $params; $i++) { - if ($i == $defind && $data[$defind] === null && - isset($arr[$data[1]])) - { - $str .= '$arr[\'' . $data[1] . '\']'; + + if ($this->_default_from_input + && $this->_default_params[$type] + && $field[$this->_default_params[$type]] === null + && array_key_exists($name, $input)) + { + // Grab the user input from $_GET/$_POST. + if ($this->_escape_default_from_input) { + $field[$this->_default_params[$type]] = + htmlspecialchars($input[$name]); } else { - $str .= '$data[' . $i . ']'; + $field[$this->_default_params[$type]] = $input[$name]; } - if ($i < $params) $str .= ', '; } - $str .= ');'; - eval($str); + + array_shift($field); + call_user_func_array( + array(&$this, 'display' . ucfirst($type) . 'Row'), + $field + ); } + print "</table>\n"; + for ($i = 0; $i < sizeof($hidden); $i++) { $this->displayHidden($this->fields[$hidden[$i]][1], $this->fields[$hidden[$i]][2], $this->fields[$hidden[$i]][3]); } + $this->end(); }
http://cvs.php.net/diff.php/pear/HTML_Form/package.xml?r1=1.23&r2=1.24&ty=u Index: pear/HTML_Form/package.xml diff -u pear/HTML_Form/package.xml:1.23 pear/HTML_Form/package.xml:1.24 --- pear/HTML_Form/package.xml:1.23 Fri Mar 18 09:06:38 2005 +++ pear/HTML_Form/package.xml Sun Oct 16 14:57:33 2005 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> <package version="1.0"> - <!-- $Id: package.xml,v 1.23 2005/03/18 14:06:38 danielc Exp $ --> + <!-- $Id: package.xml,v 1.24 2005/10/16 18:57:33 danielc Exp $ --> <name>HTML_Form</name> <summary>Simple HTML form package</summary> <description> @@ -25,15 +25,20 @@ </maintainer> </maintainers> <release> - <version>1.2.0</version> + <version>1.3.0</version> <state>stable</state> - <date>2005-03-18</date> + <date>2005-10-16</date> <notes><![CDATA[ -* Add methods for password rows without - confirmation fields. Request 3867. -* Have docblocks for Select methods indicate - defaults must match data type of entries. - Bug 3870. +MAJOR SECURITY FIXES + +Prior versions of this package had major +vulnerabilities when using the add*() methods to +build your forms. + +This release resolves all of the security issues +and fixes some unreported bugs. In addition, the +documentation block comment for the display() +method now accurately reflects how it works. ]]> </notes> <filelist> @@ -51,6 +56,20 @@ <changelog> <release> + <version>1.2.0</version> + <state>stable</state> + <date>2005-03-18</date> + <notes><![CDATA[ +* Add methods for password rows without + confirmation fields. Request 3867. +* Have docblocks for Select methods indicate + defaults must match data type of entries. + Bug 3870. + ]]> + </notes> + </release> + + <release> <version>1.1.3</version> <state>stable</state> <date>2005-03-07</date> http://cvs.php.net/diff.php/pear/HTML_Form/HTML/Form.php?r1=1.21&r2=1.22&ty=u Index: pear/HTML_Form/HTML/Form.php diff -u pear/HTML_Form/HTML/Form.php:1.21 pear/HTML_Form/HTML/Form.php:1.22 --- pear/HTML_Form/HTML/Form.php:1.21 Fri Mar 18 09:06:38 2005 +++ pear/HTML_Form/HTML/Form.php Sun Oct 16 14:57:35 2005 @@ -5,6 +5,9 @@ /** * HTML form utility functions * + * Release 1.3.0 introduces very important security fixes. + * Please make sure you have upgraded. + * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license @@ -20,7 +23,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License - * @version $Id: Form.php,v 1.21 2005/03/18 14:06:38 danielc Exp $ + * @version $Id: Form.php,v 1.22 2005/10/16 18:57:35 danielc Exp $ * @link http://pear.php.net/package/HTML_Form */ @@ -109,12 +112,15 @@ /** * HTML form utility functions * + * Release 1.3.0 introduces very important security fixes. + * Please make sure you have upgraded. + * * @category HTML * @package HTML_Form * @author Stig Bakken <ssb@fast.no> * @author Urs Gehrig <urs@circle.ch> * @author Daniel Convissor <danielc@php.net> - * @copyright 1997-2004 The PHP Group + * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License * @version Release: @package_version@ * @link http://pear.php.net/package/HTML_Form @@ -172,6 +178,53 @@ */ var $attr; + /** + * an array indicating which parameter to an add*Row() method contains + * the the field's $default value + * + * @var array + * @access private + * @since Property available since Release 1.3.0 + */ + var $_default_params = array( + 'blank' => false, + 'checkbox' => 3, + 'file' => false, + 'hidden' => false, + 'image' => false, + 'password' => 3, + 'passwordOne' => 3, + 'plaintext' => false, + 'radio' => 4, + 'reset' => false, + 'select' => 4, + 'submit' => false, + 'text' => 3, + 'textarea' => 3, + ); + + /** + * allow $_GET/$_POST data to show up in fields when a $default + * hasn't been set? + * + * @var boolean + * @access private + * @see HTML_Form::setDefaultFromInput() + * @since Property available since Release 1.3.0 + */ + var $_default_from_input = true; + + /** + * escape the $_GET/$_POST data that shows up in fields when a $default + * hasn't been set? + * + * @var boolean + * @access private + * @see HTML_Form::setEscapeDefaultFromInput() + * @since Property available since Release 1.3.0 + */ + var $_escape_default_from_input = true; + // }}} // {{{ constructor @@ -204,6 +257,42 @@ $this->attr = $attr; } + /** + * Enables/Disables $_GET/$_POST user input data showing up in fields + * when a $default hasn't been set + * + * The default is TRUE. + * + * @param boolean $bool TRUE to use $_GET/$_POST for the default, + * FALSE to default to an empty string + * + * @return void + * + * @see HTML_Form::setEscapeDefaultFromInput() + * @since Method available since Release 1.3.0 + */ + function setDefaultFromInput($bool) { + $this->_default_from_input = $bool; + } + + /** + * Enables/Disables escaping of the $_GET/$_POST data that shows up in + * fields when a $default hasn't been set + * + * The default is TRUE. + * + * Uses htmlspecialchars() for the escaping. + * + * @param boolean $bool TRUE to escape, FALSE to disable escaping + * + * @return void + * + * @see HTML_Form::setDefaultFromInput() + * @since Method available since Release 1.3.0 + */ + function setEscapeDefaultFromInput($bool) { + $this->_escape_default_from_input = $bool; + } // =========== ADD =========== @@ -2468,7 +2557,15 @@ * Prints a complete form with all fields you specified via * the add*() methods * - * If the $_GET/$_POST supreglobal don't exist, then + * If you did not specify a field's default value (via the $default + * parameter to the add*() method in question), this method will + * automatically insert the user input found in $_GET/$_POST. This + * behavior can be disabled via setDefaultFromInput(false). + * + * The $_GET/$_POST input is automatically escaped via htmlspecialchars(). + * This behavior can be disabled via setEscapeDefaultFromInput(false). + * + * If the $_GET/$_POST superglobal doesn't exist, then * $HTTP_GET_VARS/$HTTP_POST_VARS is used. * * NOTE: can NOT be called statically. @@ -2481,19 +2578,33 @@ * @return void * * @access public - * @see HTML_Form::end(), HTML_Form::end() + * @see HTML_Form::end(), HTML_Form::returnEnd(), + * HTML_Form::setDefaultFromInput(), + * HTML_Form::setEscapeDefaultFromInput() */ function display($attr = '', $caption = '', $capattr = '') { - $arrname = '_' . strtoupper($this->method); - if (isset($$arrname)) { - $arr =& $$arrname; + // Determine where to get the user input from. + + if (strtoupper($this->method) == 'POST') { + if (!empty($_POST)) { + $input =& $_POST; + } else { + if (!empty($HTTP_POST_VARS)) { + $input =& $HTTP_POST_VARS; + } else { + $input = array(); + } + } } else { - $arrname = 'HTTP' . $arrname . '_VARS'; - if (isset($GLOBALS[$arrname])) { - $arr =& $GLOBALS[$arrname]; + if (!empty($_GET)) { + $input =& $_GET; } else { - $arr = array(); + if (!empty($HTTP_GET_VARS)) { + $input =& $HTTP_GET_VARS; + } else { + $input = array(); + } } } @@ -2505,87 +2616,52 @@ print "\n </caption>\n"; } + /* + * Go through each field created through the add*() methods + * and pass their arguments on to the display*Row() methods. + */ + $hidden = array(); - foreach ($this->fields as $i => $data) { - /* - * $params = the number of arguments the add*() methods have - * $defind = the number of them that have default values - */ - switch ($data[0]) { + foreach ($this->fields as $field_index => $field) { + $type = $field[0]; + $name = $field[1]; + + switch ($type) { case 'hidden': - $hidden[] = $i; - $defind = 1; - continue 2; - case 'reset': - $params = 4; - $defind = 4; - break; - case 'submit': - $params = 5; - $defind = 5; - break; - case 'blank': - $params = 4; - $defind = 3; - break; - case 'image': - $params = 6; - $defind = 3; - break; - case 'checkbox': - $params = 6; - $defind = 4; - break; - case 'file': - case 'text': - $params = 8; - $defind = 6; - break; - case 'password': - case 'passwordOne': - $params = 8; - $defind = 5; - break; - case 'radio': - $params = 7; - $defind = 4; - break; - case 'textarea': - $params = 9; - $defind = 6; - break; - case 'select': - $params = 10; - $defind = 7; - break; - case 'plaintext': - $params = 4; - $defind = 3; - break; - default: - // unknown field type + // Deal with these later so they don't mess up layout. + $hidden[] = $field_index; continue 2; } - $str = '$this->display' . ucfirst($data[0]) . 'Row('; - for ($i = 1; $i <= $params; $i++) { - if ($i == $defind && $data[$defind] === null && - isset($arr[$data[1]])) - { - $str .= '$arr[\'' . $data[1] . '\']'; + + if ($this->_default_from_input + && $this->_default_params[$type] + && $field[$this->_default_params[$type]] === null + && array_key_exists($name, $input)) + { + // Grab the user input from $_GET/$_POST. + if ($this->_escape_default_from_input) { + $field[$this->_default_params[$type]] = + htmlspecialchars($input[$name]); } else { - $str .= '$data[' . $i . ']'; + $field[$this->_default_params[$type]] = $input[$name]; } - if ($i < $params) $str .= ', '; } - $str .= ');'; - eval($str); + + array_shift($field); + call_user_func_array( + array(&$this, 'display' . ucfirst($type) . 'Row'), + $field + ); } + print "</table>\n"; + for ($i = 0; $i < sizeof($hidden); $i++) { $this->displayHidden($this->fields[$hidden[$i]][1], $this->fields[$hidden[$i]][2], $this->fields[$hidden[$i]][3]); } + $this->end(); }