SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
Isolating content between domains since 1996
Riyaz Walikar | @riyazwalikar | www.riyazwalikar.com
whoami
• WebAppSec Consultant, Penetration Tester, Bug Bounty
Hunter for Google, Facebook, Paypal, Mozilla and other
bounty programs
• One of the null Security Community Bangalore Chapter
Moderator
• Work at a Big4 and have conducted several Penetration Tests
all over the world.
• Spoken at several international security conferences
Imagine the Internet if
• fabekook.cn was able to read DOM values from facebook.com
from another browser tab
• gmaail.br was able to read your address book from
http://mail.google.com/mail/c/data/contactstore?type=4&ma
x=-1
• boinkofindia.com was able to read your account balance and
obtain a list of all your transactions from your internet
banking account while you are logged in.
Why is this possible?
Uh oh!
What is SOP?
• SOP restricts how a document or script loaded
from one origin can interact with a resource
from another origin
• Earliest available implementation – Netscape
Navigator 2.0 (1996)
define: origin
URL Outcome Reason
http://store.company.com/dir2/other.html Success ----
http://store.company.com/dir/inner/another.html Success ----
https://store.company.com/secure.html Failure Different protocol
http://store.company.com:81/dir/etc.html Failure Different port
http://news.company.com/dir/other.html Failure Different host
Access made from: http://store.company.com/dir/page.html
Changing 'origins'
• Setting document.domain to a suffix of the
current domain.
• Setting document.domain to another domain
altogether isn’t allowed.
Demo
A document.domain change set
Cross Origin Network Access
• Origin is permitted to send data to another
origin but not read
• Interactions between origins are placed in three
categories:
– Cross origin writes (redirects, links, form action etc.)
– Cross origin embedding (html tag with src/hrefs)
– Cross origin reads (not allowed without CORS etc.)
Cross Origin Embedding
• JavaScript <script src="..."></script>.
• CSS with <link rel="stylesheet" href="...">.
• Images with <img>.
• Media files with <video> and <audio> tags.
• Plug-ins with <object>, <embed> and <applet>.
• Fonts with @font-face.
• Anything with <frame> and <iframe>.
Prevent Cross Origin Access
• To prevent Cross origin writes, use a CSRF token
• To prevent Cross origin embedding, ensure
resource is not interpreted as any of the formats
discussed earlier.
• To prevent Cross Origin reads of a resource, ensure
that it is non-embeddable.
• For iframes the X-Frame-Options header can be
used to control access to the page.
Cross Origin Resource Sharing
• W3C specification that allows cross domain
communication from the browser
• Works by adding new HTTP headers that
describe the set of origins that are permitted to
read across domains
3 Pointers
• Browsers prevent data from being accessed
cross domain via the Same Origin Policy
• In case a page loads another domain via a
frame, X-Frame-Options can be used to control
access
• CORS is used to relax the Same Origin Policy for
legitimate and trusted requests.
References
• https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript
• http://www.w3.org/Security/wiki/Same_Origin_Policy
• http://code.google.com/p/browsersec/wiki/Part2
Allowing Cross origin resource sharing since March 2004
Riyaz Walikar | @riyazwalikar | www.riyazwalikar.com
What is CORS?
• W3C working draft that defines how the browser
and server must communicate when accessing
sources across origins
• Implemented via HTTP headers that servers set
and browsers enforce
• Can be categorized into
– Simple requests
– Requests that need a ‘preflight’
Demo
A simple cross origin request without CORS
CORS standard exchange between client and server
Why is CORS needed?
• For legitimate and trusted requests to gain access
to authorized data from other domains
• Think cross application data sharing models
• Allows data to be exchanged with trusted sites
while using a relaxed Same Origin policy mode.
• Application APIs exposed via web services and
trusted domains require CORS to be accessible
over the SOP
APIs that support CORS!
CORS – Simple Requests
• Preflight is not needed if
– Request is a HEAD/GET/POST via XHR
– No Custom headers
– Body is text/plain
• Server responds with a CORS header
– Browser determines access
– Neither the request, nor response contain cookies
CORS Headers – Simple Request
• Origin
– Header set by the client for every CORS request
– Value is the current domain that made the request
• Access-Control-Allow-Origin
– Set by the server and used by the browser to
determine if the response is to be allowed or not.
– Can be set to * to make resources public (bad
practice!)
Demo
A cross origin request with CORS for a simple request
CORS – Requests with Preflight
• Preflight requests are made if
– Request is a method other than HEAD/GET/POST
via XHR (PUT, DELETE etc.)
– Custom headers are present (X-PINGBACK etc.)
– Content-Type other than application/x-www-
form-urlencoded, multipart/form-data, or
text/plain
• A transparent request is made to the server
requesting access information using OPTIONS
CORS – Requests with Preflight
• Browser sends
– Origin header
– Access-Control-Request-Method
– Access-Control-Request-Headers – (Optional)
• Server sends set of CORS headers that the
browser uses to determine if the actual
request has to be made or not
CORS Headers – Request with Preflight
(Preflight Browser Request)
• Origin
– Header set by the client for every CORS request
– Value is the current domain that made the request
• Access-Control-Request-Method:
– Set by the browser, along with Origin.
– Value is the method that the request wants to use
• Access-Control-Request-Headers (Optional):
– A comma separated list of the custom headers being
used.
CORS Headers – Request with Preflight
(Preflight Server Response)
• Access-Control-Allow-Origin
– Same as in Simple requests
• Access-Control-Allow-Methods:
– a comma separated list of allowed methods
• Access-Control-Allow-Headers:
– a comma separated list of headers that the server will
allow.
• Access-Control-Max-Age:
– the amount of time in seconds that this preflight
request should be cached for.
Demo
A cross origin request with CORS for a preflight request
CORS (In)security?
• Several security issues arise from the improper
implementation of CORS, most commonly using a
universal allow notation (*) in the server headers
• Clients should not trust the received content
completely and eval or render content without
sanitization which could result in misplaced trust
• The application that allows CORS may become
vulnerable to CSRF attacks
CORS (In)security?
• Prolonged caching of Preflight responses could
lead to attacks arising out of abuse of the
Preflight Client Cache
• Access control decisions based on the Origin
header could result in vulnerabilities as this
can be spoofed by an attacker
CORS Security - Universal Allow
• Setting the 'Access-Control-Allow-Origin' header to *
• Effectively turns the content into a public resource,
allowing access from any domain
• Scenarios?
– An attacker can steal data from an intranet site that has set
this header to * by enticing a user to visit an attacker
controlled site on the Internet.
– An attacker can perform attacks on other remote apps via
a victim’s browser when the victim navigates to an attacker
controlled site.
Demo
A universal allow for the Access-Control-Allow-Origin header
CORS Security – Misplaced Trust
• Data exchange between two domains is based on trust
• If one of the servers involved in the exchange of data is
compromised then the model of CORS is put at risk
• Scenarios?
– An attacker can compromise site A and host malicious
content knowing site B trusts the data that site A sends to
site B via CORS request resulting in XSS and other attacks.
– An attacker can compromise site B and use the exposed
CORS functionality in site A to attack users in site A.
CSRF with CORS
• Server may process client request to change server side
data while verifying that the Origin header was set
• An attacker can use the .withCredentials = “true” property
of XHR to replay any cookies to the application on which
the victim is logged in
• Scenarios?
– An attacker sets the Origin header or uses a trusted site A to
send a non idempotent request to site B
– The victim who is logged into site B when he is viewing the
trusted site A causes site B to create a user account without
his knowledge via a CSRF attack
Demo
A CSRF attack that creates a user using a trusted site via CORS
CORS – Caching of Preflight responses
• The Access-Control-Max-Age header is set to a high
value, allowing browsers to cache Preflight
responses
• Caching the preflight response for longer duration
can pose a security risk.
• If the COR access-control policy is changed on the
server the browser would still follow the old policy
available in the Preflight Result Cache
CORS – Access Control based on Origin
• The Origin header indicates that the request is from
a particular domain, but does not guarantee it
• Spoofing the Origin header allows access to the page
if access is based on this header
• Scenarios?
– An attacker sets the Origin header to view sensitive
information that is restricted
– Attacker uses cURL to set a custom origin header:
curl --header 'origin:http://someserver.com'
http://myserver.com:90/demo/origin_spoof.php
Demo
Sensitive information revealed via weak Access Control based on
the Origin header
References
• http://www.html5rocks.com/en/tutorials/cors/
• https://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity
• http://arunranga.com/examples/access-control/
• http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-
resource-sharing/
Questions?
And hopefully answers as well
Riyaz Walikar | @riyazwalikar | karniv0re@null.co.in

