Jump to content

Security Question...


DamienRoche

Recommended Posts

Ok, so everybody knows you are meant to use addslashes on input before adding data to a database.

 

But what if you use a preg_match and regexp to halt the script if any input contains special characters.

 

I currently use the second method I mentioned above and that works fine, but is there any way to bypass this?

 

Bottom line..am I opening myself up for sql injection etc. or would you consider this secure enough?

 

Damien.

Link to comment
Share on other sites

I've used mysql_real_escape_string as well. But what do you think about using regexp to just stop the script in it's tracks?

 

I mean, I don't filter the input because some fields shouldn't have special characters. I just use an if preg_match and regexp to detect the character and stop the script.

 

I guess really what I'm asking is: can the regexp solution be bypassed?

 

..can a special character get passed a preg_match? it doesn't seem possible..but I am a noob  ???

 

I should have also noted, this was more a discussion than a problem >> solution thing.

Link to comment
Share on other sites

There's many instances where I don't mind users adding special characters, basically because they might need or want to, for instance if there blogging and want to use any kind of speech marks.

 

Yes it's possible to formulate a regex statement to catch any defined characters, banned words, emails etc. And no there shouldn't be a way around it unless they get at the code.

Link to comment
Share on other sites

 

Care to elaborate as to how using regex is better?

 

edit:

 

For SQL injection attacks, that is.

 

Simple, the stricter you are with data, the less chance that an unknown loophole with mysql_real_escape_string() will affect your script.

 

At most points people will apply multiple filters to get user data from a form on to a page... real_escape.. htmlentities/specialchars are extremely common. This can be done with a single regex prior to insertion, and will save from potential holes in 2 functions.

 

I'm not saying there's anything wrong with mysql_real_escape_string()... I'm just saying regex is more secure, and situation depending, better.

Link to comment
Share on other sites

What doesn't 'mysql_real_escape_string()' catch (e.g. 2 functions)?

 

And my age old (never satisfyingly answered question), surely 'addslashes()' is faster...

 

Code what you want... I'm just saying that using strict regex rules is more secure. Speed isn't always the 'best' solution.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.