 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
06-25-2009, 09:22 PM
|
#1 (permalink)
|
|
The Frequenter
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
|
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 ~
|
|
|
|
06-25-2009, 09:26 PM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,216
Thanks: 17
|
Quote:
Originally Posted by knight13
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.
|
|
|
|
06-25-2009, 09:40 PM
|
#3 (permalink)
|
|
The Frequenter
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
|
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 ~
|
|
|
|
06-25-2009, 09:42 PM
|
#4 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
|
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.
|
|
|
06-25-2009, 09:50 PM
|
#5 (permalink)
|
|
The Frequenter
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
|
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 ~
|
|
|
|
06-25-2009, 09:55 PM
|
#6 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,239
Thanks: 3
|
Quote:
Originally Posted by knight13
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
|
|
|
|
06-25-2009, 09:57 PM
|
#7 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
|
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.
|
|
|
06-25-2009, 10:10 PM
|
#8 (permalink)
|
|
The Frequenter
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
|
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 ~
|
|
|
|
06-26-2009, 06:12 PM
|
#9 (permalink)
|
|
The Contributor
Join Date: Jun 2008
Location: Twin Cities, Minnesota, USA
Posts: 50
Thanks: 3
|
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 } }
|
|
|
|
06-26-2009, 06:22 PM
|
#10 (permalink)
|
|
The Frequenter
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
|
Thanks ryanmr.
__________________
Anyone who has never made a mistake has never tried anything new.
~ Albert Einstein ~
|
|
|
|
06-26-2009, 06:28 PM
|
#11 (permalink)
|
|
The Contributor
Join Date: Jun 2008
Location: Twin Cities, Minnesota, USA
Posts: 50
Thanks: 3
|
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.
|
|
|
|
06-26-2009, 06:50 PM
|
#12 (permalink)
|
|
The Frequenter
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
|
I like the second code better. 
__________________
Anyone who has never made a mistake has never tried anything new.
~ Albert Einstein ~
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|