Weitere ähnliche Inhalte

Was ist angesagt?

What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.Mikhail Egorov
 
HTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeHTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeAbhishek L.R
 
Waf bypassing Techniques
Waf bypassing TechniquesWaf bypassing Techniques
Waf bypassing TechniquesAvinash Thapa
 
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 EditionGoing Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 EditionSoroush Dalili
 
Attacking thru HTTP Host header
Attacking thru HTTP Host headerAttacking thru HTTP Host header
Attacking thru HTTP Host headerSergey Belov
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessionsSukrit Gupta
 
SSRF For Bug Bounties
SSRF For Bug BountiesSSRF For Bug Bounties
SSRF For Bug BountiesOWASP Nagpur
 
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
XXE Exposed: SQLi, XSS, XXE and XEE against Web ServicesXXE Exposed: SQLi, XSS, XXE and XEE against Web Services
XXE Exposed: SQLi, XSS, XXE and XEE against Web ServicesAbraham Aranguren
 
Web authentication & authorization
Web authentication & authorizationWeb authentication & authorization
Web authentication & authorizationAlexandru Pasaila
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web APIBrad Genereaux
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUDPrem Sanil
 
Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014Navaneethan Naveen
 

Was ist angesagt? (20)

Same origin policy
Same origin policySame origin policy
Same origin policy
 
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
 
