catrina icon indicating copy to clipboard operation
catrina copied to clipboard

Contact form sender isn't safe.

Open brunoziie opened this issue 10 years ago • 3 comments

Isn't safe use php extract function on data sent by user.

brunoziie avatar Feb 06 '15 15:02 brunoziie

Oh, seriously? what problem with this? Do you have other suggestion without use of frameworks @brunoziie?

thulioph avatar Feb 14 '15 07:02 thulioph

When you use extract(), you allow the user inject values to variables in your code. For example, you have a variable $foo in your code with a certain value, then the user sends a POST request with a field with same name. Using extract($_POST), the value of $foo will be replaced by $POST['foo'] value.

// Before extract()
$foo = 'John';

// After extract()
// $_POST => array('foo', 'Jane');
extract($_POST);

echo $foo; // outputs: Jane

You must to validate the all data sent by user and manually assign values to variable

brunoziie avatar Feb 19 '15 13:02 brunoziie

Thanks for tip @brunoziie, new ideas are welcome.

thulioph avatar Mar 29 '15 17:03 thulioph