Cross-Site Forgery http://www.flickr.com/photos/torkildr/3462607995/

Slides:



Advertisements
Similar presentations
Nick Feamster CS 6262 Spring 2009
Advertisements

Cross-site Request Forgery (CSRF) Attacks
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
COMP 321 Week 12. Overview Web Application Security  Authentication  Authorization  Confidentiality Cross-Site Scripting Lab 12-1 Introduction.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
It’s always better live. MSDN Events Securing Web Applications Part 1 of 2 Understanding Threats and Attacks.
Introduction to InfoSec – Recitation 10 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Origins, Cookies and Security – Oh My! John Kemp, Nokia Mobile Solutions.
WEB SECURITY WEEK 3 Computer Security Group University of Texas at Dallas.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Lecture 14 – Web Security SFDV3011 – Advanced Web Development 1.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
Robust Defenses for Cross-Site Request Forgery CS6V Presented by Saravana M Subramanian.
© All rights reserved. Zend Technologies, Inc. PHP Security Kevin Schroeder Zend Technologies.
Lecture 16 Page 1 CS 236 Online SQL Injection Attacks Many web servers have backing databases –Much of their information stored in a database Web pages.
Feedback #2 (under assignments) Lecture Code:
Security Scanners Mark Shtern. Popular attack targets Web – Web platform – Web application Windows OS Mac OS Linux OS Smartphone.
PHP2010/11 : [‹#›] PHP Security. PHP2010/11 : [‹#›] Two Golden Rules 1.FILTER external input Obvious.. $_POST, $_COOKIE, etc. Less obvious.. $_SERVER.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
BIT 286: Web Applications Lecture 10 : Thursday, February 5, 2015 ASP.Net Form Submission.
Web Database Programming Week 7 Session Management & Authentication.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
Securing Angular Apps Brian Noyes
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
CSRF Attacks Daniel Chen 11/18/15. What is CSRF?  Cross Site Request Forgery (Sea-Surf)  AKA XSRF/ One Click / Sidejacking / Session Riding  Exploits.
Session Management Tyler Moore CS7403 University of Tulsa Slides adapted in part or whole from Dan Boneh, Stanford CS155 1.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
COOKIES AND SESSIONS.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
GENERAL SECURITY CONSIDERATIONS.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Lecture 19 Page 1 CS 236 Online 6. Application Software Security Why it’s important: –Security flaws in applications are increasingly the attacker’s entry.
Web Application Security
Javascript worms By Benjamin Mossé SecPro
Building Secure ColdFusion Applications
Web Application Vulnerabilities
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
TOPIC: Web Security (Part-4)
Security in Django.
API Security Auditing Be Aware,Be Safe
SQL Injection Attacks Many web servers have backing databases
What is REST API ? A REST (Representational State Transfer) Server simply provides access to resources and the REST client accesses and presents the.
ITM 352 Cookies.
PHP FORM HANDLING Post Method
What does “Security” encompass?
Cookies BIS1523 – Lecture 23.
Web Systems Development (CSC-215)
AJAX Robin Burke ECT 360.
PHP: Security issues FdSc Module 109 Server side scripting and
An Introduction to Web Application Security
Riding Someone Else’s Wave with CSRF
CSC 495/583 Topics of Software Security Intro to Web Security
Cross-Site Request Forgery (CSRF) Attack Lab
Building Web Applications
Web Security Advanced Network Security Peter Reiher August, 2014
HTTP GET vs POST SE-2840 Dr. Mark L. Hornick.
Cookies and sessions Saturday, February 23, 2019Saturday, February 23,
Cross Site Request Forgery New Attacks and Defenses
PHP Forms and Databases.
PHP-II.
Lecture 28 Security II April 7, 2017
6. Application Software Security
Cross-Site Scripting Attack (XSS)
Cross Site Request Forgery (CSRF)
Presentation transcript:

Cross-Site Forgery http://www.flickr.com/photos/torkildr/3462607995/

Some key web security concerns Logging of URLs Impersonation Autocomplete Man-in-the-middle Bots and denial-of-service Theft of data Encrypting data yourself Hashing passwords Injection attacks (last lecture) Cross-site forgery (current lecture) Covered in earlier lecture

Cross-site request forgery attack Cross-site request forgery (CSRF): Trick user's browser into trashing your site Very complex but important attack Very hard to defend against I'd guess that nearly every site on the web is susceptible to this attack, at some level

How CSRF works Browser Some other server Your server User submits login form to your server Server sends back session cookie; browser is now logged in User decides to visit another site The other server sends back HTML or JS… That causes the user's browser to send bad commands to your server

Key points User has to already be logged into your site For example, as a site administrator who is allowed by your site to insert/delete DB data User has to access another site The other site has to have a way of telling the browser to send commands to your site

"Send commands to your site"? Sure, the other server just has to send back… <form id="badform" method="post" action="http://yourserver.com/dbdelete.php"> <input type="text" name="id" value="100"> </form> <script>$("#badform").get(0).submit();</script>

What happens then… The browser reads the FORM and SCRIPT It executes the JS, automatically submitting the form The browser posts the data to your web page Your PHP probably checks that the user is logged in Yup… the session cookie took care of that And then your PHP acts on the command In this case, to delete some data

Even worse: Making the attack invisible Instead of outputting the form and JS directly, instead output a 1 pixel x 1 pixel IFRAME And then output the form and the JS inside the IFRAME The user will never notice

Even worse: Damaging lots of data Instead of outputting just one IFRAME, output a bunch of IFRAMES, each containing a form Then autosubmit all of the IFRAMES one after another… trash the entire database Major integrity fail (In fact, the FORM and IFRAME tags even have attributes that would make it possible to do this by reusing one IFRAME)

Even worse: Combine with XSS Instead of outputting a FORM that submits a relatively harmless data-deletion command, instead tell the browser to send evil data E.g., SCRIPT tag as shown in the previous lecture And if your site doesn't protect against cross-site scripting (again, see previous lecture), then other users can be attacked

Preventing CSRF is a huge pain Reduces but does not eliminate the risk: Use very short sessions Always check the referer header Options for eliminating the risk: Require a custom http header Create a special token that must be present

Option #1: Use very short sessions There is a tradeoff: You can use long sessions: Increased usability Users don't get logged of automatically if they step away for coffee You can use short sessions: Increased security Session cookies time out fast, so they have to be stolen fast if they are going to be of any use Therefore, the users are only susceptible to CSRF for a short amount of time

Option #2: Always check the referer Most (not all) versions of most browsers send an http header that tells what page the user is looking at when an http request is initiated HTTP_REFERER is like "Content-Type"… it is just another header sent by the browser to the server

Option #2: Always check the referer So when the form is posted back to your site $referer = $_SERVER['HTTP_REFERER']; if ($referer !== the CORRECT value for your site) refuse to do anything Referer should be a page on your site, NOT a page on somebody else's site

Option #2: Always check the referer Why this theoretically should work… Operations initiated by your page will have a REFERER header that matches your site Operations initiated by some other server's pages will have a REFERER header that matches their site Not a very good defense against CSRF, sadly Browsers can be configured in insecure ways that make this method unreliable

Option #3: Require a custom http header You can send a custom header of your own! In your JS: $.ajax({url:"http://myserver.com/dbpage.php", data:{a:1,b:2,c:3,etc:5},success:fnSuccess, beforeSend: function(request) { request.setRequestHeader("MYHEADER", "itslegit"); }}); In your PHP: if ($_SERVER["HTTP_MYHEADER"] != "itslegit") refuse to do anything

Option #3: Require a custom http header Why this works… Operations initiated by your page will have that special header present Operations initiated by some other server's pages will not have that special header present This approach apparently works quite reliably… but ALL your non-idempotent operations need to be done via AJAX.

Option #4: Create a special token that must be present When you output a form, generate a random number and put a copy in the session <?php $_SESSION["x"] = rand(1,1000) ?> <form …>… <input type="hidden" name="x" value="<?= $_SESSION["x"]?>">… </form> And when the form is posted, check that the right value is sent back if ($_REQUEST["x"] !== $_SESSION["x"]) refuse to do anything

Option #4: Create a special token that must be present Why this works… Operations initiated by your site will have that special token Operations initiated by some other server's pages will not have that special token (It's random, so it's hard to guess) This approach also works reliably, but ALL your non-idempotent operations need to be protected like this.

Summary Cross-site request forgery (CSRF) is dangerous Can trick users' browsers into trashing your data Can be combined with cross-site scripting Two solutions are not totally reliable Short sessions Checking the referer header Two solutions are a pain to implement Perform all non-idempotent operations with AJAX, set and set custom header Perform all non-idempotent operations with a form containing a secret random token that you check