Web fundamentals - part 1
Web fundamentals - part 1Web fundamentals - part 1
Web fundamentals - part 1
 
HTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeHTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status Code
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Waf bypassing Techniques
Waf bypassing TechniquesWaf bypassing Techniques
Waf bypassing Techniques
 
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 EditionGoing Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
 
Http security response headers
Http security response headers Http security response headers
Http security response headers
 
Attacking thru HTTP Host header
Attacking thru HTTP Host headerAttacking thru HTTP Host header
Attacking thru HTTP Host header
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Http-protocol
Http-protocolHttp-protocol
Http-protocol
 
SSRF For Bug Bounties
SSRF For Bug BountiesSSRF For Bug Bounties
SSRF For Bug Bounties
 
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
XXE Exposed: SQLi, XSS, XXE and XEE against Web ServicesXXE Exposed: SQLi, XSS, XXE and XEE against Web Services
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
 
Web authentication & authorization
Web authentication & authorizationWeb authentication & authorization
Web authentication & authorization
 
Secure Session Management
Secure Session ManagementSecure Session Management
Secure Session Management
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014
 
Api security-testing
Api security-testingApi security-testing
Api security-testing
 
SSRF workshop
SSRF workshop SSRF workshop
SSRF workshop
 

Andere mochten auch

Cross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORSCross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORSMichael Neale
 
Breaking The Cross Domain Barrier
Breaking The Cross Domain BarrierBreaking The Cross Domain Barrier
Breaking The Cross Domain BarrierAlex Sexton
 
Cookie testing
Cookie testingCookie testing
Cookie testingBugRaptors
 
Deploying JHipster Microservices
Deploying JHipster MicroservicesDeploying JHipster Microservices
Deploying JHipster MicroservicesJoe Kutner
 
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015Alvaro Sanchez-Mariscal
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016Matt Raible
 
REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!Stormpath
 
Api gateway : To be or not to be
Api gateway : To be or not to beApi gateway : To be or not to be
Api gateway : To be or not to beJaewoo Ahn
 
