SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Gergely Revay
http://gerionsecurity.com
@geri_revay
Security implications of the Cross-Origin
Resource Sharing
Disclaimer
This presentation is purely my opinion and not at all
related to SIEMENS.
https://c1.staticflickr.com/1/21/27423135_082e7b5983.jpg
The Game
Agenda
●
What is CORS ?
●
Pre-CORS solutions
●
Attacker model
●
What's the problem?
●
Attack Scenarios
●
Solution
●
Demo
●
Cross-Origin Resource Sharing
●
HTML5 feature
●
XmlHTTPRequest
●
Load content from another domain on the
client-side
What is CORS
What is CORS
Same-Origin Policy
Pre-CORS
●
Many different hacks
●
Proxy in same-origin
●
JSON-P
<script type="application/javascript"
src="http://server2.example.com/Users/1234?
jsonp=parseResponse">
</script>
HTML code:
parseResponse({"Name": "Foo", "Id": 1234, "Rank": 7});
Response Content:
How CORS works?
●
2 different request types:
– Simple request
– Not simple request
●
Browser makes the decision
The trick – simple request
Simple Request:Simple Request:
●
HEAD,GET or POST
●
Headers:
– Accept
– Accept-Language
– Content-Language
– Last-Event-ID
– Content-Type, but only if the value is
one of:
●
application/x-www-form-urlencoded
●
multipart/form-data
●
text/plain
The trick – NOT simple req
Preflight example
OPTIONS /cors HTTP/1.1
Origin: http://api.bob.com
Access-Control-Request-Method: PUT
Access-Control-Request-Headers: X-Custom-Header
Host: api.alice.com
Accept-Language: en-US
Connection: keep-alive
User-Agent: Mozilla/5.0
Access-Control-Allow-Origin: http://api.bob.com
Access-Control-Allow-Methods: GET, POST, PUT
Access-Control-Allow-Headers: X-Custom-Header
Content-Type: text/html; charset=utf-8
Preflight request:
Preflight response:
Attacker Model
c
Attacker Model
c
Attacker Model: Knowledge
Does he have internal knowledge ?
Internal External
Attacker Model: Goal
●
Get access to the internal network
●
Attack internal services
●
Steal data from the user.
Attacker Model: Location
Local Remote
What is the problem?
Attack scenarios
CORS is just a tool, not a vulnerability.
Attack scenarios: CSRF recap
c
Attack Scenarios
●
Multistage CSRF
●
Cross-domain data theft
●
Complex JavaScript attack scenarios
●
Pivoting (BeEF)
●
Network Enumeration
●
File upload CSRF
Example: File upload CSRF
-----------------------------256672629917035
Content-Disposition: form-data; name="file"; filename="test2.txt"
Content-Type: text/plain
test3
-----------------------------256672629917035
<html>
<body>
<script>
function submitRequest()
{
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://example.com/new_file.html", true);
xhr.setRequestHeader("Accept", "text/html,application/xhtml+xml;q=0.9,*/*;q=0.8");
xhr.setRequestHeader("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3");
xhr.setRequestHeader("Content-Type", "multipart/form-data;
boundary=---------------------------256672629917035");
xhr.withCredentials = "true";
var body = "-----------------------------256672629917035rn" +
"Content-Disposition: form-data; name="file"; filename="test2.txt"rn" +
"Content-Type: text/plainrn" +
"rn" +
"test3rn" +
"-----------------------------256672629917035--rn";
var aBody = new Uint8Array(body.length);
for (var i = 0; i < aBody.length; i++)
aBody[i] = body.charCodeAt(i);
xhr.send(new Blob([aBody]));
}
</script>
<form action="#">
<input type="submit" value="Submit request" onclick="submitRequest();" />
</form>
</body>
</html>
Limitations
Pretty strong limitations
Limitations: Write only requests
XmlHttpResponse is not readable if:
●
No Access-Control-Allow-Origins header
●
Source origin is not allowed in A-C-Allow-
Origins
●
WithCredentials is true but A-C-A-O=*
Bear in mind: the requests are still sent!
Limitations: Preflight Req Fails
If one of the requirements of the pre-flight
request is not satisfied, the original request will
not be sent.
OPTIONS /cors HTTP/1.1
Origin: http://api.bob.com
Access-Control-Request-Method: PUT
Access-Control-Request-Headers: X-Custom-Header
Host: api.alice.com
Accept-Language: en-US
Connection: keep-alive
User-Agent: Mozilla/5.0
Solution
●
More awareness on the basics of CORS
●
Strict Allow-Origin settings
●
Rejecting Allow-Credential requests
●
Change of mindset: development problem
Hardening
Can and need to be done on various levels:
●
Webserver
●
Application
Hardening: Apache HTTPD
●
mod_headers
●
In config or .htaccess
●
<Directory>, <Location>, <Files> or
<VirtualHost>
Header set Access-Control-Allow-Origin “example.com”
Hardening: Application
Application logic should consider CORS and
set the appropriate headers.
i.e.: ASP .NET:
Response.AppendHeader(
"Access-Control-Allow-Origin",
"example.com");
DEMO
No animals were harmed in the making of these
demos.
Q & A
Thank you!
Gergely Revay
http://gerionsecurity.com
@geri_revay
Resources:
● http://www.w3.org/TR/cors/
● http://www.html5rocks.com/en/tutorials/cors/
● https://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity
● https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS

Weitere ähnliche Inhalte

Was ist angesagt?

Webinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControlWebinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControl
Severalnines
 
MongoDB Shell Tips & Tricks
MongoDB Shell Tips & TricksMongoDB Shell Tips & Tricks
MongoDB Shell Tips & Tricks
MongoDB
 

Was ist angesagt? (20)

Brief introduction to php findsock-shell
Brief introduction to php findsock-shellBrief introduction to php findsock-shell
Brief introduction to php findsock-shell
 
Django and Nginx reverse proxy cache
Django and Nginx reverse proxy cacheDjango and Nginx reverse proxy cache
Django and Nginx reverse proxy cache
 
Mongodb
MongodbMongodb
Mongodb
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
 
Node js crash course session 2
Node js crash course   session 2Node js crash course   session 2
Node js crash course session 2
 
Webinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControlWebinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControl
 
Node js crash course session 3
Node js crash course   session 3Node js crash course   session 3
Node js crash course session 3
 
High Performance Python Microservice Communication
High Performance Python Microservice CommunicationHigh Performance Python Microservice Communication
High Performance Python Microservice Communication
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB Shell Tips & Tricks
MongoDB Shell Tips & TricksMongoDB Shell Tips & Tricks
MongoDB Shell Tips & Tricks
 
Redis
RedisRedis
Redis
 
Mastering the MongoDB Shell
Mastering the MongoDB ShellMastering the MongoDB Shell
Mastering the MongoDB Shell
 
AJAX
AJAXAJAX
AJAX
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
 
NoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDBNoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDB
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Ajax xml json
Ajax xml jsonAjax xml json
Ajax xml json
 
Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo db
 
JSONSchema with golang
JSONSchema with golangJSONSchema with golang
JSONSchema with golang
 

Andere mochten auch

CONFidence 2014: Arkadiusz Bolibok,Paweł Goleń: Evaluation of Transactional C...
CONFidence 2014: Arkadiusz Bolibok,Paweł Goleń: Evaluation of Transactional C...CONFidence 2014: Arkadiusz Bolibok,Paweł Goleń: Evaluation of Transactional C...
CONFidence 2014: Arkadiusz Bolibok,Paweł Goleń: Evaluation of Transactional C...
PROIDEA
 
CONFidence 2014:
CONFidence 2014: CONFidence 2014:
CONFidence 2014:
PROIDEA
 
Shiny
ShinyShiny
Shiny
egypt
 
State of the Framework Address: Recent Developments in the Metasploit Framework
State of the Framework Address: Recent Developments in the Metasploit FrameworkState of the Framework Address: Recent Developments in the Metasploit Framework
State of the Framework Address: Recent Developments in the Metasploit Framework
egypt
 
OSINT RF Reverse Engineering by Marc Newlin
OSINT RF Reverse Engineering by Marc NewlinOSINT RF Reverse Engineering by Marc Newlin
OSINT RF Reverse Engineering by Marc Newlin
EC-Council
 

Andere mochten auch (17)

CONFidence 2014: Alexander Timorin: SCADA deep inside: protocols and security...
CONFidence 2014: Alexander Timorin: SCADA deep inside: protocols and security...CONFidence 2014: Alexander Timorin: SCADA deep inside: protocols and security...
CONFidence 2014: Alexander Timorin: SCADA deep inside: protocols and security...
 
Malicious Topologies of IPv4
Malicious Topologies of IPv4Malicious Topologies of IPv4
Malicious Topologies of IPv4
 
CONFidence 2014: Arkadiusz Bolibok,Paweł Goleń: Evaluation of Transactional C...
CONFidence 2014: Arkadiusz Bolibok,Paweł Goleń: Evaluation of Transactional C...CONFidence 2014: Arkadiusz Bolibok,Paweł Goleń: Evaluation of Transactional C...
CONFidence 2014: Arkadiusz Bolibok,Paweł Goleń: Evaluation of Transactional C...
 
CONFidence 2014:
CONFidence 2014: CONFidence 2014:
CONFidence 2014:
 
Shiny
ShinyShiny
Shiny
 
Post Metasploitation
Post MetasploitationPost Metasploitation
Post Metasploitation
 
Break IT Down by Josh Smith
Break IT Down by Josh SmithBreak IT Down by Josh Smith
Break IT Down by Josh Smith
 
Hunting Layered Malware by Raul Alvarez
Hunting Layered Malware by Raul AlvarezHunting Layered Malware by Raul Alvarez
Hunting Layered Malware by Raul Alvarez
 
NTXISSACSC3 - Metasploit Year in Review by James Lee
NTXISSACSC3 - Metasploit Year in Review  by James LeeNTXISSACSC3 - Metasploit Year in Review  by James Lee
NTXISSACSC3 - Metasploit Year in Review by James Lee
 
Hacking Web Apps by Brent White
Hacking Web Apps by Brent WhiteHacking Web Apps by Brent White
Hacking Web Apps by Brent White
 
State of the Framework Address: Recent Developments in the Metasploit Framework
State of the Framework Address: Recent Developments in the Metasploit FrameworkState of the Framework Address: Recent Developments in the Metasploit Framework
State of the Framework Address: Recent Developments in the Metasploit Framework
 
already-0wned
already-0wnedalready-0wned
already-0wned
 
Security by Weston Hecker
Security by Weston HeckerSecurity by Weston Hecker
Security by Weston Hecker
 
Metasploit
MetasploitMetasploit
Metasploit
 
OSINT RF Reverse Engineering by Marc Newlin
OSINT RF Reverse Engineering by Marc NewlinOSINT RF Reverse Engineering by Marc Newlin
OSINT RF Reverse Engineering by Marc Newlin
 
Defending Against 1,000,000 Cyber Attacks by Michael Banks
Defending Against 1,000,000 Cyber Attacks by Michael BanksDefending Against 1,000,000 Cyber Attacks by Michael Banks
Defending Against 1,000,000 Cyber Attacks by Michael Banks
 
Pentest with Metasploit
Pentest with MetasploitPentest with Metasploit
Pentest with Metasploit
 

Ähnlich wie CONFidence 2014: Kiss, Zagon, Sseller: Scaling security

Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
Zoran Jeremic
 
02 banking trojans-thomassiebert
02 banking trojans-thomassiebert02 banking trojans-thomassiebert
02 banking trojans-thomassiebert
geeksec80
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
Cosmin Mereuta
 

Ähnlich wie CONFidence 2014: Kiss, Zagon, Sseller: Scaling security (20)

WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...
WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...
WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...
 
Android and REST
Android and RESTAndroid and REST
Android and REST
 
W3 conf hill-html5-security-realities
W3 conf hill-html5-security-realitiesW3 conf hill-html5-security-realities
W3 conf hill-html5-security-realities
 
Consuming RESTful Web services in PHP
Consuming RESTful Web services in PHPConsuming RESTful Web services in PHP
Consuming RESTful Web services in PHP
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js Applications
 
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
 
Building Client-Side Attacks with HTML5 Features
Building Client-Side Attacks with HTML5 FeaturesBuilding Client-Side Attacks with HTML5 Features
Building Client-Side Attacks with HTML5 Features
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
 
02 banking trojans-thomassiebert
02 banking trojans-thomassiebert02 banking trojans-thomassiebert
02 banking trojans-thomassiebert
 
Synapseindia dot net development web applications with ajax
Synapseindia dot net development  web applications with ajaxSynapseindia dot net development  web applications with ajax
Synapseindia dot net development web applications with ajax
 
Browser security
Browser securityBrowser security
Browser security
 
AJAX Transport Layer
AJAX Transport LayerAJAX Transport Layer
AJAX Transport Layer
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Client side
Client sideClient side
Client side
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
 
PSR-7 and PSR-15, why can't you ignore them
PSR-7 and PSR-15, why can't you ignore themPSR-7 and PSR-15, why can't you ignore them
PSR-7 and PSR-15, why can't you ignore them
 
Rapid API development examples for Impress Application Server / Node.js (jsfw...
Rapid API development examples for Impress Application Server / Node.js (jsfw...Rapid API development examples for Impress Application Server / Node.js (jsfw...
Rapid API development examples for Impress Application Server / Node.js (jsfw...
 
Security in Node.JS and Express:
Security in Node.JS and Express:Security in Node.JS and Express:
Security in Node.JS and Express:
 
New web attacks-nethemba
New web attacks-nethembaNew web attacks-nethemba
New web attacks-nethemba
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

CONFidence 2014: Kiss, Zagon, Sseller: Scaling security

  • 2. Disclaimer This presentation is purely my opinion and not at all related to SIEMENS. https://c1.staticflickr.com/1/21/27423135_082e7b5983.jpg
  • 4. Agenda ● What is CORS ? ● Pre-CORS solutions ● Attacker model ● What's the problem? ● Attack Scenarios ● Solution ● Demo
  • 5. ● Cross-Origin Resource Sharing ● HTML5 feature ● XmlHTTPRequest ● Load content from another domain on the client-side What is CORS
  • 7. Pre-CORS ● Many different hacks ● Proxy in same-origin ● JSON-P <script type="application/javascript" src="http://server2.example.com/Users/1234? jsonp=parseResponse"> </script> HTML code: parseResponse({"Name": "Foo", "Id": 1234, "Rank": 7}); Response Content:
  • 8. How CORS works? ● 2 different request types: – Simple request – Not simple request ● Browser makes the decision
  • 9. The trick – simple request Simple Request:Simple Request: ● HEAD,GET or POST ● Headers: – Accept – Accept-Language – Content-Language – Last-Event-ID – Content-Type, but only if the value is one of: ● application/x-www-form-urlencoded ● multipart/form-data ● text/plain
  • 10. The trick – NOT simple req
  • 11. Preflight example OPTIONS /cors HTTP/1.1 Origin: http://api.bob.com Access-Control-Request-Method: PUT Access-Control-Request-Headers: X-Custom-Header Host: api.alice.com Accept-Language: en-US Connection: keep-alive User-Agent: Mozilla/5.0 Access-Control-Allow-Origin: http://api.bob.com Access-Control-Allow-Methods: GET, POST, PUT Access-Control-Allow-Headers: X-Custom-Header Content-Type: text/html; charset=utf-8 Preflight request: Preflight response:
  • 14. Attacker Model: Knowledge Does he have internal knowledge ? Internal External
  • 15. Attacker Model: Goal ● Get access to the internal network ● Attack internal services ● Steal data from the user.
  • 17. What is the problem?
  • 18. Attack scenarios CORS is just a tool, not a vulnerability.
  • 20. Attack Scenarios ● Multistage CSRF ● Cross-domain data theft ● Complex JavaScript attack scenarios ● Pivoting (BeEF) ● Network Enumeration ● File upload CSRF
  • 21. Example: File upload CSRF -----------------------------256672629917035 Content-Disposition: form-data; name="file"; filename="test2.txt" Content-Type: text/plain test3 -----------------------------256672629917035
  • 22. <html> <body> <script> function submitRequest() { var xhr = new XMLHttpRequest(); xhr.open("POST", "https://example.com/new_file.html", true); xhr.setRequestHeader("Accept", "text/html,application/xhtml+xml;q=0.9,*/*;q=0.8"); xhr.setRequestHeader("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"); xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=---------------------------256672629917035"); xhr.withCredentials = "true"; var body = "-----------------------------256672629917035rn" + "Content-Disposition: form-data; name="file"; filename="test2.txt"rn" + "Content-Type: text/plainrn" + "rn" + "test3rn" + "-----------------------------256672629917035--rn"; var aBody = new Uint8Array(body.length); for (var i = 0; i < aBody.length; i++) aBody[i] = body.charCodeAt(i); xhr.send(new Blob([aBody])); } </script> <form action="#"> <input type="submit" value="Submit request" onclick="submitRequest();" /> </form> </body> </html>
  • 24. Limitations: Write only requests XmlHttpResponse is not readable if: ● No Access-Control-Allow-Origins header ● Source origin is not allowed in A-C-Allow- Origins ● WithCredentials is true but A-C-A-O=* Bear in mind: the requests are still sent!
  • 25. Limitations: Preflight Req Fails If one of the requirements of the pre-flight request is not satisfied, the original request will not be sent. OPTIONS /cors HTTP/1.1 Origin: http://api.bob.com Access-Control-Request-Method: PUT Access-Control-Request-Headers: X-Custom-Header Host: api.alice.com Accept-Language: en-US Connection: keep-alive User-Agent: Mozilla/5.0
  • 26. Solution ● More awareness on the basics of CORS ● Strict Allow-Origin settings ● Rejecting Allow-Credential requests ● Change of mindset: development problem
  • 27. Hardening Can and need to be done on various levels: ● Webserver ● Application
  • 28. Hardening: Apache HTTPD ● mod_headers ● In config or .htaccess ● <Directory>, <Location>, <Files> or <VirtualHost> Header set Access-Control-Allow-Origin “example.com”
  • 29. Hardening: Application Application logic should consider CORS and set the appropriate headers. i.e.: ASP .NET: Response.AppendHeader( "Access-Control-Allow-Origin", "example.com");
  • 30. DEMO No animals were harmed in the making of these demos.
  • 31. Q & A Thank you! Gergely Revay http://gerionsecurity.com @geri_revay Resources: ● http://www.w3.org/TR/cors/ ● http://www.html5rocks.com/en/tutorials/cors/ ● https://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity ● https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS