SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
Trusted Types - W3C TPAC
Krzysztof Kotowicz, Google
koto@google.com
https://github.com/WICG/trusted-types
Slides: https://tinyurl.com/tttpac
DOM XSS
DOM XSS is a growing, prevalent problem
source ⇒ sink
location.hash ⇒ bar.innerHTML
● At Google, DOM XSS is already the most common XSS variant
Reasons:
● Growing complexity of client-side code
● Easy to introduce, hard to prevent & detect
DOM XSS is easy to introduce
● DOM API has ~70 sinks that can result in JavaScript execution
innerHTML, HTMLScriptElement.src, eval()
● These sinks are extremely common in applications
● DOM API “insecure by default”
(input) => document.querySelector(‘log’).innerHTML = input
● Sources far away from sinks, complex data flows (e.g. server roundtrip)
● Static checks don’t work reliably:
foo.innerHTML = bar // what is bar?
foo[(_ => "innerHTML")()] = bar
foo[k] = v
● Manual review is infeasible
● Dynamic (taint-tracking, fuzzing) has a small code coverage
DOM XSS is hard to detect
DOM XSS is hard to mitigate
● HTML Sanitization, CSP - bypasses via script gadgets
<div data-role=popup id='--><script>"use strict"
alert(1)</script>'></div>
<template is=dom-bind><div
c={{alert('1',ownerDocument.defaultView)}}
b={{set('_rootDataHost',ownerDocument.defaultView)}}>
</div></template>
● In-browser XSS filters - DOM XSS out of scope
Addressing DOM XSS @ Google
● Stop tracking a string, leverage the type system
● https://github.com/google/safe-html-types/blob/master/doc/safehtml-typ
es.md
● Wrappers for strings, representing values known to be safe to use in
various HTML contexts and with various DOM APIs:
○ SafeHTML (<b>I’m safe</b>)
○ SafeURL (https://click.me)
○ TrustedResourceURL (https://i.am.a/script.js)
○ …
Safe HTML Types
● Producing the typed value is safe by construction
goog.html.SafeHtml.create(“DIV”, {“benign”: “attributes”}, “text”);
● ... or sanitization (integrate with your sanitizers, templating systems, …)
goog.html.SafeUrl.sanitize(untrustedUrl);
● or gets reviewed manually
goog.html.uncheckedconversions.safeUrlFromStringKnownToSatisfyTypeContract(
“url comes from the server response”, url);
Producing Safe HTML types
Consuming Safe HTML types
● A typed object is propagated throughout the application code
● Taint tracking not necessary
● Wrappers over DOM XSS sinks that accept only typed values
goog.dom.safe.setLocationHref(locationObj, safeURL)
● Compiler prohibits the use of native sinks
let foo = “bar”; location.href = foo
Compile error!
● DOM is secure by default
● Only the code producing a safe type can introduce XSS
● Reduce the security-relevant code by orders of magnitude
○ Stable components (sanitizers, templating libs)
○ Custom application code producing the types
○ Scales extremely well (<1 headcount for all of Google)
● Very successful at preventing XSS
● … as understood by the compiler
Safe HTML Types advantages
Safe HTML Types limitations
● Reliance on compilation
○ Not all code is compiled
○ Different compilation units
○ Cross-language boundaries
● Compiler limitations
○ JS type system is unsound
○ Reflection, dynamic code
○ Missing type information
○ False positive/false negative tradeoff
● No protection at runtime
Trusted Types
Trusted Types
Safe HTML types
built into the platform
Trusted Types
1. API to create string-wrapping objects of a few types:
a. TrustedHTML (.innerHTML)
b. TrustedURL (a.href)
c. TrustedScriptURL (script.src)
d. TrustedScript (el.onclick)
TrustedURL<"//foo">.toString() == "//foo"
2. Opt-in enforcement:
Make DOM XSS sinks accept only the typed objects
Trusted Types
Without enforcement:
● Use types in place of strings with no breakage
● Backwards compatible (use the light polyfill defining the types)
With enforcement:
● DOM XSS attack surface reduction - minimizing the trusted codebase
● Only the code producing the types can introduce DOM XSS
● Design facilitates limiting the “DOM XSS capability” via policies
const myPolicy = TrustedTypes.createPolicy('my-policy', {
createHTML(html) {
return mySanitizer(html)
},
createScriptURL(url) {
const u = new URL(url, document.baseURI)
if (u.origin === window.origin)
return u.href;
throw new TypeError('Invalid URL!')
}
})
Trusted Types - policies
Name
Rules
Sanitize
HTML
Only
same
origin
scripts
Policy
Trusted Types - creating & using types
> document.body.innerHTML = myPolicy.createHTML(location.hash);
Running mySanitizer…
> document.body.innerHTML = location.hash
TypeError: HTMLBodyElement.innerHTML requires TrustedHTML assignment
(dispatch a securitypolicyviolation event?)
(function() {
// Seemingly unsafe policy
const unsafePolicy = TrustedTypes.createPolicy('unsafefoo', {
createHTML: (s) => s,
});
// No XSS because of the usage limitation
return fetch('/get-html')....then(
(response) => unsafePolicy.createHTML(response)
);
})();
Trusted Types - guarding policy usage
● Only the code calling an insecure policy
can cause DOM XSS
● Policy reference similar to a CSP script
nonce
● Rest of codebase is “DOM XSS neutral”
● Enables gradual adoption with
immediate security benefits
● Example blogging application - DOM
XSS can only be caused by a Markdown
renderer.
Module
Unsafe
policy
Secure
policy
Module
Module
Module
Module
Trusted Types - guarding policy usage
Enforcement & guarding policy creation
An X-Bikeshed-Later*
response header with a list of allowed policy names:
Content-Security-Policy: trusted-types foo bar
TrustedTypes.createPolicy('foo', ...) // OK
TrustedTypes.createPolicy('bar', ...) // OK
TrustedTypes.createPolicy('baz', ...) // Policy disallowed
Content-Security-Policy: trusted-types *
*
For now, Content-Security-Policy
● Trusted objects can be created via policies
● A policy defines application-specific rules to create types
● Multiple policies can coexist
○ A strict HTML sanitizer for the comment editing section
○ A custom one for application templating system
● Limit policy creation
○ Response header value
● Limit policy usage
○ Guard the reference
○ Example: HTML sanitizers need a no-op policy to use internally only
Policies
Implementations:
● Chrome - http://crbug/739170, http://w3c-test.org/trusted-types/
google-chrome-unstable --enable-blink-features=TrustedDOMTypes
--enable-experimental-web-platform-features
● Polyfill - https://github.com/WICG/trusted-types
○ https://wicg.github.io/trusted-types/demo/
● Tinyfill - TrustedTypes={createPolicy:(n, rules) => rules}
Trusted Types status
Integration trials
● JS libraries and frameworks: DOM interpolation, templating
○ Angular, Polymer + https://github.com/Polymer/polymer-resin
○ Pug - https://github.com/mikesamuel/pug-plugin-trusted-types
● External examples:
○ Sanitizers: http://koto.github.io/DOMPurify/demos/trusted-types-demo.html
○ Angular app: gothinkster/angular-realworld-example-app - 44 lines ugly patch
○ React app gothinkster/react-redux-realworld-example-app - trivial patch
● Internally - adopting Trusted Types at Google applications
Trusted Types status
● Makes DOM XSS easy to detect & difficult to introduce
○ Based on a solution with proven track record
(most core Google applications use it)
○ Promotes containing security-relevant code
○ Power to the authors (custom rules, multiple policies)
○ Control to the security teams (policy review, header control)
● Backwards-compatible, polyfillable
● Easy to implement in UAs (1Q 2*intern project at Google)
● Extensible: more types, browser-provided policies, userland libraries
Summary

Más contenido relacionado

La actualidad más candente

In the DOM, no one will hear you scream
In the DOM, no one will hear you screamIn the DOM, no one will hear you scream
In the DOM, no one will hear you screamMario Heiderich
 
An Abusive Relationship with AngularJS
An Abusive Relationship with AngularJSAn Abusive Relationship with AngularJS
An Abusive Relationship with AngularJSMario Heiderich
 
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...Mario Heiderich
 
The Image that called me - Active Content Injection with SVG Files
The Image that called me - Active Content Injection with SVG FilesThe Image that called me - Active Content Injection with SVG Files
The Image that called me - Active Content Injection with SVG FilesMario Heiderich
 
The Ultimate IDS Smackdown
The Ultimate IDS SmackdownThe Ultimate IDS Smackdown
The Ultimate IDS SmackdownMario Heiderich
 
The Future of Web Attacks - CONFidence 2010
The Future of Web Attacks - CONFidence 2010The Future of Web Attacks - CONFidence 2010
The Future of Web Attacks - CONFidence 2010Mario Heiderich
 
A XSSmas carol
A XSSmas carolA XSSmas carol
A XSSmas carolcgvwzq
 
Dev and Blind - Attacking the weakest Link in IT Security
Dev and Blind - Attacking the weakest Link in IT SecurityDev and Blind - Attacking the weakest Link in IT Security
Dev and Blind - Attacking the weakest Link in IT SecurityMario Heiderich
 
talk-ta3m-crypto-tools-workshop
talk-ta3m-crypto-tools-workshoptalk-ta3m-crypto-tools-workshop
talk-ta3m-crypto-tools-workshopSteve Phillips
 
SMIMP Lightning Talk - DEFCON CryptoVillage
SMIMP Lightning Talk - DEFCON CryptoVillageSMIMP Lightning Talk - DEFCON CryptoVillage
SMIMP Lightning Talk - DEFCON CryptoVillageAdam Caudill
 
Security Vulnerabilities: How to Defend Against Them
Security Vulnerabilities: How to Defend Against ThemSecurity Vulnerabilities: How to Defend Against Them
Security Vulnerabilities: How to Defend Against ThemMartin Vigo
 
Dot Net Training in Chennai
Dot Net Training in ChennaiDot Net Training in Chennai
Dot Net Training in Chennaijeevanfita
 
Security in PHP Applications: An absolute must!
Security in PHP Applications: An absolute must!Security in PHP Applications: An absolute must!
Security in PHP Applications: An absolute must!Mark Niebergall
 
REST project brief - typical setup for teams
REST project brief - typical setup for teamsREST project brief - typical setup for teams
REST project brief - typical setup for teamsDian Swanepoel
 
Cookie mechanism and attacks on web-client
Cookie mechanism and attacks on web-client Cookie mechanism and attacks on web-client
Cookie mechanism and attacks on web-client Positive Hack Days
 
Lock Interface in Java
Lock Interface in JavaLock Interface in Java
Lock Interface in JavaHome
 

La actualidad más candente (20)

In the DOM, no one will hear you scream
In the DOM, no one will hear you screamIn the DOM, no one will hear you scream
In the DOM, no one will hear you scream
 
An Abusive Relationship with AngularJS
An Abusive Relationship with AngularJSAn Abusive Relationship with AngularJS
An Abusive Relationship with AngularJS
 
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
 
The Image that called me - Active Content Injection with SVG Files
The Image that called me - Active Content Injection with SVG FilesThe Image that called me - Active Content Injection with SVG Files
The Image that called me - Active Content Injection with SVG Files
 
The Ultimate IDS Smackdown
The Ultimate IDS SmackdownThe Ultimate IDS Smackdown
The Ultimate IDS Smackdown
 
The Future of Web Attacks - CONFidence 2010
The Future of Web Attacks - CONFidence 2010The Future of Web Attacks - CONFidence 2010
The Future of Web Attacks - CONFidence 2010
 
A XSSmas carol
A XSSmas carolA XSSmas carol
A XSSmas carol
 
Dev and Blind - Attacking the weakest Link in IT Security
Dev and Blind - Attacking the weakest Link in IT SecurityDev and Blind - Attacking the weakest Link in IT Security
Dev and Blind - Attacking the weakest Link in IT Security
 
talk-ta3m-crypto-tools-workshop
talk-ta3m-crypto-tools-workshoptalk-ta3m-crypto-tools-workshop
talk-ta3m-crypto-tools-workshop
 
Introducing Cloakcast
Introducing CloakcastIntroducing Cloakcast
Introducing Cloakcast
 
XSS
XSSXSS
XSS
 
XML Security
XML SecurityXML Security
XML Security
 
SMIMP Lightning Talk - DEFCON CryptoVillage
SMIMP Lightning Talk - DEFCON CryptoVillageSMIMP Lightning Talk - DEFCON CryptoVillage
SMIMP Lightning Talk - DEFCON CryptoVillage
 
XML Encryption
XML EncryptionXML Encryption
XML Encryption
 
Security Vulnerabilities: How to Defend Against Them
Security Vulnerabilities: How to Defend Against ThemSecurity Vulnerabilities: How to Defend Against Them
Security Vulnerabilities: How to Defend Against Them
 
Dot Net Training in Chennai
Dot Net Training in ChennaiDot Net Training in Chennai
Dot Net Training in Chennai
 
Security in PHP Applications: An absolute must!
Security in PHP Applications: An absolute must!Security in PHP Applications: An absolute must!
Security in PHP Applications: An absolute must!
 
REST project brief - typical setup for teams
REST project brief - typical setup for teamsREST project brief - typical setup for teams
REST project brief - typical setup for teams
 
Cookie mechanism and attacks on web-client
Cookie mechanism and attacks on web-client Cookie mechanism and attacks on web-client
Cookie mechanism and attacks on web-client
 
Lock Interface in Java
Lock Interface in JavaLock Interface in Java
Lock Interface in Java
 

Similar a Trusted Types @ W3C TPAC 2018

[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSS[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSSOWASP
 
Web security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersWeb security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersPhú Phùng
 
Content Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at YahooContent Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at YahooBinu Ramakrishnan
 
Securing the client side web
Securing the client side webSecuring the client side web
Securing the client side webSC5.io
 
Tsc summit #2 - HTTP Header Security
Tsc summit #2  - HTTP Header SecurityTsc summit #2  - HTTP Header Security
Tsc summit #2 - HTTP Header SecurityMikal Villa
 
Introduction to Web Application Security - Blackhoodie US 2018
Introduction to Web Application Security - Blackhoodie US 2018Introduction to Web Application Security - Blackhoodie US 2018
Introduction to Web Application Security - Blackhoodie US 2018Niranjanaa Ragupathy
 
Sandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession LearnedSandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession LearnedMinded Security
 
Web security: Securing untrusted web content at browsers
Web security: Securing untrusted web content at browsersWeb security: Securing untrusted web content at browsers
Web security: Securing untrusted web content at browsersPhú Phùng
 
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
 
The Cross Site Scripting Guide
The Cross Site Scripting GuideThe Cross Site Scripting Guide
The Cross Site Scripting GuideDaisuke_Dan
 
BSides Rochester 2018: Chaim Sanders: How the Cookie Crumbles: Modern HTTP St...
BSides Rochester 2018: Chaim Sanders: How the Cookie Crumbles: Modern HTTP St...BSides Rochester 2018: Chaim Sanders: How the Cookie Crumbles: Modern HTTP St...
BSides Rochester 2018: Chaim Sanders: How the Cookie Crumbles: Modern HTTP St...JosephTesta9
 
Dom based xss
Dom based xssDom based xss
Dom based xssLê Giáp
 
Story of http headers
Story of http headersStory of http headers
Story of http headersVandana Verma
 
Efficient Context-sensitive Output Escaping for Javascript Template Engines
Efficient Context-sensitive Output Escaping for Javascript Template EnginesEfficient Context-sensitive Output Escaping for Javascript Template Engines
Efficient Context-sensitive Output Escaping for Javascript Template Enginesadonatwork
 
Waf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScriptWaf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScriptDenis Kolegov
 
Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007Stephan Chenette
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encodingEoin Keary
 

Similar a Trusted Types @ W3C TPAC 2018 (20)

[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSS[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSS
 
Web security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersWeb security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in Browsers
 
Content Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at YahooContent Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at Yahoo
 
Securing the client side web
Securing the client side webSecuring the client side web
Securing the client side web
 
Tsc summit #2 - HTTP Header Security
Tsc summit #2  - HTTP Header SecurityTsc summit #2  - HTTP Header Security
Tsc summit #2 - HTTP Header Security
 
Introduction to Web Application Security - Blackhoodie US 2018
Introduction to Web Application Security - Blackhoodie US 2018Introduction to Web Application Security - Blackhoodie US 2018
Introduction to Web Application Security - Blackhoodie US 2018
 
Sandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession LearnedSandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession Learned
 
Web security: Securing untrusted web content at browsers
Web security: Securing untrusted web content at browsersWeb security: Securing untrusted web content at browsers
Web security: Securing untrusted web content at browsers
 
Let's talk Security
Let's talk SecurityLet's talk Security
Let's talk Security
 
Html5 hacking
Html5 hackingHtml5 hacking
Html5 hacking
 
WAF protections and bypass resources
WAF protections and bypass resourcesWAF protections and bypass resources
WAF protections and bypass resources
 
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)
 
The Cross Site Scripting Guide
The Cross Site Scripting GuideThe Cross Site Scripting Guide
The Cross Site Scripting Guide
 
BSides Rochester 2018: Chaim Sanders: How the Cookie Crumbles: Modern HTTP St...
BSides Rochester 2018: Chaim Sanders: How the Cookie Crumbles: Modern HTTP St...BSides Rochester 2018: Chaim Sanders: How the Cookie Crumbles: Modern HTTP St...
BSides Rochester 2018: Chaim Sanders: How the Cookie Crumbles: Modern HTTP St...
 
Dom based xss
Dom based xssDom based xss
Dom based xss
 
Story of http headers
Story of http headersStory of http headers
Story of http headers
 
Efficient Context-sensitive Output Escaping for Javascript Template Engines
Efficient Context-sensitive Output Escaping for Javascript Template EnginesEfficient Context-sensitive Output Escaping for Javascript Template Engines
Efficient Context-sensitive Output Escaping for Javascript Template Engines
 
Waf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScriptWaf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScript
 
Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encoding
 

Más de Krzysztof Kotowicz

Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.Krzysztof Kotowicz
 
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
 
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome ExtensionsI'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome ExtensionsKrzysztof Kotowicz
 
I'm in your browser, pwning your stuff
I'm in your browser, pwning your stuffI'm in your browser, pwning your stuff
I'm in your browser, pwning your stuffKrzysztof Kotowicz
 
Advanced Chrome extension exploitation
Advanced Chrome extension exploitationAdvanced Chrome extension exploitation
Advanced Chrome extension exploitationKrzysztof Kotowicz
 
Html5: Something wicked this way comes (Hack in Paris)
Html5: Something wicked this way comes (Hack in Paris)Html5: Something wicked this way comes (Hack in Paris)
Html5: Something wicked this way comes (Hack in Paris)Krzysztof Kotowicz
 
Something wicked this way comes - CONFidence
Something wicked this way comes - CONFidenceSomething wicked this way comes - CONFidence
Something wicked this way comes - CONFidenceKrzysztof Kotowicz
 
Html5: something wicked this way comes - HackPra
Html5: something wicked this way comes - HackPraHtml5: something wicked this way comes - HackPra
Html5: something wicked this way comes - HackPraKrzysztof Kotowicz
 
Html5: something wicked this way comes
Html5: something wicked this way comesHtml5: something wicked this way comes
Html5: something wicked this way comesKrzysztof Kotowicz
 
Creating, obfuscating and analyzing malware JavaScript
Creating, obfuscating and analyzing malware JavaScriptCreating, obfuscating and analyzing malware JavaScript
Creating, obfuscating and analyzing malware JavaScriptKrzysztof Kotowicz
 
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScriptTworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScriptKrzysztof Kotowicz
 
Jak ocalić swoje dane przed SQL injection?
Jak ocalić swoje dane przed SQL injection?Jak ocalić swoje dane przed SQL injection?
Jak ocalić swoje dane przed SQL injection?Krzysztof Kotowicz
 
SQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developersSQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developersKrzysztof Kotowicz
 
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)Krzysztof Kotowicz
 

Más de Krzysztof Kotowicz (15)

Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
 
Hacking HTML5 offensive course (Zeronights edition)
Hacking HTML5 offensive course (Zeronights edition)Hacking HTML5 offensive course (Zeronights edition)
Hacking HTML5 offensive course (Zeronights edition)
 
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome ExtensionsI'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions
I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions
 
HTML5: Atak i obrona
HTML5: Atak i obronaHTML5: Atak i obrona
HTML5: Atak i obrona
 
I'm in your browser, pwning your stuff
I'm in your browser, pwning your stuffI'm in your browser, pwning your stuff
I'm in your browser, pwning your stuff
 
Advanced Chrome extension exploitation
Advanced Chrome extension exploitationAdvanced Chrome extension exploitation
Advanced Chrome extension exploitation
 
Html5: Something wicked this way comes (Hack in Paris)
Html5: Something wicked this way comes (Hack in Paris)Html5: Something wicked this way comes (Hack in Paris)
Html5: Something wicked this way comes (Hack in Paris)
 
Something wicked this way comes - CONFidence
Something wicked this way comes - CONFidenceSomething wicked this way comes - CONFidence
Something wicked this way comes - CONFidence
 
Html5: something wicked this way comes - HackPra
Html5: something wicked this way comes - HackPraHtml5: something wicked this way comes - HackPra
Html5: something wicked this way comes - HackPra
 
Html5: something wicked this way comes
Html5: something wicked this way comesHtml5: something wicked this way comes
Html5: something wicked this way comes
 
Creating, obfuscating and analyzing malware JavaScript
Creating, obfuscating and analyzing malware JavaScriptCreating, obfuscating and analyzing malware JavaScript
Creating, obfuscating and analyzing malware JavaScript
 
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScriptTworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
 
Jak ocalić swoje dane przed SQL injection?
Jak ocalić swoje dane przed SQL injection?Jak ocalić swoje dane przed SQL injection?
Jak ocalić swoje dane przed SQL injection?
 
SQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developersSQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developers
 
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)
Kompletny przewodnik po SQL injection dla developerów PHP (i nie tylko)
 

Último

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Último (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Trusted Types @ W3C TPAC 2018

  • 1. Trusted Types - W3C TPAC Krzysztof Kotowicz, Google koto@google.com https://github.com/WICG/trusted-types Slides: https://tinyurl.com/tttpac
  • 3. DOM XSS is a growing, prevalent problem source ⇒ sink location.hash ⇒ bar.innerHTML ● At Google, DOM XSS is already the most common XSS variant Reasons: ● Growing complexity of client-side code ● Easy to introduce, hard to prevent & detect
  • 4. DOM XSS is easy to introduce ● DOM API has ~70 sinks that can result in JavaScript execution innerHTML, HTMLScriptElement.src, eval() ● These sinks are extremely common in applications ● DOM API “insecure by default” (input) => document.querySelector(‘log’).innerHTML = input
  • 5. ● Sources far away from sinks, complex data flows (e.g. server roundtrip) ● Static checks don’t work reliably: foo.innerHTML = bar // what is bar? foo[(_ => "innerHTML")()] = bar foo[k] = v ● Manual review is infeasible ● Dynamic (taint-tracking, fuzzing) has a small code coverage DOM XSS is hard to detect
  • 6. DOM XSS is hard to mitigate ● HTML Sanitization, CSP - bypasses via script gadgets <div data-role=popup id='--><script>"use strict" alert(1)</script>'></div> <template is=dom-bind><div c={{alert('1',ownerDocument.defaultView)}} b={{set('_rootDataHost',ownerDocument.defaultView)}}> </div></template> ● In-browser XSS filters - DOM XSS out of scope
  • 8. ● Stop tracking a string, leverage the type system ● https://github.com/google/safe-html-types/blob/master/doc/safehtml-typ es.md ● Wrappers for strings, representing values known to be safe to use in various HTML contexts and with various DOM APIs: ○ SafeHTML (<b>I’m safe</b>) ○ SafeURL (https://click.me) ○ TrustedResourceURL (https://i.am.a/script.js) ○ … Safe HTML Types
  • 9. ● Producing the typed value is safe by construction goog.html.SafeHtml.create(“DIV”, {“benign”: “attributes”}, “text”); ● ... or sanitization (integrate with your sanitizers, templating systems, …) goog.html.SafeUrl.sanitize(untrustedUrl); ● or gets reviewed manually goog.html.uncheckedconversions.safeUrlFromStringKnownToSatisfyTypeContract( “url comes from the server response”, url); Producing Safe HTML types
  • 10. Consuming Safe HTML types ● A typed object is propagated throughout the application code ● Taint tracking not necessary ● Wrappers over DOM XSS sinks that accept only typed values goog.dom.safe.setLocationHref(locationObj, safeURL) ● Compiler prohibits the use of native sinks let foo = “bar”; location.href = foo Compile error!
  • 11. ● DOM is secure by default ● Only the code producing a safe type can introduce XSS ● Reduce the security-relevant code by orders of magnitude ○ Stable components (sanitizers, templating libs) ○ Custom application code producing the types ○ Scales extremely well (<1 headcount for all of Google) ● Very successful at preventing XSS ● … as understood by the compiler Safe HTML Types advantages
  • 12. Safe HTML Types limitations ● Reliance on compilation ○ Not all code is compiled ○ Different compilation units ○ Cross-language boundaries ● Compiler limitations ○ JS type system is unsound ○ Reflection, dynamic code ○ Missing type information ○ False positive/false negative tradeoff ● No protection at runtime
  • 14. Trusted Types Safe HTML types built into the platform
  • 15. Trusted Types 1. API to create string-wrapping objects of a few types: a. TrustedHTML (.innerHTML) b. TrustedURL (a.href) c. TrustedScriptURL (script.src) d. TrustedScript (el.onclick) TrustedURL<"//foo">.toString() == "//foo" 2. Opt-in enforcement: Make DOM XSS sinks accept only the typed objects
  • 16. Trusted Types Without enforcement: ● Use types in place of strings with no breakage ● Backwards compatible (use the light polyfill defining the types) With enforcement: ● DOM XSS attack surface reduction - minimizing the trusted codebase ● Only the code producing the types can introduce DOM XSS ● Design facilitates limiting the “DOM XSS capability” via policies
  • 17. const myPolicy = TrustedTypes.createPolicy('my-policy', { createHTML(html) { return mySanitizer(html) }, createScriptURL(url) { const u = new URL(url, document.baseURI) if (u.origin === window.origin) return u.href; throw new TypeError('Invalid URL!') } }) Trusted Types - policies Name Rules Sanitize HTML Only same origin scripts Policy
  • 18. Trusted Types - creating & using types > document.body.innerHTML = myPolicy.createHTML(location.hash); Running mySanitizer… > document.body.innerHTML = location.hash TypeError: HTMLBodyElement.innerHTML requires TrustedHTML assignment (dispatch a securitypolicyviolation event?)
  • 19. (function() { // Seemingly unsafe policy const unsafePolicy = TrustedTypes.createPolicy('unsafefoo', { createHTML: (s) => s, }); // No XSS because of the usage limitation return fetch('/get-html')....then( (response) => unsafePolicy.createHTML(response) ); })(); Trusted Types - guarding policy usage
  • 20. ● Only the code calling an insecure policy can cause DOM XSS ● Policy reference similar to a CSP script nonce ● Rest of codebase is “DOM XSS neutral” ● Enables gradual adoption with immediate security benefits ● Example blogging application - DOM XSS can only be caused by a Markdown renderer. Module Unsafe policy Secure policy Module Module Module Module Trusted Types - guarding policy usage
  • 21. Enforcement & guarding policy creation An X-Bikeshed-Later* response header with a list of allowed policy names: Content-Security-Policy: trusted-types foo bar TrustedTypes.createPolicy('foo', ...) // OK TrustedTypes.createPolicy('bar', ...) // OK TrustedTypes.createPolicy('baz', ...) // Policy disallowed Content-Security-Policy: trusted-types * * For now, Content-Security-Policy
  • 22. ● Trusted objects can be created via policies ● A policy defines application-specific rules to create types ● Multiple policies can coexist ○ A strict HTML sanitizer for the comment editing section ○ A custom one for application templating system ● Limit policy creation ○ Response header value ● Limit policy usage ○ Guard the reference ○ Example: HTML sanitizers need a no-op policy to use internally only Policies
  • 23. Implementations: ● Chrome - http://crbug/739170, http://w3c-test.org/trusted-types/ google-chrome-unstable --enable-blink-features=TrustedDOMTypes --enable-experimental-web-platform-features ● Polyfill - https://github.com/WICG/trusted-types ○ https://wicg.github.io/trusted-types/demo/ ● Tinyfill - TrustedTypes={createPolicy:(n, rules) => rules} Trusted Types status
  • 24. Integration trials ● JS libraries and frameworks: DOM interpolation, templating ○ Angular, Polymer + https://github.com/Polymer/polymer-resin ○ Pug - https://github.com/mikesamuel/pug-plugin-trusted-types ● External examples: ○ Sanitizers: http://koto.github.io/DOMPurify/demos/trusted-types-demo.html ○ Angular app: gothinkster/angular-realworld-example-app - 44 lines ugly patch ○ React app gothinkster/react-redux-realworld-example-app - trivial patch ● Internally - adopting Trusted Types at Google applications Trusted Types status
  • 25. ● Makes DOM XSS easy to detect & difficult to introduce ○ Based on a solution with proven track record (most core Google applications use it) ○ Promotes containing security-relevant code ○ Power to the authors (custom rules, multiple policies) ○ Control to the security teams (policy review, header control) ● Backwards-compatible, polyfillable ● Easy to implement in UAs (1Q 2*intern project at Google) ● Extensible: more types, browser-provided policies, userland libraries Summary