vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   GPC cleaner.. safe procedure.. (https://vborg.vbsupport.ru/showthread.php?t=156689)

SDB 08-31-2007 09:09 AM

GPC cleaner.. safe procedure..
 
Hi

OK, I'm using the input cleaner to protect from sql inserts, etc.

But I'm clearly missing something.

I am using NOHTML to clean a text area input through $_POST.

But if i were to enter an ' in the text area it breaks the SQL, unless I use a $db->escape_string(....) function on it.

Is there a different way I'm supposed to use the cleaner?

Could someone please give me a definitive procedure for cleaning text input prior to entering it into the db?

cheers

Antivirus 08-31-2007 09:17 AM

please post your code

SDB 08-31-2007 10:25 AM

OK.. eg :

Code:


$vbulletin->input->clean_array_gpc('p', array(
        'firstname' => TYPE_NOHTML,
        'surname' => TYPE_NOHTML
        ));

$db->query_write("INSERT into foo (firstname, surname) values ('".$vbulletin->GPC['firstname']."','".$vbulletin->GPC['surname']."');


Dismounted 08-31-2007 11:18 AM

If you're only inserting to the database, only escape is required ($vbulletin->db->escape_string()), but if you're going to display that data, you will have to use the GPC cleaner (TYPE_NOHTML) as well.

SDB 08-31-2007 01:13 PM

So are you saying there is no need to clean data that is going to be inserted into the db?

I thought one of the main pureposes of the cleaner was to protect against XSS and malicious db inserts, etc?

(thanks for your replies)

Opserty 08-31-2007 01:26 PM

You are still cleaning the data with $db->escape_string()... ( to prevent SQL injections )

Like Dismounted said:
Quote:

if you're going to display that data, you will have to use the GPC cleaner (TYPE_NOHTML) as well.

SDB 08-31-2007 02:23 PM

OK..

I'm with you now, thank you.

If the user enteres some text, and I want to store it in the db, and then later display it..

A safe procedure that will protect me from malicious use of the system is to GPC it for TYPE_NOHTML, and then escape_string it also?

Please confirm.

-

Also, having done this..

If someone enters a ' or a &, by the time I get it back out of the db and back into the text area, it had & type codes rather than the characters. How do I handle these please?

Thanks again, I really appreciate this.

Simon

Opserty 08-31-2007 04:40 PM

Quote:

Originally Posted by SDB (Post 1329513)
O
Also, having done this..

If someone enters a ' or a &, by the time I get it back out of the db and back into the text area, it had & type codes rather than the characters. How do I handle these please?

Thanks again, I really appreciate this.

Simon

Well in that case clean it using TYPE_STR and escape it and store it in the db. Then when you come to display it (except in the textarea) use htmlspecialchars_uni() on the text. Or if you want to be fancy you can use vB's BBcode parser :P.

SDB 08-31-2007 04:50 PM

aah, great. I'll use TYPE_STR

If i use the bbcode parser, and set everything to false, does it do any parsing at all?

I already have the parser instatiated, so it would be nice to use that, but I don't want smilies or basically anything to parsed. I just want to make it safe.

Thanks again

Simon

Paul M 08-31-2007 06:33 PM

The input cleaner is not designed to prevent SQL injection - that's what escape_string is for.


All times are GMT. The time now is 08:14 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01178 seconds
  • Memory Usage 1,734KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete