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.
 
 
 
 
 
 
Rob Richards be974aff6e Fix bug #26159 - SimpleXML XPath support (patch by Adam Trachtenberg) 22 years ago
TSRM - Don't fix include_once() case sensitivity problem for beta 2. 22 years ago
Zend ChangeLog update 22 years ago
build Fix buildconf for systems using coreutils-5.0 22 years ago
ext Fix bug #26159 - SimpleXML XPath support (patch by Adam Trachtenberg) 22 years ago
main Fix for file:// wrapper parsing. 22 years ago
netware updating license information in the headers. 23 years ago
pear * Fix potential warning 22 years ago
regex Fixed bug #25669 (eregi() with non-ascii characters) 22 years ago
sapi proto fix 22 years ago
scripts Missing "confdefs.h" in the cleanup-files-list 22 years ago
tests Add new iterator test inspired by bug #26527 22 years ago
win32 change names to php5_xxx in NSAPI 22 years ago
.gdbinit Fixed printzn part. 23 years ago
CODING_STANDARDS - Update codinf standards with the posted RFC (results from PEAR Meeting) 23 years ago
CREDITS Let's pretend this is up-to-date now 24 years ago
ChangeLog ChangeLog update 22 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
EXTENSIONS - Email address change 22 years ago
INSTALL Update documentation for PHP 5. 23 years ago
LICENSE Bump year. 23 years ago
Makefile.frag - Fixed bug: #13561 (--without-pear prevents install of phpize, php-config) 23 years ago
Makefile.global When encountering a test that users GET/POST make run-tests.php use CGI 23 years ago
NEWS Added php_strip_whitespace() and php_check_syntax() functions. 22 years ago
README.CVS-RULES No exceptions. 24 years ago
README.EXTENSIONS * zend_module_entry change: apino, debug and zts are moved first, 24 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 - Whitespace 23 years ago
README.QNX PHP 4.0 27 years ago
README.SELF-CONTAINED-EXTENSIONS Improve the wording in this paragraph. 23 years ago
README.STREAMS Added notes about locking functions. 23 years ago
README.SUBMITTING_PATCH - Fixed email address 23 years ago
README.TESTING Update documentation for PHP 5. 23 years ago
README.TESTING2 many new enhancements to run-tests that allow for testing cgi and other 23 years ago
README.UNIX-BUILD-SYSTEM Update documentation for PHP 5. 23 years ago
README.Zeus Update build instructions for Zeus web server 23 years ago
README.input_filter An input filter might not simply strip stuff, it might also turn things 23 years ago
TODO No more vectors 23 years ago
TODO-PHP5 The basic input filtering framework is done and working nicely 23 years ago
TODO.BUILDv5 phpize is already working, remove from todo 24 years ago
acconfig.h.in Wipe out acconfig.h.in and rewrite some checks to use PHP_ARG_ENABLE. 26 years ago
acinclude.m4 - Fixed build of shared extensions which require openssl and when you only 22 years ago
buildconf First shot at making ze1/ze2 coexist 23 years ago
config.guess upgrade files to libtool 1.4.3 shipped ones 23 years ago
config.sub upgrade files to libtool 1.4.3 shipped ones 23 years ago
configure.in Added configure check for nanosleep() availability. 22 years ago
cvsclean "User interface" for removing all files which are ignored by cvs 26 years ago
footer consistent with the used style 23 years ago
genfiles - Hope this is the last commit in the series. Make sure that the .h file 24 years ago
header Is the version 5 now? :) 22 years ago
ltmain.sh - Updated libtool to 1.4.3 which has test for the sed problem.. 23 years ago
makedist what's a php5? 23 years ago
makerpm Make this work again 22 years ago
php.gif 2 years is ages.... and no way temporary. changed the php4 logo to a versionless one. 24 years ago
php.ini-dist Removed entries which no longer have no function 22 years ago
php.ini-recommended Removed entries which no longer have no function 22 years ago
php4.spec.in MFB 23 years ago
run-tests-config.php many new enhancements to run-tests that allow for testing cgi and other 23 years ago
run-tests.php This check is no longer needed (Andrei) 22 years ago
run-tests2.php updating license information in the headers. 23 years ago
snapshot Integration of -ng changes. Changes: 26 years ago
stamp-h.in # Fix ColorResolve bogosity 26 years ago
stub.c Add newline. Recent GCC snapshots segfault, if the input file is completely 25 years ago

README.input_filter

Input Filter Support in PHP5
----------------------------

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 PHP5 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.

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)

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

unsigned int my_sapi_input_filter(int arg, char *var, char **val, unsigned int val_len)
{
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);

return strlen(*val);
}

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|l", &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);
}