PHP_SELF and XSS

To make it safe to use you need to use htmlspecialchars(). <?php echo htmlspecialchars($_SERVER[“PHP_SELF”], ENT_QUOTES, “utf-8”); ?> See A XSS Vulnerability in Almost Every PHP Form I’ve Ever Written for how $_SERVER[“PHP_SELF”] can be attacked.

Do htmlspecialchars and mysql_real_escape_string keep my PHP code safe from injection?

When it comes to database queries, always try and use prepared parameterised queries. The mysqli and PDO libraries support this. This is infinitely safer than using escaping functions such as mysql_real_escape_string. Yes, mysql_real_escape_string is effectively just a string escaping function. It is not a magic bullet. All it will do is escape dangerous characters in … Read more

CSRF, XSS and SQL Injection attack prevention in JSF

XSS JSF is designed to have builtin XSS prevention. You can safely redisplay all user-controlled input (request headers (including cookies!), request parameters (also the ones which are saved in DB!) and request bodies (uploaded text files, etc)) using any JSF component. <h:outputText value=”#{user.name}” /> <h:outputText value=”#{user.name}” escape=”true” /> <h:inputText value=”#{user.name}” /> etc… Note that when … Read more

XSS prevention in JSP/Servlet web application

XSS can be prevented in JSP by using JSTL <c:out> tag or fn:escapeXml() EL function when (re)displaying user-controlled input. This includes request parameters, headers, cookies, URL, body, etc. Anything which you extract from the request object. Also the user-controlled input from previous requests which is stored in a database needs to be escaped during redisplaying. … Read more

How to prevent XSS with HTML/PHP?

Basically you need to use the function htmlspecialchars() whenever you want to output something to the browser that came from the user input. The correct way to use this function is something like this: echo htmlspecialchars($string, ENT_QUOTES, ‘UTF-8’); Google Code University also has these very educational videos on Web Security: How To Break Web Software … Read more

xss attack on a php page

An XSS attack is one in which the page allows allows users to inject script blocks into the rendered HTML. So, first you must figure out how to do that. For instance, if the input from the user gets displayed on the page and it isn’t html escaped then a user could do the following: … Read more