JHipster for Spring Boot webinar
JHipster for Spring Boot webinarJHipster for Spring Boot webinar
JHipster for Spring Boot webinarJulien Dubois
 
AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application Carlo Bonamico
 
Single-Page-Application & REST security
Single-Page-Application & REST securitySingle-Page-Application & REST security
Single-Page-Application & REST securityIgor Bossenko
 
Web Security - Cookies, Domains and CORS
Web Security - Cookies, Domains and CORSWeb Security - Cookies, Domains and CORS
Web Security - Cookies, Domains and CORSPerfectial, LLC
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkVolker Hirsch
 

Andere mochten auch (17)

Cross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORSCross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORS
 
Breaking The Cross Domain Barrier
Breaking The Cross Domain BarrierBreaking The Cross Domain Barrier
Breaking The Cross Domain Barrier
 
Jhipster
JhipsterJhipster
Jhipster
 
Cookie testing
Cookie testingCookie testing
Cookie testing
 
Deploying JHipster Microservices
Deploying JHipster MicroservicesDeploying JHipster Microservices
Deploying JHipster Microservices
 
Intro to JHipster
Intro to JHipster Intro to JHipster
Intro to JHipster
 
JHipster
JHipsterJHipster
JHipster
 
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
 
REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!
 
Api gateway : To be or not to be
Api gateway : To be or not to beApi gateway : To be or not to be
Api gateway : To be or not to be
 
JHipster overview
JHipster overviewJHipster overview
JHipster overview
 
JHipster for Spring Boot webinar
JHipster for Spring Boot webinarJHipster for Spring Boot webinar
JHipster for Spring Boot webinar
 
AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application
 
Single-Page-Application & REST security
Single-Page-Application & REST securitySingle-Page-Application & REST security
Single-Page-Application & REST security
 
Web Security - Cookies, Domains and CORS
Web Security - Cookies, Domains and CORSWeb Security - Cookies, Domains and CORS
Web Security - Cookies, Domains and CORS
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of Work
 

Ähnlich wie CORS and (in)security

What Is Cross-Origin Resource Sharing in Web Development.pdf
What Is Cross-Origin Resource Sharing in Web Development.pdfWhat Is Cross-Origin Resource Sharing in Web Development.pdf
What Is Cross-Origin Resource Sharing in Web Development.pdfMPrashanth13
 
Html cors- lior rotkovitch
Html cors- lior rotkovitchHtml cors- lior rotkovitch
Html cors- lior rotkovitchLior Rotkovitch
 
Lesson 6 web based attacks
Lesson 6 web based attacksLesson 6 web based attacks
Lesson 6 web based attacksFrank Victory
 
Hacking HTML5 offensive course (Zeronights edition)
Hacking HTML5 offensive course (Zeronights edition)Hacking HTML5 offensive course (Zeronights edition)
Hacking HTML5 offensive course (Zeronights edition)Krzysztof Kotowicz
 
Of CORS thats a thing how CORS in the cloud still kills security
Of CORS thats a thing how CORS in the cloud still kills securityOf CORS thats a thing how CORS in the cloud still kills security
Of CORS thats a thing how CORS in the cloud still kills securityJohn Varghese
 
Browsers_SameOriginPolicy_CORS_ContentSecurityPolicy
Browsers_SameOriginPolicy_CORS_ContentSecurityPolicyBrowsers_SameOriginPolicy_CORS_ContentSecurityPolicy
Browsers_SameOriginPolicy_CORS_ContentSecurityPolicysubbul
 
Krzysztof Kotowicz - Hacking HTML5
Krzysztof Kotowicz - Hacking HTML5Krzysztof Kotowicz - Hacking HTML5
Krzysztof Kotowicz - Hacking HTML5DefconRussia
 
Going Beyond Cross Domain Boundaries (jQuery Bulgaria)
Going Beyond Cross Domain Boundaries (jQuery Bulgaria)Going Beyond Cross Domain Boundaries (jQuery Bulgaria)
Going Beyond Cross Domain Boundaries (jQuery Bulgaria)Ivo Andreev
 
