Bluehost.com Web Hosting $6.95

Any security issues with preg_match and web form input ?

This is a discussion on Any security issues with preg_match and web form input ? within the PHP General forums, part of the PHP Programming Forums category; I accept a regex search term posted from a form, but I use $_REQUEST, so a person could throw the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-09-2003
Richard A. Devenezia
 
Posts: n/a
Default Any security issues with preg_match and web form input ?

I accept a regex search term posted from a form, but I use $_REQUEST, so a
person could throw the search term on the url if they wanted to.

Am I open to any security breaches ?

$search_term = isset ($_REQUEST ['search']) ? $_REQUEST ['search'] : '';
if ($search_term != "") {
....
$contents = join ("", file($file));
if (preg_match ("/$search_term/i", $contents)) {
}
....
}

Thanks,

--
Richard A. DeVenezia
Reply With Quote
  #2 (permalink)  
Old 12-09-2003
Chris Shiflett
 
Posts: n/a
Default Re: [PHP] Any security issues with preg_match and web form input ?

--- "Richard A. DeVenezia" <radevenz@ix.netcom.com> wrote:
> I accept a regex search term posted from a form, but I use $_REQUEST,
> so a person could throw the search term on the url if they wanted to.
>
> Am I open to any security breaches?
>
> $search_term = isset ($_REQUEST ['search']) ? $_REQUEST ['search'] : '';
> if ($search_term != "") {
> ...
> $contents = join ("", file($file));
> if (preg_match ("/$search_term/i", $contents)) {
> }
> ...
> }


Although I can't think of a specific vulnerability for this, it is a bad
practice to directly use data from the client without validating it in any
way prior.

Imagine that a random user can sit down at your desk and edit this script,
except that he can only enter code where you have $search_term in your
example above. Each time he makes a change, he executes this script to see
the result. Now, imagine that he spends day after day trying to figure out
something that he can use to compromise your script or cause it to
misbehave in some way. Now imagine that there are thousands of people all
doing this, day after day. Would you feel comfortable allowing them to
edit your code (even just this one part) and be able to test each change,
or would you rather have a look at what they entered before running the
script each time?

Hopefully you would rather make sure they entered something that looks
like a valid regular expression. Your code can take this same approach.

Hope that helps.

Chris

=====
Chris Shiflett - http://shiflett.org/

PHP Security Handbook
Coming mid-2004
HTTP Developer's Handbook
http://httphandbook.org/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:57 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0