tags:

views:

54

answers:

4

I am accepting user text in a form and echoing it back on the page (the code goes to the database as well but that is prepared queries so no worries there). I wanted to know if there are any possible security implications that can be caused by it? On the server side I mean, i know on the client side you can break but can you reach server side?

I need to know if something like eval can be possibly done with this case.

A: 

use htmlspecialchars($yourstring) in php, or strip characters, no need to open possibilities for exploits.

Stempy
are any server side exploits possible? can you give an example?
pinaki
elaborate on server side exploits? XSS is a server side exploit. (in effect) User input if not sanitised can wipe entire databases or do all kinds of unwanted things, read up SQL injection.
Ross
A: 

If you use the user input directly to query an SQL database, you can be subjected to SQL injections. Just google it for examples.

EDIT: Oh, I missed the text saying that you just echo the text. Hm, well, maybe the user can issue PHP commands if you evaluate the user input. But I don't know why you should do that because then the user could issue any PHP commands to the server (which is a clear security risk)...

gablin
i am not doing an eval.. so this case does not exist..
pinaki
+2  A: 

The scenario you explained is called XSS. It is possible to compromise your server with the help of an XSS vulnerability, but it does need other things to fall in place.

Say you have an administrator account that has permissions to make configuration changes to your server over the web. Now, if an attacker creates a XSS link and somehow gets the administrator to click it, his account would be compromised.

Once the attacker has administrator access, he can systematically take control of the entire system. This happened recently with Apache - read their article on it. It is the best write-up on a security incident I have ever seen, you will learn a lot from it.

sri
+1. nice article.. you miss the whole point though.. i am not worried about client side injection and what effects it can have.. i need to know if it can have any server side implications. thanks for the effort.
pinaki
@pinaki - It can affect server side as well, **if** you are doing some kind server include/eval based on user provided content. For example, see this page - http://www.owasp.org/index.php/File_System#Includes_and_Remote_files
sri
@pinaki .. but apart from that, XSS cannot directly cause harm to the server; its a client side thing.
sri
hmm.. yours seems to be the only conclusive answer around, so gonna accept it.. thanks.. do let me know if you have any other such posts..
pinaki
A: 

Use:

echo htmlentities($string);

Everywhere. Unless you want to open your application to dozens of possible attacks:

http://ha.ckers.org/xss.html

If you need to echo a HTML markup:

1) Use HTMLPurifier on the HTML before saving it to the database.

2) I recommend to use XHTML STRICT filtering.

3) Disallow tags like scripts, frame, attributes like onclick etc. The list of tags and attributes users entering HTML should never need is quite long. Just restrict them to what they might need, e.g.: p, ol, ul, h1, h2, h3, dl, abbr, img (these can be dangerous, many possible attacks through img tag, be careful), a (detto), table, maybe few more.

Richard Knop