I have a site written in PHP utilizing PDO. I am using the bindParam() function to bind to a sql insert query:
("insert into Table (id, date, data) VALUES (?, ?, ?)")
but I am able to insert a string containing
"<script>window.location="google.com"</script>"
How to prevent this?
Thanks!!!
shamittomar
46.8k12 gold badges77 silver badges81 bronze badges
asked Sep 15, 2010 at 3:26
Andy Hin
32.2k42 gold badges104 silver badges148 bronze badges
2 Answers 2
PDO is not going to stop you do that. You will need to yourself take care of the string:
- If you do not want
<script>tags at all, usestrip_tags - If you want those tags but don't want them to execute, then use
htmlentities
answered Sep 15, 2010 at 3:43
shamittomar
46.8k12 gold badges77 silver badges81 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Assuming you mean
<script>window.location="google.com"</script>
You should worry about injection protection on row display, as you don't want to fill up the database with HTML entities.
Use htmlspecialchars()[1] on pages that display what's on the database.
[1] http://www.php.net/manual/en/function.htmlspecialchars.php
2 Comments
Andy Hin
What do you mean? Shouldn't I prevent these from going into the DB in the first place?
Andrew67
Well you can either filter on input to DB or filter on output to browser, just make sure you don't filter twice. My preference at the moment is to filter on output so as not to have the DB littered with HTML entities.
default