LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2003, 07:43 PM   #1
Obi Perrin
Member
 
Registered: Nov 2002
Posts: 136

Rep: Reputation: 15
Question (PHP) Stopping Malicious Form Input


I've been reading the php manual about the security of php (in my case as an apache module) and some of the examples they give are rather frightening to say the least. So, as well as md5'ing all passwords in the database, using an unprivilged database user and turning off global_vars, I've written this little function which I run all of my input through before they're registered as variables, in the hope that it will detect malicious input:

PHP Code:
function validate($in_type$user_input)
{
    if (
$in_type == "string")
    {
        
$user_input htmlentities($user_input);
        return 
$user_input;
    }
    else if (
$in_type == "int")
    {
        if (
is_numeric($user_input))
        {
            return 
$user_input;
        }else{
            return 
"Error";
        }

    }else{
        return 
"Error";
    }

So, I would use the following to register a variable:

PHP Code:
$lang validate("string"$_GET['lang']); 
Now, I've been using this on my own apache without a problem, so I at least know that it doesn't generate any errors, but I'm wondering if anyone can see any way of still passing evil stuff into my scripts even after they're run through this? Or if they've come across different and perhaps better ways to protect against this kind of thing?

Thanks :-D

Last edited by Obi Perrin; 04-27-2003 at 07:45 PM.
 
  


Reply



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 On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
csh: variable input of the form x.y.z not accepted kpachopoulos Programming 1 07-24-2005 04:39 PM
PHP form help Zeppelin_Fan Programming 5 03-24-2005 04:47 PM
PHP to sendmail from form lawadm1 Linux - Software 1 08-16-2004 11:55 PM
php/form kev82 Programming 0 02-25-2004 06:21 PM
Protecting against malicious PHP paranoid Linux - Security 0 03-14-2003 09:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration