SlideShare a Scribd company logo
Content Isolation with

Same Origin Policy

     Krishna Chaitanya T
         Infosys Labs
Microsoft MVP, Internet Explorer
You know this is possible…
         (why?)
Why not this?
Why?
Why not?
The big (small) picture
• WHO can access WHAT from WHERE,
  HOW and WHY? Any IFs and BUTs? ;)

          Site A        Site B




          Browsing     Browsing
          context of   context of
            Site A       Site B
The questions…
• Can A get resources from B.com?

• Can A execute resources from B.com?

• Can A post content to B.com?

• Can A interfere with the DOM of B?

• Can A redirect a browsing context of B?
More questions…
• Can A read cookies/localStorage of B?

• What about http/https protocols

• How about different port numbers?

• Can chat.A.com communicate with A.com?

• Can blog.com/user1 talk to blog.com/user2?
Ok. Now enough of questions.

   Let’s clear the confusion!
Same Origin Policy (SOP)
• Browser has to isolate different origins
• Origin = scheme://host:port
  • https://mysite.com
  • http://chat.mysite.com
  • http://mysite.com:81/

• Privileges within origin
  • Full network access, storage, read/write access to DOM
SOP facts…
• Script requests are not subjected to SOP!
• Frames have separate security contexts for
  each origin.
• Frame Navigation Policy: Script in Frame A
  can navigate Frame B (This is not SOP!)
• Access to HTML5 LocalStorage, Cookies*
  is by SOP.
SOP facts…
• Browsers do not prevent cross domain
  content inclusion!
• Examples:
    <iframe src=“…”/>
    <img src=“…”/>
    <link rel=“stylesheet” href=“…”/>
• Information about user’s interaction can be
  collected using events onload, onerror etc.
So how is cross origin communication feasible with
           Same Origin Policy in place?



       HACKS / SOP bypass
SOP Hacks
• JSONP – JSON with Padding
• Domain relaxation – document.domain
• Server side proxies
• JavaScript window.name hack
• Iframe hacks-Fragment Identifier
  Messaging (FIM), Subspace etc.
Understanding JSONP
1. Create a JavaScript function (callback)
   function processData(data){
              console.log('Hello '+data.firstName+' '+data.lastName);
   }

2. Pass valid JSON data & execute it
       processData({firstName:'Krishna', lastName:'Chaitanya'});



3. Move the code in step 2 to external JS file
   (Idea is to simulate server’s response). So
   far it’s good.
Understanding JSONP
4. Configure server side code to respond to
   the query string
   <script src=“http://mysite.com/index.aspx?callback=processData”/>



5. Script loading is exempted from SOP, so
   the code so far still works.
6. Wrap JSON data with function name.
       processData({firstName:'Krishna', lastName:'Chaitanya'});
Domain relaxation
• Cooperating websites sharing common
  TLDs can relax their origins
• “a.site.com” & “site.com” - different origins
• Both parties should set document.domain
               document.domain=“site.com”


• Now sub domain enjoys same origin
  benefits!
Surprisingly, there wasn’t a standard for cross origin
 communication till recently. Only few clever hacks.



         Here comes HTML5!
Genuine Cross Origin Access
• Client side - HTML5 PostMessage API
  • Secure communication between frames
      otherwindow.postMessage(message, targetOrigin);



    //Posting message to a cross domain partner.
    frames[0].postMessage(“Hello Partner!”,
    "http://localhost:81/");

    //Retrieving message from the sender
    window.onmessage = function (e) {
         if (e.origin == 'http://localhost') {
             //sanitize and accept data
         }
    };
Genuine Cross Origin Access
• Server side – HTML5 CORS
  • XHR enhanced for secure cross origin sharing
     var xhr = new XMLHttpRequest();
     if ("withCredentials" in xhr) {
                xhr.open("GET", "http://mysite.com", true);
                xhr.send();
     } else {
                // Fallback behavior
     }


  • Server just needs to send this new header:
        Access-Control-Allow-Origin: http://mysite.com (or) *



                                           More about these in future events 
A better picture

 Site A                      Site B




 Browsing                   Browsing
 context of                 context of
   Site A                     Site B




              AJAX
              PostMessage (HTML5)
              Cross Origin Resource Sharing (HTML5)
              Server side proxy
Litmus Test ;)

 If (!sleepy && !confused){
          GoTo slide 2;
          print(“Answer all questions till slide 8 correctly”);
 }
 else {
          GoTo slide 9;
          print(“Repeat”);
 }
Thank You!

Twitter: @novogeek
Blog: http://novogeek.com

More Related Content

