TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-25-2009, 09:22 PM   #1 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
knight13 is on a distinguished road
Default html form field security?

I know that any field you can write in is a security risk if you do not validate the info first, and it can hurt your database.

What i am wondering is their any security risk's with drop down menus, radio buttons or check boxes since they can not be written in only selected.
__________________
Anyone who has never made a mistake has never tried anything new.
~ Albert Einstein ~
knight13 is offline  
Reply With Quote
Old 06-25-2009, 09:26 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,216
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by knight13 View Post
I know that any field you can write in is a security risk if you do not validate the info first, and it can hurt your database.

What i am wondering is their any security risk's with drop down menus, radio buttons or check boxes since they can not be written in only selected.
Thats not technically true, they are passed in plain text via either GET or POST regardless of how the message is collected. All GET and POST data can easily be forged. HTML forms are just a way to gather the information before sending it.

If you use firefox, try a tool called Tamper to see how forms work.
Village Idiot is offline  
Reply With Quote
Old 06-25-2009, 09:40 PM   #3 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
knight13 is on a distinguished road
Default

I downloaded what you said but what exactly do i do with it now?
__________________
Anyone who has never made a mistake has never tried anything new.
~ Albert Einstein ~
knight13 is offline  
Reply With Quote
Old 06-25-2009, 09:42 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Default

Although you see a radio box, or a check box, HTTP doesn't have a clue, nor care too much, what the object was beforehand. Whether it's a text box or a radio box, the data is still passed through in the format of key to value, whether it's GET or POST.

Here's a picture of my POST for this message:



Notice the POST data under the Cache-Control parameter, which is just a GET sent in the actual request.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-25-2009, 09:50 PM   #5 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
knight13 is on a distinguished road
Default

I have no idea what you mean.

So basically you are saying that select menus, radio buttons and checkboxes can be messed with?

If so how do they do it? and how do i protect against it?
__________________
Anyone who has never made a mistake has never tried anything new.
~ Albert Einstein ~
knight13 is offline  
Reply With Quote
Old 06-25-2009, 09:55 PM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,239
Thanks: 3
Salathe is on a distinguished road
Default

Quote:
Originally Posted by knight13 View Post
So basically you are saying that select menus, radio buttons and checkboxes can be messed with?

If so how do they do it? and how do i protect against it?
Absolutely, they can be messed with, missed out, etc. There's absolutely no requirement for a form to even exist! Someone could write a (very simple!) PHP script to pretend they're submitting your form but with any values that they like (malicious or not).

How to protect against it? As you would any other user input. Filter it, validate it, etc..
__________________
salathe@php.net
Salathe is offline  
Reply With Quote
Old 06-25-2009, 09:57 PM   #7 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Default

Every single HTML element is the same once you've submitted the data for that form. All you see when you see a radio box, or a check box, are elements that facilitate filling in forms, but a check box can quite easily contain any value. Whatever you specify in the value attribute.

html4strict Code:
<input type="checkbox" name="myCheckbox" value="This is a string in a check-box" />

And then try and submit that and see what you get on the other end.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-25-2009, 10:10 PM   #8 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
knight13 is on a distinguished road
Default

So i would do it like this then

html code
HTML Code:
<input type="checkbox" name="myCheckbox" value="This is a string in a check-box" />
validated code
PHP Code:
    if(isset($_POST['myCheckbox'])) {
    
$check $_POST['myCheckbox'];
    
$check mysql_real_escape_string($check);
    } 
__________________
Anyone who has never made a mistake has never tried anything new.
~ Albert Einstein ~
knight13 is offline  
Reply With Quote
Old 06-26-2009, 06:12 PM   #9 (permalink)
The Contributor
 
ryanmr's Avatar
 
Join Date: Jun 2008
Location: Twin Cities, Minnesota, USA
Posts: 50
Thanks: 3
ryanmr is on a distinguished road
Default

For a checkbox, you might be looking for it to send back true or false or maybe 1 or 0, so when validating the checkbox, you can check for those specific values and have your scripts main flow react based on those true/false values.
Here's some code to show what I mean.

php Code:
if ( isset($_POST["form_submitted"]) ) { // is the form submitted
    $checkbox = $_POST["the_checkbox"]; // get the value of the checkbox, it does not matter what it _could_ be
    $checkbox_state = false; // default to false
    switch ($checkbox) { // checking specific values here, true and false, always defaulting to false
        case "true":
            $checkbox_state = true;
            break;
        case "false":
            $checkbox_state = false;
            break;
        default:
            $checkbox_state = false;
    }
   
   
    // ... later in code somewhere ...
   
    if ( $checkbox_state == true) {
        // do some action
    } else {
        // don't do some action
    }
}
__________________
blog twitter ifupdown
ryanmr is offline  
Reply With Quote
Old 06-26-2009, 06:22 PM   #10 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
knight13 is on a distinguished road
Default

Thanks ryanmr.
__________________
Anyone who has never made a mistake has never tried anything new.
~ Albert Einstein ~
knight13 is offline  
Reply With Quote
Old 06-26-2009, 06:28 PM   #11 (permalink)
The Contributor
 
ryanmr's Avatar
 
Join Date: Jun 2008
Location: Twin Cities, Minnesota, USA
Posts: 50
Thanks: 3
ryanmr is on a distinguished road
Default

Glad I could help.

The code I posted had a switch statement in it and it was not nessesary. Here's a partial update, the same code, just with an if/else instead of a switch.

php Code:
$checkbox = $_POST["the_checkbox"]; // get the value of the checkbox, it does not matter what it _could_ be
   
    // A switch isn't needed there, a simple if/else is better.
   
    if ( $checkbox == "true" ) {
        $checkbox = true;
    } else {
        $checkbox = false;
    }

This now overwrites the original post value stored in $checkbox making for less variables and cleaner code.
__________________
blog twitter ifupdown
ryanmr is offline  
Reply With Quote
Old 06-26-2009, 06:50 PM   #12 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
knight13 is on a distinguished road
Default

I like the second code better.
__________________
Anyone who has never made a mistake has never tried anything new.
~ Albert Einstein ~
knight13 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to do form handling(validation and security) in php planepixel Absolute Beginners 7 06-27-2009 01:19 AM
Form Validation Not Working :( Guezala Absolute Beginners 27 05-13-2009 08:28 PM
Refresh an input field delayedinsanity Javascript, AJAX, E4X 5 07-27-2008 07:48 AM
Exciting Stuff in HTML 5! Wildhoney XHTML, HTML, CSS 16 12-07-2007 12:25 PM
Form Processing William Tips & Tricks 8 04-17-2005 03:24 PM


All times are GMT. The time now is 01:32 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design