1
tank1955
Text sanitizing question
  • 2008/11/19 0:55

  • tank1955

  • Module Developer

  • Posts: 276

  • Since: 2007/9/7 1


ShoutBox user reported a problem with slashes appearing in their posted messages. The user claims if they change my sanitizing line from $myts->addSlashes($field) to $myts->stripSlashesGPC($field) then everything works as it should.

It appears to me that $myts->displayTarea must not remove slashes that were added by magic_quotes_gpc. Correct me if I'm wrong.

My question is to cover for both states of magic_quotes_gpc would the proper sanitizing line be:
$form_field $myts->addSlashes($myts->stripSlashesGPC($field));

before storing $form_field in the database table?

Thanks in advance.

2
ghia
Re: Text sanitizing question
  • 2008/11/19 2:25

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


These are the two functions from myts:
function addSlashes($text)
{
  if (!
get_magic_quotes_gpc()) {
    
$text addslashes($text);
  }
  return 
$text;
}

function 
stripSlashesGPC($text)
{
  if (
get_magic_quotes_gpc()) {
    
$text stripslashes($text);
  }
        return 
$text;
}
So, they take both already in account for the magic quotes.
AFAIK, it is sufficient to use only the $myts->addSlashes function before storing a form value to the database.
For displaying it depends on the origin of the data: from the database it can be displayed as it is. If it is from the form (GPC) then it has to pass the stripSlashesGPC.
If it is a variable submitted to $myts->addSlashes, then it should be processed by the PHP (!) function stripslashes.
It is very important to know in every step of the program the condition of the variables, and not to repeat any of the conversions, because this will have a data change as a result.

displayTarea does nothing with stripslashes and assume a clean variable. previewTarea assumes a (GPC) variable and does a stripSlashesGPC.

3
tank1955
Re: Text sanitizing question
  • 2008/11/19 3:05

  • tank1955

  • Module Developer

  • Posts: 276

  • Since: 2007/9/7 1


thanks for your help ghia

4
ghia
Re: Text sanitizing question
  • 2008/11/19 10:19

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Now, I read that there are CSV files used as 'database' in Shoutbox. When I referred in my previous post to database, you should read MySQL database.
For other databases, different rules apply.
I think for CSV, if there is anything to do, the quotes has to be doubled in stead of slashed. It depends on the implementation of the read/write functions if such manipulations must be done by hand or are ready implemented.
Anyway it is best to start always from a clean variable.
You have to do nothing special if you use the CSV functions from PHP: fgetcsv, fputcsv and str_getcsv.

5
tank1955
Re: Text sanitizing question
  • 2009/1/10 17:00

  • tank1955

  • Module Developer

  • Posts: 276

  • Since: 2007/9/7 1


I have been doing some more reading about text sanitizing. For the next release of Video Tube I want to clean up the debug deprecated messages caused by $myts->makeTboxData4Save useage.

I am not sure if I should just change from $myts->makeTboxData4Save to $myts->addslashes. Some articles I have been reading recommend the use of mysql_real_escape_string instead of addslashes. I would like to hear your thoughts.

Login

Who's Online

297 user(s) are online (221 user(s) are browsing Support Forums)


Members: 0


Guests: 297


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits