Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
Necuima

Test For Invalid Data - Mysql Injection Attacks

Recommended Posts

Hi,

 

Today someone tried to inject some invalid data into a contacts database table.  The data fields are just VARCHARs. Fortunately I had enough checks in there to prevent the insertion.

 

But I hastily put together the following PHP data checks to try and strengthen the defences.  Are they sufficient?  Is there a better way?  Note: there are no particularly sensitive data in this database but I'd like to prevent any 'bad' data being put into the database table.

function test_for_invalid_data($data)

 {

  // the following are 'needle in haystack' tests - stristr does a case-insensitive check

  if ((stristr($data, 'href') === FALSE) 

    && (stristr($data, 'http') === FALSE)

    && (stristr($data, '<a') === FALSE)

    && (stristr($data, 'link') === FALSE)

    && (stristr($data, 'url') === FALSE)

    && (stristr($data, '</a') === FALSE))

   { // 'needle' strings not found - good!

    return TRUE;

   }

  else

   return FALSE;

 }

Any advice will be most appreciated.

 

Necuima.

Share this post


Link to post
Share on other sites

I think you're thinking of XSS (cross-site scripting), not SQL injection.

To start, I'd recommend doing a YouTube search for "XSS" and "SQL injection", watching a few videos, and then coming back here if you have any questions.

Thanks.

Share this post


Link to post
Share on other sites

If you're just looking for characters that might reflect spam or a hack attempt, I'd included "script" and "img". 

Share this post


Link to post
Share on other sites

Thank you both for your advice - I will do as you both suggest.

 

I forgot to mention that I also always use Larry's 'escape-data' process.

 

Cheers from Oz.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...