Chrome extensions threat analysis and countermeasures
Chrome extensions threat analysis and countermeasuresChrome extensions threat analysis and countermeasures
Chrome extensions threat analysis and countermeasuresRoel Palmaers
 
Web Hacking Series Part 5
Web Hacking Series Part 5Web Hacking Series Part 5
Web Hacking Series Part 5Aditya Kamat
 
Do you lose sleep at night?
Do you lose sleep at night?Do you lose sleep at night?
Do you lose sleep at night?Nathan Van Gheem
 
cross document messaging, html 5
cross document messaging, html 5cross document messaging, html 5
cross document messaging, html 5Kristoffer Snabb
 
Advanced Client Side Exploitation Using BeEF
Advanced Client Side Exploitation Using BeEFAdvanced Client Side Exploitation Using BeEF
Advanced Client Side Exploitation Using BeEF1N3
 
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...Divyanshu
 
CNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application TechnologiesCNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application TechnologiesSam Bowne
 
AWS Webcast - Best Practices for Content Delivery using Amazon CloudFront
AWS Webcast - Best Practices for Content Delivery using Amazon CloudFrontAWS Webcast - Best Practices for Content Delivery using Amazon CloudFront
AWS Webcast - Best Practices for Content Delivery using Amazon CloudFrontAmazon Web Services
 
Best practices for content delivery using amazon cloud front
Best practices for content delivery using amazon cloud frontBest practices for content delivery using amazon cloud front
Best practices for content delivery using amazon cloud frontAmazon Web Services
 

Ähnlich wie CORS and (in)security (20)

What Is Cross-Origin Resource Sharing in Web Development.pdf
What Is Cross-Origin Resource Sharing in Web Development.pdfWhat Is Cross-Origin Resource Sharing in Web Development.pdf
What Is Cross-Origin Resource Sharing in Web Development.pdf
 
Html cors- lior rotkovitch
Html cors- lior rotkovitchHtml cors- lior rotkovitch
Html cors- lior rotkovitch
 
Lesson 6 web based attacks
Lesson 6 web based attacksLesson 6 web based attacks
Lesson 6 web based attacks
 
Hacking HTML5 offensive course (Zeronights edition)
Hacking HTML5 offensive course (Zeronights edition)Hacking HTML5 offensive course (Zeronights edition)
Hacking HTML5 offensive course (Zeronights edition)
 
HTML5 - The Promise & The Peril
HTML5 - The Promise & The PerilHTML5 - The Promise & The Peril
HTML5 - The Promise & The Peril
 
Of CORS thats a thing how CORS in the cloud still kills security
Of CORS thats a thing how CORS in the cloud still kills securityOf CORS thats a thing how CORS in the cloud still kills security
Of CORS thats a thing how CORS in the cloud still kills security
 
Browsers_SameOriginPolicy_CORS_ContentSecurityPolicy
Browsers_SameOriginPolicy_CORS_ContentSecurityPolicyBrowsers_SameOriginPolicy_CORS_ContentSecurityPolicy
Browsers_SameOriginPolicy_CORS_ContentSecurityPolicy
 
Krzysztof Kotowicz - Hacking HTML5
Krzysztof Kotowicz - Hacking HTML5Krzysztof Kotowicz - Hacking HTML5
Krzysztof Kotowicz - Hacking HTML5
 
Going Beyond Cross Domain Boundaries (jQuery Bulgaria)
Going Beyond Cross Domain Boundaries (jQuery Bulgaria)Going Beyond Cross Domain Boundaries (jQuery Bulgaria)
Going Beyond Cross Domain Boundaries (jQuery Bulgaria)
 
Chrome extensions threat analysis and countermeasures
Chrome extensions threat analysis and countermeasuresChrome extensions threat analysis and countermeasures
Chrome extensions threat analysis and countermeasures
 
Web Hacking Series Part 5
Web Hacking Series Part 5Web Hacking Series Part 5
Web Hacking Series Part 5
 
