Jump to content

Escaping data


tibberous

Recommended Posts

I finally said hell with it and just started to try and break my web app. I came up with this test:

 

'"<  \“smart quotes”  >"'

 

'"<  \“smart quotes”  >"'

 

'"<  \“smart quotes”  >"'

 

If my app could pass that through all it's fields, it was secure. The problem is that it blew it up. Alot.

 

So, I came up with the idea of keeping the data unescaped in the database, and to use escape functions to display the data based on the context I was using it. So, it was in an xml file, I'd go x($username), but if it was in a line of javascript code, I'd use e($username). And d was for the database, and h was for html.

 

I've used a ton of different methods, but this seems to be the cleanest way I've found. The functions themselves are simple too:

 

function x($input){
	$input = str_replace(array('"', "'", "<", ">", "\r\n", "\n", chr(145), chr(146), chr(147), chr(148), chr(151)), array(""", "&#39;", "<", ">", "\r", "\n", "'", "'", '"', '"', '-'), $input);
	return trim($input);
}

 

How would you guys recommend to consistently escape data?

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.