PPTX
Secure web messaging in HTML5
PPTX
JSFoo Chennai 2012
PPTX
Clickjacking DevCon2011
PPTX
Html5 security
PPTX
Dom based xss
PPT
Same Origin Policy Weaknesses
PDF
Attacking Web Proxies
PDF
Html5 for Security Folks
Secure web messaging in HTML5
JSFoo Chennai 2012
Clickjacking DevCon2011
Html5 security
Dom based xss
Same Origin Policy Weaknesses
Attacking Web Proxies
Html5 for Security Folks

What's hot (20)

PPT
Browser Security
PDF
New Insights into Clickjacking
PPT
Xss is more than a simple threat
PPTX
Owasp Top 10 A3: Cross Site Scripting (XSS)
PPTX
Cross Site Scripting Defense Presentation
PDF
The Cross Site Scripting Guide
PDF
Html5 localstorage attack vectors
PPTX
Click jacking
PPTX
Cross Site Scripting (XSS)
PPTX
Cross-Site Scripting (XSS)
PPT
Xss talk, attack and defense
PDF
BsidesDelhi 2018: DomGoat - the DOM Security Playground
PDF
When Ajax Attacks! Web application security fundamentals
PPTX
Top Ten Web Hacking Techniques of 2012
KEY
Cross Site Scripting - Mozilla Security Learning Center
PPT
Top Ten Web Hacking Techniques – 2008
PDF
Top Ten Web Hacking Techniques (2010)
PPT
Web browser privacy and security
PDF
XSS-Alert-Pentration testing tool
Browser Security
New Insights into Clickjacking
Xss is more than a simple threat
Owasp Top 10 A3: Cross Site Scripting (XSS)
Cross Site Scripting Defense Presentation
The Cross Site Scripting Guide
Html5 localstorage attack vectors
Click jacking
Cross Site Scripting (XSS)
Cross-Site Scripting (XSS)
Xss talk, attack and defense
BsidesDelhi 2018: DomGoat - the DOM Security Playground
When Ajax Attacks! Web application security fundamentals
Top Ten Web Hacking Techniques of 2012
Cross Site Scripting - Mozilla Security Learning Center
Top Ten Web Hacking Techniques – 2008
Top Ten Web Hacking Techniques (2010)
Web browser privacy and security
XSS-Alert-Pentration testing tool
Ad

Similar to Browser Internals-Same Origin Policy (20)

PDF
Going Beyond Cross Domain Boundaries (jQuery Bulgaria)
PDF
Building Client-Side Attacks with HTML5 Features
PDF
Krzysztof Kotowicz - Hacking HTML5
PDF
AtlasCamp 2014: 10 Things a Front End Developer Should Know About Connect
PPTX
Building Secure User Interfaces With JWTs
PDF
Hacking HTML5 offensive course (Zeronights edition)
PDF
Html5 security
PPT
Top 10 HTML5 Features for Oracle Cloud Developers
PPTX
Browsers_SameOriginPolicy_CORS_ContentSecurityPolicy
PPTX
Building Secure User Interfaces With JWTs (JSON Web Tokens)
PPTX
Websocket vs SSE - Paris.js - 24/06/15
PPT
HTML5 hacking
PPTX
HTML5: An Overview
PDF
Talk about html5 security
KEY
Message in a Bottle
PDF
Nodejs and WebSockets
PPTX
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
PDF
Html5 Application Security
PPTX
Asynchronous Web Programming with HTML5 WebSockets and Java
PPT
Browser security
Going Beyond Cross Domain Boundaries (jQuery Bulgaria)
Building Client-Side Attacks with HTML5 Features
Krzysztof Kotowicz - Hacking HTML5
AtlasCamp 2014: 10 Things a Front End Developer Should Know About Connect
Building Secure User Interfaces With JWTs
Hacking HTML5 offensive course (Zeronights edition)
Html5 security
Top 10 HTML5 Features for Oracle Cloud Developers
Browsers_SameOriginPolicy_CORS_ContentSecurityPolicy
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Websocket vs SSE - Paris.js - 24/06/15
HTML5 hacking
HTML5: An Overview
Talk about html5 security
Message in a Bottle
Nodejs and WebSockets
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Html5 Application Security
Asynchronous Web Programming with HTML5 WebSockets and Java
Browser security
Ad

Recently uploaded (20)

PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Machine learning based COVID-19 study performance prediction
PPT
Teaching material agriculture food technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
August Patch Tuesday
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Empathic Computing: Creating Shared Understanding
A comparative analysis of optical character recognition models for extracting...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Advanced methodologies resolving dimensionality complications for autism neur...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Machine learning based COVID-19 study performance prediction
Teaching material agriculture food technology
Unlocking AI with Model Context Protocol (MCP)
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Programs and apps: productivity, graphics, security and other tools
TLE Review Electricity (Electricity).pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
August Patch Tuesday
Mobile App Security Testing_ A Comprehensive Guide.pdf
A comparative study of natural language inference in Swahili using monolingua...
Heart disease approach using modified random forest and particle swarm optimi...
Spectroscopy.pptx food analysis technology
Empathic Computing: Creating Shared Understanding