Do you lose sleep at night?
Do you lose sleep at night?Do you lose sleep at night?
Do you lose sleep at night?
 
cross document messaging, html 5
cross document messaging, html 5cross document messaging, html 5
cross document messaging, html 5
 
Advanced Client Side Exploitation Using BeEF
Advanced Client Side Exploitation Using BeEFAdvanced Client Side Exploitation Using BeEF
Advanced Client Side Exploitation Using BeEF
 
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
 
CNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application TechnologiesCNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application Technologies
 
AWS Webcast - Best Practices for Content Delivery using Amazon CloudFront
AWS Webcast - Best Practices for Content Delivery using Amazon CloudFrontAWS Webcast - Best Practices for Content Delivery using Amazon CloudFront
AWS Webcast - Best Practices for Content Delivery using Amazon CloudFront
 
Best practices for content delivery using amazon cloud front
Best practices for content delivery using amazon cloud frontBest practices for content delivery using amazon cloud front
Best practices for content delivery using amazon cloud front
 
Codefest2015
Codefest2015Codefest2015
Codefest2015
 
Flashack
FlashackFlashack
Flashack
 

Mehr von n|u - The Open Security Community

Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...n|u - The Open Security Community
 

Mehr von n|u - The Open Security Community (20)

Hardware security testing 101 (Null - Delhi Chapter)
Hardware security testing 101 (Null - Delhi Chapter)Hardware security testing 101 (Null - Delhi Chapter)
Hardware security testing 101 (Null - Delhi Chapter)
 
Osint primer
Osint primerOsint primer
Osint primer
 
SSRF exploit the trust relationship
SSRF exploit the trust relationshipSSRF exploit the trust relationship
SSRF exploit the trust relationship
 
Nmap basics
Nmap basicsNmap basics
Nmap basics
 
Metasploit primary
Metasploit primaryMetasploit primary
Metasploit primary
 
Introduction to TLS 1.3
Introduction to TLS 1.3Introduction to TLS 1.3
Introduction to TLS 1.3
 
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
 
Talking About SSRF,CRLF
Talking About SSRF,CRLFTalking About SSRF,CRLF
Talking About SSRF,CRLF
 
Building active directory lab for red teaming
Building active directory lab for red teamingBuilding active directory lab for red teaming
Building active directory lab for red teaming
 
Owning a company through their logs
Owning a company through their logsOwning a company through their logs
Owning a company through their logs
 
Introduction to shodan
Introduction to shodanIntroduction to shodan
Introduction to shodan
 
Cloud security
Cloud security Cloud security
Cloud security
 
Detecting persistence in windows
Detecting persistence in windowsDetecting persistence in windows
Detecting persistence in windows
 
Frida - Objection Tool Usage
Frida - Objection Tool UsageFrida - Objection Tool Usage
Frida - Objection Tool Usage
 
OSQuery - Monitoring System Process
OSQuery - Monitoring System ProcessOSQuery - Monitoring System Process
OSQuery - Monitoring System Process
 
DevSecOps Jenkins Pipeline -Security
DevSecOps Jenkins Pipeline -SecurityDevSecOps Jenkins Pipeline -Security
DevSecOps Jenkins Pipeline -Security
 
Extensible markup language attacks
Extensible markup language attacksExtensible markup language attacks
Extensible markup language attacks
 
Linux for hackers
Linux for hackersLinux for hackers
Linux for hackers
 
Android Pentesting
Android PentestingAndroid Pentesting
Android Pentesting
 
News bytes null 200314121904
News bytes null 200314121904News bytes null 200314121904
News bytes null 200314121904
 

Kürzlich hochgeladen

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 

