At https://www.owasp.org/index.php/PHP_Top_5#How_to_Determine_if_you_are_Vulnerable_2 link, under title P2: Cross-site scripting > How to Protect Against It; in item 4 and 5 it's written that:
- item 4: Free text input can only be safely re-displayed to the user after using HTML entities
- item 5: Variables sent back to the user via URLs must be URL encoded using urlencode(), although the use of GET requests is deprecated for anything besides navigation purposes
My Questions
Q1
For item 4 it's explicitly said that can only but I remember I read that htmlspecialchars()
is enough & more efficient vs htmlentities()
. (An example source link about superiority of htmlspecialchars
. Please read the comment of Pornel_: What are the best practices for avoiding xss attacks in a PHP site) So I am confused after this input of OWASP. Should I replace my htmlspecialchars()
with htmlentities()
that I use while I print the MySQL user inputted data to the screen as html.
Q2
For my forms (add article, add comment, e-mail to admin) I utilize Post - Redirect - Session Variables
flow. (My explanation may be stupid for you but I mean I don't use GET
at the 3rd step of my flow. Instead of GET
, I utilize Session
variables.) So still do I need to use urlencode()
somewhere on Session
variables? (Note: Even if you yes, I don't know HOW, that's another topic for me to study, for the time being I only want to learn yes or no and why cause I couldn't find the answer of this question in my research. of course if you define HOW part also, it will be really appreciated)
thanks in advance
Best regards
htmlspecialchars
is okey. – Andre Chenier