Browser Internals-Same Origin Policy

  • 1. Content Isolation with Same Origin Policy Krishna Chaitanya T Infosys Labs Microsoft MVP, Internet Explorer
  • 2. You know this is possible… (why?)
  • 6. The big (small) picture • WHO can access WHAT from WHERE, HOW and WHY? Any IFs and BUTs? ;) Site A Site B Browsing Browsing context of context of Site A Site B
  • 7. The questions… • Can A get resources from B.com? • Can A execute resources from B.com? • Can A post content to B.com? • Can A interfere with the DOM of B? • Can A redirect a browsing context of B?
  • 8. More questions… • Can A read cookies/localStorage of B? • What about http/https protocols • How about different port numbers? • Can chat.A.com communicate with A.com? • Can blog.com/user1 talk to blog.com/user2?
  • 9. Ok. Now enough of questions. Let’s clear the confusion!
  • 10. Same Origin Policy (SOP) • Browser has to isolate different origins • Origin = scheme://host:port • https://mysite.com • http://chat.mysite.com • http://mysite.com:81/ • Privileges within origin • Full network access, storage, read/write access to DOM
  • 11. SOP facts… • Script requests are not subjected to SOP! • Frames have separate security contexts for each origin. • Frame Navigation Policy: Script in Frame A can navigate Frame B (This is not SOP!) • Access to HTML5 LocalStorage, Cookies* is by SOP.
  • 12. SOP facts… • Browsers do not prevent cross domain content inclusion! • Examples: <iframe src=“…”/> <img src=“…”/> <link rel=“stylesheet” href=“…”/> • Information about user’s interaction can be collected using events onload, onerror etc.
  • 13. So how is cross origin communication feasible with Same Origin Policy in place? HACKS / SOP bypass
  • 14. SOP Hacks • JSONP – JSON with Padding • Domain relaxation – document.domain • Server side proxies • JavaScript window.name hack • Iframe hacks-Fragment Identifier Messaging (FIM), Subspace etc.
  • 15. Understanding JSONP 1. Create a JavaScript function (callback) function processData(data){ console.log('Hello '+data.firstName+' '+data.lastName); } 2. Pass valid JSON data & execute it processData({firstName:'Krishna', lastName:'Chaitanya'}); 3. Move the code in step 2 to external JS file (Idea is to simulate server’s response). So far it’s good.
  • 16. Understanding JSONP 4. Configure server side code to respond to the query string <script src=“http://mysite.com/index.aspx?callback=processData”/> 5. Script loading is exempted from SOP, so the code so far still works. 6. Wrap JSON data with function name. processData({firstName:'Krishna', lastName:'Chaitanya'});
  • 17. Domain relaxation • Cooperating websites sharing common TLDs can relax their origins • “a.site.com” & “site.com” - different origins • Both parties should set document.domain document.domain=“site.com” • Now sub domain enjoys same origin benefits!
  • 18. Surprisingly, there wasn’t a standard for cross origin communication till recently. Only few clever hacks. Here comes HTML5!
  • 19. Genuine Cross Origin Access • Client side - HTML5 PostMessage API • Secure communication between frames otherwindow.postMessage(message, targetOrigin); //Posting message to a cross domain partner. frames[0].postMessage(“Hello Partner!”, "http://localhost:81/"); //Retrieving message from the sender window.onmessage = function (e) { if (e.origin == 'http://localhost') { //sanitize and accept data } };
  • 20. Genuine Cross Origin Access • Server side – HTML5 CORS • XHR enhanced for secure cross origin sharing var xhr = new XMLHttpRequest(); if ("withCredentials" in xhr) { xhr.open("GET", "http://mysite.com", true); xhr.send(); } else { // Fallback behavior } • Server just needs to send this new header: Access-Control-Allow-Origin: http://mysite.com (or) * More about these in future events 
  • 21. A better picture Site A Site B Browsing Browsing context of context of Site A Site B AJAX PostMessage (HTML5) Cross Origin Resource Sharing (HTML5) Server side proxy
  • 22. Litmus Test ;) If (!sleepy && !confused){ GoTo slide 2; print(“Answer all questions till slide 8 correctly”); } else { GoTo slide 9; print(“Repeat”); }
  • 23. Thank You! Twitter: @novogeek Blog: http://novogeek.com