You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Zoe Slattery ffa06648fd bc math tests from testfest 2009 17 years ago
TSRM - fix #44683, popen crashes when an invalid mode is passed (works on 2k8/vista/win7) 17 years ago
Zend Test from 2009 testfest 17 years ago
build Add actions for the gitclean target. 17 years ago
ext bc math tests from testfest 2009 17 years ago
main - Fixed bug #49248 by fixing bug #48994 properly 17 years ago
netware MFH: Bump copyright year, 3 of 3. 17 years ago
pear add missing fetch.php 17 years ago
regex MFH 18 years ago
sapi - fix build (pls at least try to compile before committing) 17 years ago
scripts MFH:- Fixed bug #48661 (phpize broken with non-bash shells) 17 years ago
tests More tests from 2009 testfest 17 years ago
win32 - silent warning (fix for #28038) 17 years ago
.gdbinit - Added a function to print all CVs from the local scope. 17 years ago
CODING_STANDARDS Multi-branch test commit to see if email notifications are working 17 years ago
CREDITS Let's pretend this is up-to-date now 24 years ago
ChangeLog ChangeLog update 21 years ago
ChangeLog.1999.gz * separated and compressed changelogs from 1999 and 2000 25 years ago
ChangeLog.2000.gz * separated and compressed changelogs from 1999 and 2000 25 years ago
ChangeLog.2001.gz * archive the 2001 changelog 24 years ago
ChangeLog.2002.gz rotate changelog 23 years ago
ChangeLog.2003.gz - Compress 2003 changelog 22 years ago
ChangeLog.2004.gz - Compressed 2004 Changelog 21 years ago
EXTENSIONS MFH 18 years ago
INSTALL cvs->svn 17 years ago
LICENSE Update license to 3.01 20 years ago
Makefile.frag - Allow build without flex/bison installed (fixes builddir != srcdir build 19 years ago
Makefile.gcov remove --show-details from lcov's genhtml, as currently we don't separate the coverage data per test, making this option useless 19 years ago
Makefile.global - There is only one Makefile that needs removing 17 years ago
NEWS - fix #49372, segfault in php_curl_option_url 17 years ago
README.EXTENSIONS * zend_module_entry change: apino, debug and zts are moved first, 25 years ago
README.EXT_SKEL ok, re-adding this mostly un-maintained awk/sed/sh nightmare for now ... 23 years ago
README.PARAMETER_PARSING_API - MFH: Fix type in example 19 years ago
README.PHP4-TO-PHP5-THIN-CHANGES new incompatibilities. maybe someone from the doc group will update the 22 years ago
README.QNX PHP 4.0 27 years ago
README.SELF-CONTAINED-EXTENSIONS Improve the wording in this paragraph. 24 years ago
README.STREAMS Added notes about locking functions. 23 years ago
README.SUBMITTING_PATCH cvs->svn 17 years ago
README.SVN-RULES MFH: cvs->svn 17 years ago
README.TESTING clarification of wwwhether 'make test' needs the PHP xecutable to be set 17 years ago
README.TESTING2 Fixed bug#46445 (run-tests2.php is missing or README.TESTING2 is unneeded) 18 years ago
README.UNIX-BUILD-SYSTEM Update documentation for PHP 5. 23 years ago
README.UPDATE_5_2 - add notice about glob regression (Lukas) 19 years ago
README.WIN32-BUILD-SYSTEM Now that it has matured somewhat, don't discourage questions about it 23 years ago
README.Zeus - Change from PHP5 -> PHP 5 22 years ago
README.input_filter Pierre requested an update to this. I don't think it makes sense to 20 years ago
TODO Removed completed TODO items 19 years ago
TODO-5.1 Slated for PHP 6 21 years ago
TODO-PHP5 Update TODO: filter extension was added 19 years ago
UPGRADING Multi-branch test commit to see if email notifications are working 17 years ago
acconfig.h.in Wipe out acconfig.h.in and rewrite some checks to use PHP_ARG_ENABLE. 26 years ago
acinclude.m4 - Simplify default flags for Sun C compiler. 17 years ago
buildconf - Removed unused parts 17 years ago
buildconf.bat MFH: 17 years ago
config.guess - Update bundled libtool to 1.5.20 21 years ago
config.sub - Update bundled libtool to 1.5.20 21 years ago
configure.in Back to dev 17 years ago
footer consistent with the used style 23 years ago
genfiles MFH 21 years ago
header Update copyright year 19 years ago
ltmain.sh - Update bundled libtool to 1.5.20 21 years ago
makedist MFH: CVS->SVN 17 years ago
makerpm - Change from PHP5 -> PHP 5 22 years ago
php.gif fix logo (proper spacing between the letters) 20 years ago
php.ini-dist MFH: Revert previous change 17 years ago
php.ini-recommended - MFH: Fix typo. 17 years ago
php5.spec.in - Renamed all *php4* files to *php5*, changed all php4/PHP4 to php5/PHP5 22 years ago
run-tests.php sync run-tests.php with revision 286499 changes making php 6 tests with EXPECTF that can have arbitrary binary data in output work 17 years ago
server-tests-config.php - MFH Fix filename 21 years ago
server-tests.php MFH: Bump copyright year, 3 of 3. 17 years ago
snapshot Integration of -ng changes. Changes: 27 years ago
stamp-h.in # Fix ColorResolve bogosity 27 years ago
stub.c Add newline. Recent GCC snapshots segfault, if the input file is completely 26 years ago
svnclean.bat - rename to svn 17 years ago
vcsclean MFH: dropped some more mime types, svnclean -> clean for multiple VCS 17 years ago

README.input_filter

Input Filter Support in PHP 5
-----------------------------

XSS (Cross Site Scripting) hacks are becoming more and more prevalent,
and can be quite difficult to prevent. Whenever you accept user data
and somehow display this data back to users, you are likely vulnerable
to XSS hacks.

The Input Filter support in PHP 5 is aimed at providing the framework
through which a company-wide or site-wide security policy can be
enforced. It is implemented as a SAPI hook and is called from the
treat_data and post handler functions. To implement your own security
policy you will need to write a standard PHP extension. There is also
a powerful standard implementation in ext/filter that should suit most
peoples' needs. However, if you want to implement your own security
policy, read on.

A simple implementation might look like the following. This stores the
original raw user data and adds a my_get_raw() function while the normal
$_POST, $_GET and $_COOKIE arrays are only populated with stripped
data. In this simple example all I am doing is calling strip_tags() on
the data. If register_globals is turned on, the default globals that
are created will be stripped ($foo) while a $RAW_foo is created with the
original user input.

ZEND_BEGIN_MODULE_GLOBALS(my_input_filter)
zval *post_array;
zval *get_array;
zval *cookie_array;
ZEND_END_MODULE_GLOBALS(my_input_filter)

#ifdef ZTS
#define IF_G(v) TSRMG(my_input_filter_globals_id, zend_my_input_filter_globals *, v)
#else
#define IF_G(v) (my_input_filter_globals.v)
#endif

ZEND_DECLARE_MODULE_GLOBALS(my_input_filter)

zend_function_entry my_input_filter_functions[] = {
PHP_FE(my_get_raw, NULL)
{NULL, NULL, NULL}
};

zend_module_entry my_input_filter_module_entry = {
STANDARD_MODULE_HEADER,
"my_input_filter",
my_input_filter_functions,
PHP_MINIT(my_input_filter),
PHP_MSHUTDOWN(my_input_filter),
NULL,
PHP_RSHUTDOWN(my_input_filter),
PHP_MINFO(my_input_filter),
"0.1",
STANDARD_MODULE_PROPERTIES
};

PHP_MINIT_FUNCTION(my_input_filter)
{
ZEND_INIT_MODULE_GLOBALS(my_input_filter, php_my_input_filter_init_globals, NULL);

REGISTER_LONG_CONSTANT("POST", PARSE_POST, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GET", PARSE_GET, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("COOKIE", PARSE_COOKIE, CONST_CS | CONST_PERSISTENT);

sapi_register_input_filter(my_sapi_input_filter);
return SUCCESS;
}

PHP_RSHUTDOWN_FUNCTION(my_input_filter)
{
if(IF_G(get_array)) {
zval_ptr_dtor(&IF_G(get_array));
IF_G(get_array) = NULL;
}
if(IF_G(post_array)) {
zval_ptr_dtor(&IF_G(post_array));
IF_G(post_array) = NULL;
}
if(IF_G(cookie_array)) {
zval_ptr_dtor(&IF_G(cookie_array));
IF_G(cookie_array) = NULL;
}
return SUCCESS;
}

PHP_MINFO_FUNCTION(my_input_filter)
{
php_info_print_table_start();
php_info_print_table_row( 2, "My Input Filter Support", "enabled" );
php_info_print_table_row( 2, "Revision", "$Revision$");
php_info_print_table_end();
}

/* The filter handler. If you return 1 from it, then PHP also registers the
* (modified) variable. Returning 0 prevents PHP from registering the variable;
* you can use this if your filter already registers the variable under a
* different name, or if you just don't want the variable registered at all. */
SAPI_INPUT_FILTER_FUNC(my_sapi_input_filter)
{
zval new_var;
zval *array_ptr = NULL;
char *raw_var;
int var_len;

assert(*val != NULL);

switch(arg) {
case PARSE_GET:
if(!IF_G(get_array)) {
ALLOC_ZVAL(array_ptr);
array_init(array_ptr);
INIT_PZVAL(array_ptr);
}
IF_G(get_array) = array_ptr;
break;
case PARSE_POST:
if(!IF_G(post_array)) {
ALLOC_ZVAL(array_ptr);
array_init(array_ptr);
INIT_PZVAL(array_ptr);
}
IF_G(post_array) = array_ptr;
break;
case PARSE_COOKIE:
if(!IF_G(cookie_array)) {
ALLOC_ZVAL(array_ptr);
array_init(array_ptr);
INIT_PZVAL(array_ptr);
}
IF_G(cookie_array) = array_ptr;
break;
}
Z_STRLEN(new_var) = val_len;
Z_STRVAL(new_var) = estrndup(*val, val_len);
Z_TYPE(new_var) = IS_STRING;

var_len = strlen(var);
raw_var = emalloc(var_len+5); /* RAW_ and a \0 */
strcpy(raw_var, "RAW_");
strlcat(raw_var,var,var_len+5);

php_register_variable_ex(raw_var, &new_var, array_ptr TSRMLS_DC);

php_strip_tags(*val, val_len, NULL, NULL, 0);

*new_val_len = strlen(*val);
return 1;
}

PHP_FUNCTION(my_get_raw)
{
long arg;
char *var;
int var_len;
zval **tmp;
zval *array_ptr = NULL;
HashTable *hash_ptr;
char *raw_var;

if(zend_parse_parameters(2 TSRMLS_CC, "ls", &arg, &var, &var_len) == FAILURE) {
return;
}

switch(arg) {
case PARSE_GET:
array_ptr = IF_G(get_array);
break;
case PARSE_POST:
array_ptr = IF_G(post_array);
break;
case PARSE_COOKIE:
array_ptr = IF_G(post_array);
break;
}

if(!array_ptr) RETURN_FALSE;

/*
* I'm changing the variable name here because when running with register_globals on,
* the variable will end up in the global symbol table
*/
raw_var = emalloc(var_len+5); /* RAW_ and a \0 */
strcpy(raw_var, "RAW_");
strlcat(raw_var,var,var_len+5);
hash_ptr = HASH_OF(array_ptr);

if(zend_hash_find(hash_ptr, raw_var, var_len+5, (void **)&tmp) == SUCCESS) {
*return_value = **tmp;
zval_copy_ctor(return_value);
} else {
RETVAL_FALSE;
}
efree(raw_var);
}