Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cross-site scripting (xss) attack

Tags:

php

xss

I just have one simple question about XSS attack. I know that you can prevent them by sanitizing the form inputs, but my question is, how about a search input (a general search on a website for example)? Should we sanitize search inputs as well? I mean, it's just a search input, the user should be able to search for anything that he/she wants on the website. Please provide me with some clarification on this.

Thank you

like image 249
user765368 Avatar asked Dec 12 '22 12:12

user765368


2 Answers

I know that you can prevent them by sanitizing the form inputs

nope, you should prevent them by sanitizing the output. So in database (or wherever) you need to pass the data as-is, and process it right before you show it to user

like image 53
zerkms Avatar answered Dec 15 '22 02:12

zerkms


Tho this has already been answered by zerkms

Doing sanitizing on sql injections from any user input that touches the database requires mysql_real_escape_string($_REQUEST['search'])

On output if your showing what user searched for like "You searched for:" use htmlentities(strip_tags($_REQUEST['search']), ENT_QUOTES);

Then your safe from incoming and outgoing

like image 30
Lawrence Cherone Avatar answered Dec 15 '22 02:12

Lawrence Cherone