Kürzlich hochgeladen (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

CORS and (in)security

  • 1. Isolating content between domains since 1996 Riyaz Walikar | @riyazwalikar | www.riyazwalikar.com
  • 2. whoami • WebAppSec Consultant, Penetration Tester, Bug Bounty Hunter for Google, Facebook, Paypal, Mozilla and other bounty programs • One of the null Security Community Bangalore Chapter Moderator • Work at a Big4 and have conducted several Penetration Tests all over the world. • Spoken at several international security conferences
  • 3. Imagine the Internet if • fabekook.cn was able to read DOM values from facebook.com from another browser tab • gmaail.br was able to read your address book from http://mail.google.com/mail/c/data/contactstore?type=4&ma x=-1 • boinkofindia.com was able to read your account balance and obtain a list of all your transactions from your internet banking account while you are logged in.
  • 4. Why is this possible?
  • 6. What is SOP? • SOP restricts how a document or script loaded from one origin can interact with a resource from another origin • Earliest available implementation – Netscape Navigator 2.0 (1996)
  • 7. define: origin URL Outcome Reason http://store.company.com/dir2/other.html Success ---- http://store.company.com/dir/inner/another.html Success ---- https://store.company.com/secure.html Failure Different protocol http://store.company.com:81/dir/etc.html Failure Different port http://news.company.com/dir/other.html Failure Different host Access made from: http://store.company.com/dir/page.html
  • 8. Changing 'origins' • Setting document.domain to a suffix of the current domain. • Setting document.domain to another domain altogether isn’t allowed.
  • 10. Cross Origin Network Access • Origin is permitted to send data to another origin but not read • Interactions between origins are placed in three categories: – Cross origin writes (redirects, links, form action etc.) – Cross origin embedding (html tag with src/hrefs) – Cross origin reads (not allowed without CORS etc.)
  • 11. Cross Origin Embedding • JavaScript <script src="..."></script>. • CSS with <link rel="stylesheet" href="...">. • Images with <img>. • Media files with <video> and <audio> tags. • Plug-ins with <object>, <embed> and <applet>. • Fonts with @font-face. • Anything with <frame> and <iframe>.
  • 12. Prevent Cross Origin Access • To prevent Cross origin writes, use a CSRF token • To prevent Cross origin embedding, ensure resource is not interpreted as any of the formats discussed earlier. • To prevent Cross Origin reads of a resource, ensure that it is non-embeddable. • For iframes the X-Frame-Options header can be used to control access to the page.
  • 13. Cross Origin Resource Sharing • W3C specification that allows cross domain communication from the browser • Works by adding new HTTP headers that describe the set of origins that are permitted to read across domains
  • 14. 3 Pointers • Browsers prevent data from being accessed cross domain via the Same Origin Policy • In case a page loads another domain via a frame, X-Frame-Options can be used to control access • CORS is used to relax the Same Origin Policy for legitimate and trusted requests.
  • 16. Allowing Cross origin resource sharing since March 2004 Riyaz Walikar | @riyazwalikar | www.riyazwalikar.com
  • 17. What is CORS? • W3C working draft that defines how the browser and server must communicate when accessing sources across origins • Implemented via HTTP headers that servers set and browsers enforce • Can be categorized into – Simple requests – Requests that need a ‘preflight’
  • 18. Demo A simple cross origin request without CORS
  • 19. CORS standard exchange between client and server
  • 20. Why is CORS needed? • For legitimate and trusted requests to gain access to authorized data from other domains • Think cross application data sharing models • Allows data to be exchanged with trusted sites while using a relaxed Same Origin policy mode. • Application APIs exposed via web services and trusted domains require CORS to be accessible over the SOP
  • 22. CORS – Simple Requests • Preflight is not needed if – Request is a HEAD/GET/POST via XHR – No Custom headers – Body is text/plain • Server responds with a CORS header – Browser determines access – Neither the request, nor response contain cookies
  • 23. CORS Headers – Simple Request • Origin – Header set by the client for every CORS request – Value is the current domain that made the request • Access-Control-Allow-Origin – Set by the server and used by the browser to determine if the response is to be allowed or not. – Can be set to * to make resources public (bad practice!)
  • 24. Demo A cross origin request with CORS for a simple request
  • 25. CORS – Requests with Preflight • Preflight requests are made if – Request is a method other than HEAD/GET/POST via XHR (PUT, DELETE etc.) – Custom headers are present (X-PINGBACK etc.) – Content-Type other than application/x-www- form-urlencoded, multipart/form-data, or text/plain • A transparent request is made to the server requesting access information using OPTIONS
  • 26. CORS – Requests with Preflight • Browser sends – Origin header – Access-Control-Request-Method – Access-Control-Request-Headers – (Optional) • Server sends set of CORS headers that the browser uses to determine if the actual request has to be made or not
  • 27. CORS Headers – Request with Preflight (Preflight Browser Request) • Origin – Header set by the client for every CORS request – Value is the current domain that made the request • Access-Control-Request-Method: – Set by the browser, along with Origin. – Value is the method that the request wants to use • Access-Control-Request-Headers (Optional): – A comma separated list of the custom headers being used.
  • 28. CORS Headers – Request with Preflight (Preflight Server Response) • Access-Control-Allow-Origin – Same as in Simple requests • Access-Control-Allow-Methods: – a comma separated list of allowed methods • Access-Control-Allow-Headers: – a comma separated list of headers that the server will allow. • Access-Control-Max-Age: – the amount of time in seconds that this preflight request should be cached for.
  • 29. Demo A cross origin request with CORS for a preflight request
  • 30. CORS (In)security? • Several security issues arise from the improper implementation of CORS, most commonly using a universal allow notation (*) in the server headers • Clients should not trust the received content completely and eval or render content without sanitization which could result in misplaced trust • The application that allows CORS may become vulnerable to CSRF attacks
  • 31. CORS (In)security? • Prolonged caching of Preflight responses could lead to attacks arising out of abuse of the Preflight Client Cache • Access control decisions based on the Origin header could result in vulnerabilities as this can be spoofed by an attacker
  • 32. CORS Security - Universal Allow • Setting the 'Access-Control-Allow-Origin' header to * • Effectively turns the content into a public resource, allowing access from any domain • Scenarios? – An attacker can steal data from an intranet site that has set this header to * by enticing a user to visit an attacker controlled site on the Internet. – An attacker can perform attacks on other remote apps via a victim’s browser when the victim navigates to an attacker controlled site.
  • 33. Demo A universal allow for the Access-Control-Allow-Origin header
  • 34. CORS Security – Misplaced Trust • Data exchange between two domains is based on trust • If one of the servers involved in the exchange of data is compromised then the model of CORS is put at risk • Scenarios? – An attacker can compromise site A and host malicious content knowing site B trusts the data that site A sends to site B via CORS request resulting in XSS and other attacks. – An attacker can compromise site B and use the exposed CORS functionality in site A to attack users in site A.
  • 35. CSRF with CORS • Server may process client request to change server side data while verifying that the Origin header was set • An attacker can use the .withCredentials = “true” property of XHR to replay any cookies to the application on which the victim is logged in • Scenarios? – An attacker sets the Origin header or uses a trusted site A to send a non idempotent request to site B – The victim who is logged into site B when he is viewing the trusted site A causes site B to create a user account without his knowledge via a CSRF attack
  • 36. Demo A CSRF attack that creates a user using a trusted site via CORS
  • 37. CORS – Caching of Preflight responses • The Access-Control-Max-Age header is set to a high value, allowing browsers to cache Preflight responses • Caching the preflight response for longer duration can pose a security risk. • If the COR access-control policy is changed on the server the browser would still follow the old policy available in the Preflight Result Cache
  • 38. CORS – Access Control based on Origin • The Origin header indicates that the request is from a particular domain, but does not guarantee it • Spoofing the Origin header allows access to the page if access is based on this header • Scenarios? – An attacker sets the Origin header to view sensitive information that is restricted – Attacker uses cURL to set a custom origin header: curl --header 'origin:http://someserver.com' http://myserver.com:90/demo/origin_spoof.php
  • 39. Demo Sensitive information revealed via weak Access Control based on the Origin header
  • 40. References • http://www.html5rocks.com/en/tutorials/cors/ • https://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity • http://arunranga.com/examples/access-control/ • http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin- resource-sharing/
  • 42. Riyaz Walikar | @riyazwalikar | karniv0re@null.co.in