<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Mike West</title>
    <link rel="alternate"   type="text/html"            href="https://mikewest.org/" />
    <link rel="self"        type="application/atom+xml" href="http://feeds.mikewest.org/mikewest/" />
    <id>https://mikewest.org/</id>
    <author>
        <name>Mike West</name>
        <uri>https://mikewest.org/</uri>
        <email>mike@mikewest.org</email>
    </author>

    
    <updated>2013-09-24T00:00:00+02:00</updated>
    
    <entry>
        <title type='text'>XSS (No, the _other_ 'S') - CSSConf EU 2013</title>
        <link rel="alternate" href="https://mikewest.org/2013/09/xss-no-the-other-s-cssconfeu-2013" />
        <id>https://mikewest.org/2013/09/xss-no-the-other-s-cssconfeu-2013</id>
        <updated>2013-09-24T00:00:00+02:00</updated>
        <published>2013-09-24T00:00:00+02:00</published>
        <content type='html'>&lt;p&gt;I had the distinct pleasure of talking with folks at this year&amp;rsquo;s
&lt;a href=&quot;http://2013.cssconf.eu/&quot;&gt;CSSConf EU&lt;/a&gt; about the dangers of content-injection attacks. They&amp;rsquo;re
not just for JavaScripters, you see: CSS is dangerous too! They&amp;rsquo;ve just posted
the video, and I think it&amp;rsquo;s worth a little under a half-hour of your time to
skim through. You&amp;rsquo;ll be shocked to learn that &lt;a href=&quot;https://mkw.st/r/csp&quot;&gt;Content Security Policy&lt;/a&gt;
makes an appearance.&lt;/p&gt;

&lt;p&gt;Credit is due to &lt;a href=&quot;https://cure53.de/&quot;&gt;Mario Heiderich&lt;/a&gt;, et al. for their excellent paper
&lt;a href=&quot;http://www.nds.rub.de/media/emma/veroeffentlichungen/2012/08/16/scriptlessAttacks-ccs2012.pdf&quot;&gt;&amp;ldquo;Scriptless Attacks - Stealing the Pie Without Touching the Sill&amp;rdquo;&lt;/a&gt;,
from which I stole much of the attack-based content. Awesome stuff.&lt;/p&gt;

&lt;p&gt;Transcript is coming, but for now, please do enjoy the embedded video and
slides below:&lt;/p&gt;

&lt;h2 id=&quot;video&quot;&gt;Video&lt;/h2&gt;

&lt;iframe width=&quot;606&quot; height=&quot;455&quot; src=&quot;https://www.youtube.com/embed/eb3suf4REyI?rel=0&quot; frameborder=&quot;0&quot; title=&quot;Video: XSS (No, the _other_ 'S') - CSSConf EU 2013&quot; allowfullscreen=&quot;allowfullscreen&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;The video is 29m long, and &lt;a href=&quot;https://www.youtube.com/watch?v=eb3suf4REyI&quot;&gt;up on YouTube for your viewing
enjoyment&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;slides&quot;&gt;Slides&lt;/h2&gt;

&lt;iframe src=&quot;https://speakerdeck.com/player/c67a4f30f3a5013025764a2e0c7b14d8&quot; allowfullscreen=&quot;true&quot; mozallowfullscreen=&quot;true&quot; webkitallowfullscreen=&quot;true&quot; frameborder=&quot;0&quot; title=&quot;Video: XSS (No, the _other_ 'S') - CSSConf EU 2013&quot; width=&quot;606&quot; height=&quot;516&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;The &lt;a href=&quot;https://speakerdeck.com/mikewest&quot;&gt;slides are up on Speaker Deck&lt;/a&gt; (which is awesome), and I actually
used Speaker Deck to &lt;em&gt;present&lt;/em&gt; the slides from someone else&amp;rsquo;s laptop since my
computer decided not to connect to the conference&amp;rsquo;s projector. I love you,
Speaker Deck!&lt;/p&gt;

&lt;h2 id=&quot;transcript&quot;&gt;Transcript&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Coming soon!&lt;/strong&gt;&lt;/p&gt;

</content>
    </entry>

    
    <entry>
        <title type='text'>Frontend Security - Frontend Conference, Zürich 2013</title>
        <link rel="alternate" href="https://mikewest.org/2013/09/frontend-security-frontendconf-2013" />
        <id>https://mikewest.org/2013/09/frontend-security-frontendconf-2013</id>
        <updated>2013-09-09T00:00:00+02:00</updated>
        <published>2013-09-09T00:00:00+02:00</published>
        <content type='html'>&lt;p&gt;Last week, I was in Zürich attending &lt;a href=&quot;http://2013.frontendconf.ch/&quot;&gt;Frontend Conference&lt;/a&gt; (talks and
slides linked up &lt;a href=&quot;http://lanyrd.com/2013/fec13/&quot;&gt;on Lanyrd&lt;/a&gt;), and had the opportunity to chat with
the folks there about client-side security. &lt;a href=&quot;https://mkw.st/r/csp&quot;&gt;Content Security Policy&lt;/a&gt;,
shockingly, was central to the discussion.&lt;/p&gt;

&lt;p&gt;In the interests of making the presentation as accessible (and indexable) as
possible, a full transcript of the presentation is below, along with an embed of
the video and slides.&lt;/p&gt;

&lt;h2 id=&quot;video&quot;&gt;Video&lt;/h2&gt;

&lt;iframe width=&quot;606&quot; height=&quot;455&quot; src=&quot;https://www.youtube.com/embed/fYjO5pIY1mY?rel=0&quot; frameborder=&quot;0&quot; title=&quot;Video: 'Frontend Security' - Frontend Conf, Zürich 2013&quot; allowfullscreen=&quot;allowfullscreen&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;The video is 48m long, fully captioned, and &lt;a href=&quot;https://www.youtube.com/watch?v=fYjO5pIY1mY&quot;&gt;up on YouTube for your viewing
enjoyment&lt;/a&gt; (I swiped the &lt;a href=&quot;http://www.ustream.tv/recorded/38005119&quot;&gt;original conference feed from UStream&lt;/a&gt;
(with permission, thanks!)).&lt;/p&gt;

&lt;h2 id=&quot;slides&quot;&gt;Slides&lt;/h2&gt;

&lt;iframe src=&quot;https://speakerdeck.com/player/c67a4f30f3a5013025764a2e0c7b14d8&quot; allowfullscreen=&quot;true&quot; mozallowfullscreen=&quot;true&quot; webkitallowfullscreen=&quot;true&quot; frameborder=&quot;0&quot; title=&quot;Slides: 'Frontend Security' - Frontend Conf, Zürich 2013&quot; width=&quot;606&quot; height=&quot;516&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;The &lt;a href=&quot;https://speakerdeck.com/mikewest/frontend-security-frontend-conf-zurich-2013-08-30&quot;&gt;slides are up on Speaker Deck&lt;/a&gt; (which is awesome), and I actually
used Speaker Deck to &lt;em&gt;present&lt;/em&gt; the slides from someone else&amp;rsquo;s laptop since my
computer decided not to connect to the conference&amp;rsquo;s projector. I love you,
Speaker Deck!&lt;/p&gt;

&lt;h2 id=&quot;transcript&quot;&gt;Transcript&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; Thank you very much.  Before I get started, I&amp;rsquo;d like to say thanks to
&lt;a href=&quot;http://2013.frontendconf.ch/&quot;&gt;Frontend Conf&lt;/a&gt; because this is the first conference I&amp;rsquo;ve ever been at
where the &amp;ndash; where everything was online less than a day after the speeches.
In fact, speeches from this morning are already online.  I think it&amp;rsquo;s absolutely
incredible.  Can you give the guys up there a round of applause?  Because
that&amp;rsquo;s&amp;hellip; &lt;/p&gt;

&lt;p&gt;[applause]&lt;/p&gt;

&lt;p&gt;Blows me away.&lt;/p&gt;

&lt;p&gt;So my name is Mike West.  I work at Google on Chrome.  I do some stuff in Blink.
I do some stuff in Chrome.  If you have any questions about that, I&amp;rsquo;m happy to
answer them. What I&amp;rsquo;ve been doing recently has had a lot to do with security.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;m going to talk about a couple of things today that I find really important.
The slides are at &lt;a href=&quot;https://speakerdeck.com/mikewest/frontend-security-frontend-conf-zurich-2013-08-30&quot;&gt;this URL&lt;/a&gt;, I&amp;rsquo;m actually using them right now
because my computer decided that it didn&amp;rsquo;t want to hook up to the network.  So
you can follow along with me on SlideShare.  Sorry, on Speaker Deck.  I stopped
using SlideShare for good reasons, and I will tell you about them later.  I&amp;rsquo;m on
&lt;a href=&quot;https://twitter.com/mikewest&quot;&gt;Twitter&lt;/a&gt;.  I&amp;rsquo;m on &lt;a href=&quot;https://google.com/+MikeWest&quot;&gt;Google+&lt;/a&gt;.  You can find &lt;a href=&quot;https://mikewest.org/&quot;&gt;my website&lt;/a&gt; that I
update maybe once to twice a year.  It&amp;rsquo;s very exciting, very good stuff indeed.&lt;/p&gt;

&lt;p&gt;So my brain is absolutely full.  I&amp;rsquo;ve been to a lot of talks over the last two
days.  This is the last talk on the last day.  I think if I tried to stuff
anything else in my head, it would explode.  I suspect that many of you are
feeling the same way. So I want to give you the one thing that I want you to
remember right now, up front, before you forget everything that I&amp;rsquo;m going to
say.&lt;/p&gt;

&lt;p&gt;This is &lt;a href=&quot;https://mkw.st/r/csp&quot;&gt;an article talking about Content Security Policy&lt;/a&gt;.  What is
Content Security Policy?  Why should I care?  I&amp;rsquo;ll tell you in a minute.  But
don&amp;rsquo;t worry about that right now.  Open the article, put it somewhere, find it
later.  It&amp;rsquo;s something that I really think you should read.  It&amp;rsquo;s something
that&amp;rsquo;s well worth your time and it&amp;rsquo;s written by a very handsome man.  So I
think it&amp;rsquo;s really something that would be worth your time to play around with.
It&amp;rsquo;s on HTML5Rocks, by the way. Does anyone know HTML5Rocks?  Does anyone not
know html5rocks.com?  Excellent. That&amp;rsquo;s very good.  They&amp;rsquo;re very smart people
on my team that write lots of good articles for the site.  I really think that
if you don&amp;rsquo;t know about it and many if you do, it&amp;rsquo;s well worth your time to take
a look at.&lt;/p&gt;

&lt;p&gt;So how many of you have seen a page that looks like this, in either Chrome or
any other browser?  That&amp;rsquo;s not enough of you.  You people are browsing really
boring websites.  You need to go into a &amp;ndash; just completely different corner
of the web.  You&amp;rsquo;re not going to see this from cnn.com, right?  You&amp;rsquo;ve got to
really look for it.  This is a malware alert brought to you by the magic of
&lt;a href=&quot;https://developers.google.com/safe-browsing/&quot;&gt;SafeBrowsing&lt;/a&gt;.  SafeBrowsing is a service that Google has put together
that&amp;rsquo;s used by Chrome, used by Firefox, and a variety of other services.  It
gives us the ability to relatively rapidly show users that they could be doing
something dangerous, that we compare a list of hashes to the website that
they&amp;rsquo;re about to visit.  If there&amp;rsquo;s a match then we can inform the user that
they might not want to visit the site.  The site is something that we&amp;rsquo;ve
identified as being persistently malicious.  That is every time users go to the
site, people try to load malware onto their computers or try to direct into
phishing sites, or things along these lines.  It&amp;rsquo;s persistent.  Meaning that
for every user, they&amp;rsquo;re seeing this sort of behavior.&lt;/p&gt;

&lt;p&gt;And then we&amp;rsquo;ve gotten really good at detecting these sorts of behaviors.  We&amp;rsquo;ve
gotten really good at detecting the websites that are always going to do you
harm.  What we&amp;rsquo;re not so good at is detecting the more transient attacks.
Detecting attacks like content injection that only affect a single request or a
single subset of users, or perhaps only users that are logged in to a particular
site, only a particular user.  We&amp;rsquo;re not that great in detecting it because
we &amp;ndash; when we crawl the web, we don&amp;rsquo;t see these sites, because this site are
usually distributed via e-mail or via Twitter or via a wide variety of other
mechanisms by which people try to trick you into clicking on links that will do
you harm.&lt;/p&gt;

&lt;p&gt;I mentioned &amp;ndash; I mentioned content injection.  Content injection is a
broad term that &amp;ndash; of which XSS is a specific variant.  XSS means cross-site
scripting. And generally speaking, this means that an attacker is able to trick
a server into sending code that it didn&amp;rsquo;t mean to.  That is, instead of only
delivering the JavaScript that actually makes up your application.  Your server
is tricked into also delivering some sort of malicious code, code that does harm
to a user or exfiltrates their data without them even knowing about it which is
actually even worse.&lt;/p&gt;

&lt;p&gt;Why is XSS problematic?  Generally speaking, XSS is one of the most prevalent
problems on the web.  Almost every website will have an XSS flaw of one sort
or another at one time or another, even Google.  Given that, why is it
dangerous?  What can it actually do?  What can a &amp;ndash; an attacker do when
they can execute code in the context of your website?&lt;/p&gt;

&lt;p&gt;To understand why it&amp;rsquo;s important, you have to understand the concept of an
&lt;a href=&quot;http://tools.ietf.org/html/draft-abarth-origin&quot;&gt;origin&lt;/a&gt;.  An origin is a pairing of a scheme, a host, and a port.  That is
&lt;code&gt;http&lt;/code&gt;, &lt;code&gt;example.com&lt;/code&gt;, &lt;code&gt;80&lt;/code&gt;. or &lt;code&gt;https&lt;/code&gt;, &lt;code&gt;google.com&lt;/code&gt;, &lt;code&gt;443&lt;/code&gt;.  Those are
distinct origins.  And because they&amp;rsquo;re distinct origins, they should and
must not have accessed to each others data. &lt;code&gt;example.com&lt;/code&gt; must never have
access to &lt;code&gt;google.com&lt;/code&gt;&amp;rsquo;s data.  And the browser can actually do a relatively
good job of enforcing this sort of restrictions.&lt;/p&gt;

&lt;p&gt;There&amp;rsquo;s a policy known as the Same-Origin Policy which basically means that
everything within the context of your origin has access to all of the data for
that origin.  It can access cookies, it can access &lt;code&gt;localStorage&lt;/code&gt;,
&lt;code&gt;sessionStorage&lt;/code&gt;, you name it.  Anything you are storing locally using any of
the wide variety of HTML5 mechanisms that are out there is accessible to any
and all code that runs within the context of your origin.  In other words, the
origin boundary is the only boundary that the browser can very effectively
enforce.&lt;/p&gt;

&lt;p&gt;It is however the case that we generally includes script from all over the place
into our origins.  The browser allows this.  The browser really likes
JavaScript.  And basically any JavaScript it sees, it&amp;rsquo;s going to execute. It
just loves JavaScript.  So every time it gets a chance to execute anything, it
executes, which is problematic, right?&lt;/p&gt;

&lt;p&gt;What&amp;rsquo;s the difference between these two &lt;code&gt;script&lt;/code&gt; tags?&lt;/p&gt;

&lt;p&gt;Exactly right.  There is no difference whatsoever.  If both of these &lt;code&gt;script&lt;/code&gt;
tags are included on a page, the browser is going to go, &amp;ldquo;Yay, JavaScript.&amp;rdquo;,
grab them both, execute them as fast as it possibly can because Chrome&amp;rsquo;s all
about speed and bad things are going to happen, right?  Now, visually we can
inspect these two scripts.  We can say the first one is awesome, the second
one not so much.  Perhaps, I want to execute the first one that was actually
part of my application.  The second one, I have no idea how it got to my page,
I didn&amp;rsquo;t write that.&lt;/p&gt;

&lt;p&gt;Well, it might&amp;rsquo;ve gotten on your page like this, right?  If you&amp;rsquo;re using PHP
or any other wide variety of other templating languages and you don&amp;rsquo;t properly
escape output, if you just say &amp;ldquo;Hello {$name}!&amp;rdquo;, and then accept whatever name,
the user gives you as their name then you&amp;rsquo;re in trouble, right?  Because the &amp;ndash;
if the user gives you a name of &lt;code&gt;&amp;lt;script&amp;gt;beEvil()&amp;lt;/script&amp;gt;&lt;/code&gt; and you just
blindly write that out, then you&amp;rsquo;re doing yourself of disservice.&lt;/p&gt;

&lt;p&gt;This is how a lot of cross-scripting attacks happen.  There are a lot of
variants on this, so it&amp;rsquo;s not always the case that it&amp;rsquo;s just coming from a GET
parameter or a POST parameter.  Things can be stored locally, things can be
reflected from various pieces of the DOM.  So attackers are really, really
clever about finding holes in your site and exploiting them.  How many people
have dedicated members of their team working on security?  That&amp;rsquo;s kind of what I
suspected.&lt;/p&gt;

&lt;p&gt;I guarantee you that if you had any sort of high value data on your website or
even medium value, even low value data on your website, there are people that
are much more interested in getting access to that data then you are in
protecting it.  Because generally speaking, your team&amp;rsquo;s responsibility is to
build amazing new features and to build amazing new experiences for your users.
It&amp;rsquo;s kind of assumed that you&amp;rsquo;re doing security work.  And the security work is
not really ever part of your goals for a quarter.  Your goal for the quarter is
yo build this amazing new page.  It&amp;rsquo;s not to make sure the other pages didn&amp;rsquo;t
break in the meantime.  That should probably change, but we&amp;rsquo;ll talk about how we
can mitigate the effects.&lt;/p&gt;

&lt;p&gt;Happily, this is a absolutely trivial problem to solve. All you have to do is
perfectly escape every piece of output that you put on your site. Every piece.
Pieces that come from you and pieces that come from users.&lt;/p&gt;

&lt;p&gt;You also have to perfectly escape it for the context in which this output will
find itself.  Here&amp;rsquo;s a relatively an exhaustive list of different context in an
HTML page, you have a color exported into a &lt;code&gt;style&lt;/code&gt; tag, you have a name
directly in a paragraph tag, you have a URL that&amp;rsquo;s put directly into an
attribute of an HTML element, you have an ID that&amp;rsquo;s put directly into script,
and you have some debug information that&amp;rsquo;s put into a comment.&lt;/p&gt;

&lt;p&gt;The rules for each of these contexts are different.  For example, inside of a
comment, two dashes will close the comment and everything else will be rendered.
Two dashes of course have no effect whatsoever inside a paragraph tag, but if
you open a script tag inside of paragraph tag then you&amp;rsquo;re in trouble.  So you
need to understand the rules for each of these contexts and you need to
perfectly escape all information that you export into this contexts.&lt;/p&gt;

&lt;p&gt;It is, honestly, trivial.&lt;/p&gt;

&lt;p&gt;However, we are really bad at trivial things, apparently, if you look at the
history of the web.&lt;/p&gt;

&lt;p&gt;Has anyone heard of OWASP?  O-W-A-S-P?  Excellent.  OWASP is an interesting
organization that does a lot of security research and lots of security
trainings.  They have &amp;ndash; as an example of the kinds of cleverness that
people can come up with for exploiting things in websites, this is an XSS
filter evasion cheat sheet]&lt;a href=&quot;https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet&quot;&gt;owaspxss&lt;/a&gt;.  It&amp;rsquo;s a little bit old, it&amp;rsquo;s not really
new, it hasn&amp;rsquo;t really been updated since like, I don&amp;rsquo;t know, 2012 or so, 2011.
But there&amp;rsquo;s a lot of really interesting things in here that might make you think
again about the mechanisms by which you are filtering data that&amp;rsquo;s going out to
your websites.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Long_UTF-8_Unicode_encoding_without_semicolons&quot;&gt;Long UTF-8 encode without semicolons&lt;/a&gt;.  Did you know that you can
have UTF-8 entities put in to your site without semicolons?  So if you&amp;rsquo;re
checking for ampersand, semicolon then you&amp;rsquo;re kind of screwed because you don&amp;rsquo;t
need those semicolons.  Ha ha, hurray for HTML.&lt;/p&gt;

&lt;p&gt;Has anyone heard of &lt;a href=&quot;http://www.jsfuck.com/&quot;&gt;JSFuck&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; I have.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; JSFuck is amazing.  It proves that you can write any line of JavaScript
using only six characters.  Open brace, close brace, open parenthesis, close
parenthesis, plus and bang.  Do your filters check for any of these characters?
They all seem relatively benign, right?  But if you put these into an attribute,
you&amp;rsquo;re kind of screwed.&lt;/p&gt;

&lt;p&gt;Does anyone know what this code does by the way?  Can you guess?  You can all
read this.  I mean, it&amp;rsquo;s just JavaScript, right?  This is &lt;code&gt;alert(1)&lt;/code&gt;.  Usually
you will do &amp;ndash; usually you will do &lt;code&gt;alert('XSS')&lt;/code&gt; when you&amp;rsquo;re doing a pentest
or something but &lt;code&gt;alert('XSS')&lt;/code&gt; is about 6,000 characters long, so I
didn&amp;rsquo;t paste it.  JSFuck is quite verbose.&lt;/p&gt;

&lt;p&gt;Alex Russell puts this beautifully when he says, &amp;ldquo;I discount the probability of
perfection.&amp;rdquo;  It&amp;rsquo;s really difficult to be perfect.&lt;/p&gt;

&lt;p&gt;I would phrase it slightly differently: &amp;ldquo;We are all idiots with deadlines.&amp;rdquo;
We do the things that we think are important in the moment and it&amp;rsquo;s very easy
to forget about things, these overarching things that are a critical
foundation of the work that we should be doing.  And it&amp;rsquo;s very easy to make
small mistakes.  And unfortunately, small mistakes are really all that it takes.&lt;/p&gt;

&lt;p&gt;So what I want to talk about today is what we can do inside of a browser to
mitigate the effects of our idiocy because generally speaking, there are going
to be holes in the websites that you create.  It&amp;rsquo;s almost unavoidable.  It&amp;rsquo;s a
question of &amp;ndash; it&amp;rsquo;s a question of &amp;ldquo;when&amp;rdquo; not &amp;ldquo;if&amp;rdquo; there&amp;rsquo;s going to be a hole in
your sites and &amp;ldquo;when&amp;rdquo; not &amp;ldquo;if&amp;rdquo; that hole is going to be exploited.  It will be
really nice if there was some sort of &amp;ndash; I don&amp;rsquo;t know a &lt;em&gt;policy&lt;/em&gt; of some sort
that we could give to the browser that, I don&amp;rsquo;t know will have an effect on the
&lt;em&gt;security&lt;/em&gt; of our &lt;em&gt;content&lt;/em&gt;.  I don&amp;rsquo;t know.  We&amp;rsquo;ll back come back to that idea.&lt;/p&gt;

&lt;p&gt;Does anyone what &lt;a href=&quot;http://traumwerk.stanford.edu/philolog/2009/10/homers_odyssey_in_art_sirens_f.html&quot;&gt;this painting&lt;/a&gt; is?  This painting is &lt;a href=&quot;http://en.wikipedia.org/wiki/Odysseus&quot;&gt;Odysseus&lt;/a&gt;
and the &lt;a href=&quot;http://en.wikipedia.org/wiki/Siren&quot;&gt;Sirens&lt;/a&gt;.  It&amp;rsquo;s a really good story.  It goes something like
this. Odysseus is &amp;ndash; Odysseus is an amazing man.  And by that, I mean, that he
is an egomaniacal maniac and bastard.  This story goes something like this:
Sirens, they sing beautifully.  So, beautifully in fact, that they drive you to
the brink of madness, sailors in particular, they really like sailors for some
reason, who knows why.   Sailors are driven to the point that they &amp;ndash; all they
want to do is be near this music to hear more of the music, so they end up
throwing themselves overboard whenever they, you know, sail around the island
where these sirens find themselves.  The ship then crashes on the island then
these sirens I guess eat people, who knows.&lt;/p&gt;

&lt;p&gt;Regardless, Odysseus decides, because he is an amazing man, that he wants to be
the only living person to have heard the song of the sirens and survived.  So,
what does he do?  Well, he tells his men to tie him to the mast.  So, they bind
him quite tightly, his hands behind his back, his legs are tied to the mast.  He
can&amp;rsquo;t go anywhere.  But he can hear the music.  He simply prevented from doing
things that would be stupid, you know, acknowledging the fact that the entire
endeavor is stupid.  He then, instructs his men to put beeswax in their ears and
they, you know, wrapped things around their head, you know, primitive sorts of
earmuffs so that they can&amp;rsquo;t hear the music of the sirens.  And he gives them
explicit instruction.  You know, &amp;ldquo;row next to this island&amp;rdquo;, &amp;ldquo;don&amp;rsquo;t go to the
island&amp;rdquo;, &amp;ldquo;don&amp;rsquo;t jump out of the boat&amp;rdquo;, and &amp;ldquo;just keep rowing&amp;rdquo;, right?   The
sirens come, they sing their beautiful songs.  He&amp;rsquo;s driven to the brink of
madness but he&amp;rsquo;s able to continue on his path because he&amp;rsquo;s given these
instructions and then he&amp;rsquo;s prevented his men from acting on these distractions.&lt;/p&gt;

&lt;p&gt;It&amp;rsquo;d be really great if we could do something like this with the browser.
Where we could tell the browser, &amp;ldquo;Hey, this piece of code is what you want to be
executing.&amp;rdquo;  These distractions, all this other beautiful JavaScript that&amp;rsquo;s out
here that youreally, really want to go execute and look at it, but please do not
touch, right?  It would be nice if your application could ask the browser to tie
its hands behind its back and prevent it from doing things that it knows are
going to be bad idea.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://mkw.st/r/csp&quot;&gt;Content Security Policy&lt;/a&gt; is this thing.  It is gorgeous.  It will give you
errors like this when people try to inject code into your sites. &lt;code&gt;Refused to
execute inline script because it violates the Content Security Policy
directive: &quot;script-src 'self'&quot;&lt;/code&gt;.  We&amp;rsquo;ll talk about this in a little bit more
detail.  But the core idea I hope is clear.  Content Security Policy gives you a
mechanism by which you can whitelist certain origins of content and allow only
those origins to execute within the content &amp;ndash; within the context of your
origin. That is, if I want to include &lt;a href=&quot;http://www.google.com/fonts&quot;&gt;Google Web Fonts&lt;/a&gt; I can only
whitelist the origin from which this font should come.  I get script from that
origin, I get fonts from that origin, but I shouldn&amp;rsquo;t get them from anywhere
else in the web.  This is really quite powerful.&lt;/p&gt;

&lt;p&gt;The specification is &lt;a href=&quot;https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html&quot;&gt;here&lt;/a&gt;.  Content Security Policy
1.1 is currently in draft.  Content Security Policy 1.0 is a candidate
recommendation.  It&amp;rsquo;s currently implemented in Chrome.  It&amp;rsquo;s implemented in
Firefox 23 which just came out as an unprefix header.  We&amp;rsquo;ll talk about that in
a little bit.&lt;/p&gt;

&lt;p&gt;I edit the spec along with &lt;a href=&quot;http://www.adambarth.com/&quot;&gt;Adam Barth&lt;/a&gt; and &lt;a href=&quot;https://twitter.com/dveditz&quot;&gt;Dan Veditz&lt;/a&gt; from
Mozilla.  They are much smarter than I am, so I just kind of sit there and type
whatever they say.  It&amp;rsquo;s great.&lt;/p&gt;

&lt;p&gt;So, what could a Content Security Policy look like?  Content Security Policy is
delivered as an HTTP header.  This is the &amp;ndash; this is the policy that&amp;rsquo;s being
used on an incredibly high value website &lt;code&gt;mikewest.org&lt;/code&gt;.  Yeah.  Content
Security Policy is the name of the header, right. So, you send
&lt;code&gt;Content-Security-Policy&lt;/code&gt; and then the value is a semicolon-delimited list of
directives.  Each of these directives controls a specific type of content.&lt;/p&gt;

&lt;p&gt;Here, I&amp;rsquo;ve set the default of &lt;code&gt;'none'&lt;/code&gt;, in other words, nothing should
be allowed on my site.  Then, I slowly open that up and start saying, &amp;ldquo;Okay.
Well, okay.  Nothing except style from my CDN.  Okay.  Nothing except style and
frames from these two places.&amp;rdquo; and so on.&lt;/p&gt;

&lt;p&gt;And you see here that I&amp;rsquo;ve whitelisted &lt;a href=&quot;https://www.speakerdeck.com&quot;&gt;https://www.speakerdeck.com&lt;/a&gt;.  I did
that because Speaker Deck, being awesome, serves things over HTTPS whereas
other services do not and have no intention of doing so.  This is problematic
especially if you&amp;rsquo;re on a HTTPS site because Chrome and Firefox has started
actually blocking HTTP content within the context of an HTTPS site.  So, it&amp;rsquo;s
really good if you run a service of any sort and you expect people to embed
things on the web, serve it over SSL.  If you don&amp;rsquo;t serve it over SSL, slowly
but surely your options are going to be limited with regards to where that
content can be embedded.  All right.&lt;/p&gt;

&lt;p&gt;So, script &amp;ndash; sorry &amp;ndash; style, frames, script images, fonts, and so on.  This is
an exhaustive list of the directives that exist in
&lt;a href=&quot;http://w3.org/TR/CSP&quot;&gt;Content Security Policy 1.0&lt;/a&gt; which is currently available in Chrome.
There are couple of additional directives behind a flag in Chrome.  So, if you
go in to Chrome flags and then enable &amp;ldquo;Experimental Web Platform features&amp;rdquo;
(&amp;lt;chrome://flags/#enable-experimental-web-platform-features&amp;gt;), then you&amp;rsquo;ll be
able to start playing around with the 1.1 stuff immediately.&lt;/p&gt;

&lt;p&gt;And I&amp;rsquo;ll talk about a little bit about what&amp;rsquo;s new in 1.1 later because they are
like two important things and then a bunch of other stuff that&amp;rsquo;s gotten through
for one reason or another.  What&amp;rsquo;s interesting here is the last item, a report
URL or URI.  Yeah, URI.  What this does is actually gives you insight into
whether or not you&amp;rsquo;re being attacked.&lt;/p&gt;

&lt;p&gt;You can run Content Security Policy in such a way that every time there&amp;rsquo;s a
violation, every time a resource is loaded that &amp;ndash; I&amp;rsquo;m sorry &amp;ndash; an attempt to
load a resource has made that goes &amp;ndash; that violates your policy, you&amp;rsquo;ll get a
POST message from the browser.  The browser will say, &amp;ldquo;Hey, I tried to load this
thing and I blocked it.  It was on this page.  It had this URL, maybe you should
take a look at that,&amp;rdquo; which is really quite useful if you&amp;rsquo;re auditing websites.&lt;/p&gt;

&lt;p&gt;What&amp;rsquo;s nice here is that you can actually run kind of Content Security Policy in
a &amp;ldquo;Report Only&amp;rdquo; mode.  That is it won&amp;rsquo;t actually block any content on your site.
What it will do instead is simply send these POST messages out to your web
server so that you can start cleaning up your site before you actually deploy a
Content Security Policy.  What&amp;rsquo;s really nice is that you can actually run both
a Report Only mode and an Enforce Mode policy at the same time.  So, you can
have a really loose enforce policy that says &lt;code&gt;https:&lt;/code&gt; only.  So I should load
everything over HTTPS and if I don&amp;rsquo;t, then start telling me about that, so
that I can find these places on my site that need to be cleaned up.  Then you
can also have a Report Only mode that&amp;rsquo;s more restrictive where you start saying
only this origin, only that origin, no inline script, and so on.  This gives you
a nice mechanism by which you can start rolling this out.  You start getting
information about how your site&amp;rsquo;s actually behaving in the wild and it gives
you a good opportunity to start cleaning up these areas that need work.&lt;/p&gt;

&lt;p&gt;If any of you have any questions by the way, please ask.  Did you have a
question? Okay.  I&amp;rsquo;m sorry.  Anyway, you see the report information here.
There are variety of attributes.  They do more or less what they say on the
tin. &lt;code&gt;document-uri&lt;/code&gt; is the document what was being attacked.  &lt;code&gt;referrer&lt;/code&gt; is
the link from which the user came and so on.  The interesting bit might be the
source file line number and column number at the end.  If the violation came
from JavaScript we&amp;rsquo;ll do our best to give you some context that you can actually
find it again later on.&lt;/p&gt;

&lt;p&gt;But what do we do about inline script?  What origin would you say that this
comes from?  It&amp;rsquo;s not being loaded via a script tag, right?  It&amp;rsquo;s just
inline in the page.&lt;/p&gt;

&lt;p&gt;Ha-ha, we didn&amp;rsquo;t know either.  So, we invented one, we called it &lt;code&gt;'self'&lt;/code&gt;
&lt;em&gt;(I should have said &lt;code&gt;'unsafe-inline'&lt;/code&gt; here&amp;hellip; Oops!)&lt;/em&gt;. Basically, inline
script is the biggest problem that we saw on the web.  And it&amp;rsquo;s the core reason
the Content Security Policy is valuable.  We can instruct the browser to not to
execute inline script.  This means that even if an attacker can inject script
into your page they can&amp;rsquo;t do anything.  They&amp;rsquo;ve just injected text, it&amp;rsquo;s not
executed which means it&amp;rsquo;s not dangerous.  It does mean however that if you have
inline script in your page that you&amp;rsquo;re using now, you&amp;rsquo;re going to have to do a
little bit of rewriting.  So, code that looks like this, where it defines a
function inline in the page and then has inline &lt;code&gt;onclick&lt;/code&gt; handlers or
&lt;code&gt;javascript:&lt;/code&gt; URLs or something along those lines, we have to be rewritten
something like this.&lt;/p&gt;

&lt;p&gt;So, you externalize the script.  You put it in to an external file, you load it
from that file, and then you do some DOM manipulation in order to add event
listeners.  Quite honestly this is what you should be doing now.  I know there
are good reasons for inline script.  I know there are interesting performance
questions around it.  Generally speaking our approach with Content Security
Policy has been to throw the baby out with the bathwater and then to look in the
water and see if we can pick the baby up.  So, in 1.1 we&amp;rsquo;re going to be digging
around in the water, and I&amp;rsquo;ll show you a little bit of that in a moment.  For
1.0, to get something out the door that was really valuable, we simply say
inline script is banned.&lt;/p&gt;

&lt;p&gt;You can however turn it back on by using the &lt;code&gt;'unsafe-inline'&lt;/code&gt; origin.  We call
it &amp;ldquo;unsafe inline&amp;rdquo; because it&amp;rsquo;s kind of unsafe and we kind of don&amp;rsquo;t want you to
do it.  Regardless, here&amp;rsquo;s &lt;a href=&quot;https://mkw.st/r/csp&quot;&gt;that article again&lt;/a&gt;.  This article gives you
really all of the practical detail that you&amp;rsquo;re going to need in order to do &amp;ndash;
to start implementing this on your own.  I think its well worth your time.  I
really believe the Content Security Policy is one of the most effective
mechanisms to mitigate the risk of cross-site scripting that&amp;rsquo;s come out in the
last several years.  It&amp;rsquo;s not perfect.  There are ways to get around it.
There&amp;rsquo;s an excellent paper called &lt;a href=&quot;http://lcamtuf.coredump.cx/postxss/&quot;&gt;&amp;ldquo;Postcards from the Post-XSS World&amp;rdquo;&lt;/a&gt;
where people have already figuring out how they can attack you after you have
Content Security Policy that bans inline script.  Attackers are really, really
clever but we should make it as hard as possible for them and I think Content
Security Policy is a great way to do that.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s take a quick look at the &lt;a href=&quot;https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html&quot;&gt;1.1 spec&lt;/a&gt; just so I can tell you about
it.  Now I&amp;rsquo;m in full screen mode.  I&amp;rsquo;m sorry.  So, I had everything open on the
other machine and then it decided not to connect.  So, we&amp;rsquo;re going to go and
let&amp;rsquo;s see if I can remember where it is.  Yeah, look at that.  So, Content
Security Policy 1.1.  The interesting bits of Content Security Policy 1.1 are
the inline stuff.  There&amp;rsquo;s also &amp;ndash; there&amp;rsquo;s some discussion around the JavaScript
API that might or might not go anywhere.  But let&amp;rsquo;s look at &amp;ndash; oh, that&amp;rsquo;s right.
It used to be a separate directive and now it&amp;rsquo;s not.  So, we have the ability to
embed nonces as valid sources of script and&amp;hellip; I have no idea where it is.&lt;/p&gt;

&lt;p&gt;I just write this stuff.  I don&amp;rsquo;t know where it actually is.  Give me a break.
How can I be expected to find anything? So, &amp;ldquo;valid nonces&amp;rdquo;, that sounds good.
And it&amp;rsquo;s a Swiss keyboard, this is sweet.&lt;/p&gt;

&lt;p&gt;All right, you&amp;rsquo;ve seen something like this.  Anyway, the idea &amp;ndash; there are two
competing ideas that we kind of don&amp;rsquo;t want to implement both of them but we want
to discuss both of them.  One of them is a nonce which basically a one-time pad.
A server, when it generates a page, should generate a unique idea along with
that page and send it in the header.  It then would embed that ID as a &lt;code&gt;nonce&lt;/code&gt;
attribute on each of the scripts that are enabled.  This means that if the
server does its job and generates a new nonce every time, that an attacker
won&amp;rsquo;t be able to guess it.  So, even if they inject script, it won&amp;rsquo;t have the
&lt;code&gt;nonce&lt;/code&gt; attribute and then won&amp;rsquo;t be executed.  It has the advantage of being
very simple, it has the advantage of being transferable so that if I load a
third-party widget, I can give it the nonce as well and it can then inject code
into my page if I trust it to do that.  And ads do this all the time, so, for
ads, it&amp;rsquo;s kind of an important use-case regardless of whether it&amp;rsquo;s a good
use-case or not.  The other option is a hash where we would basically hash the
inline script.  And take, like, the SHA-1 or SHA-256 hash of the script and
then compare that to something that was in the header so that you could only
inject code that match this hash.  I think both of them have advantages and
disadvantages.  And they&amp;rsquo;re being discussed right now on the
&lt;a href=&quot;http://lists.w3.org/Archives/Public/public-webappsec/&quot;&gt;&lt;code&gt;public-webappsec@&lt;/code&gt;&lt;/a&gt; list.  I&amp;rsquo;ll get there right now.  So,
the &lt;a href=&quot;http://www.w3.org/2011/webappsec/&quot;&gt;Web Application Security Working Group&lt;/a&gt; is the group that is
doing this work.  And from this page, you&amp;rsquo;d be able to find a link to the
discussions that are going on the &amp;ndash; on the mailing list.  If you have opinions
and you can back them with use-cases, I&amp;rsquo;d really suggest that you get involved.
Just join the working group, join the discussion.  We&amp;rsquo;re still kind of in the
formative stages of 1.1 so it&amp;rsquo;s a good time to get involved.&lt;/p&gt;

&lt;p&gt;Well. OK, cool.&lt;/p&gt;

&lt;p&gt;So, that is Content Security Policy. That is the one thing that I want you to
remember from this talk.  I think it&amp;rsquo;s incredibly important, I think it&amp;rsquo;s well
worth your time to play around with. Now, we&amp;rsquo;re going to talk about other stuff
because I have more time.&lt;/p&gt;

&lt;p&gt;Some of the things that I think are important.  SSL is the first and foremost
of these. I think serving your sites over a secure channel is an absolute
prerequisite to any conception of security whatsoever.  If you&amp;rsquo;re serving your
site over HTTP, you have absolutely no guarantee that the bits that leave your
server are the same bits that are getting to the &amp;ndash; to the client and you have
no guarantee that the bits that came from the client are the bits that actually
reached your server.&lt;/p&gt;

&lt;p&gt;We conceive of the internet somehow like this, that I have my laptop, I send
the request directly out to a server.  I get a request or I get a response
directly back from the server.  But when we think about it, we know that that&amp;rsquo;s
not at all how things work.&lt;/p&gt;

&lt;p&gt;Instead, I go to conferences and I join the Wi-Fi network at a conference.  And
then I send all my requests through this Wi-Fi network.  Do you trust &lt;a href=&quot;http://2013.frontendconf.ch/about/&quot;&gt;the
people that run Frontend Conf&lt;/a&gt;? I don&amp;rsquo;t know, they look kinda shady.&lt;/p&gt;

&lt;p&gt;Generally speaking, proxies that sit between you and the servers that you want
to talk to have complete control over every HTTP connection.  There&amp;rsquo;s simply
nothing that you can do to verify anything about the connection whatsoever.
It&amp;rsquo;s unencrypted, sent in the clear, which means that those proxies have a)
the ability to modify the request but also the ability to read the request and
store them and send them to exciting people like the US government.  What I
would suggest is that your conception of the world should look something like
this where there&amp;rsquo;s always something in between you and the server and you
should never trust it.  You should always assume that everything going through
external servers is being tainted in some way.&lt;/p&gt;

&lt;p&gt;You can fix that to an extent by encrypting the data that&amp;rsquo;s being sent.  This
at least guarantees that the information that&amp;rsquo;s leaving your computer can only
&amp;ndash; well, mostly only &amp;ndash; be read by the server that it&amp;rsquo;s going to.  And mostly
only &amp;ndash; and you can mostly only read the responses that are coming back.  SSL
is not perfect.  There are a lot of ways in which SSL can leak information and
we discover new and exciting ways almost everyday.  However, it is the only
guarantee that we have, period, that any information you send is going to be
the same information that&amp;rsquo;s going out to the &amp;ndash; to the server and vice versa.
Given that, I think it&amp;rsquo;s highly important for any service that is doing anything
with any information that has any value whatsoever, any, to use SSL.  It&amp;rsquo;s
really quite important.  And it&amp;rsquo;s also really quite easy.  For example,
StartSSL (which is much bigger than 124 &amp;ndash; or 1024 by 768) will give you free
SSL certificates.  All you need is an IP address. StartSSL is great.  I use them
for my site.  It&amp;rsquo;ll look something like this when you do.  It won&amp;rsquo;t look like
this because I never touch this thing, but you&amp;rsquo;ll get a nice green thing up
here.  You&amp;rsquo;ll get some green stuff there.  You&amp;rsquo;ll get some green things over
here which is kind of nice.  But basically, all of that is theater.  What it
means simply is that you have the ability to encrypt the connection between
you and the client and that is only a good thing.  If you start setting up SSL
and you want to make sure that you&amp;rsquo;ve done it correctly, there&amp;rsquo;s an excellent
website called &lt;a href=&quot;https://www.ssllabs.com/ssltest/index.html&quot;&gt;ssllabs.com which has an SSL test&lt;/a&gt;.  This will run
through a lot of tests that show you in great detail how you have screwed up
your SSL connections or how you have screwed up your SSL system in general.&lt;/p&gt;

&lt;p&gt;I apparently still have some work to do.&lt;/p&gt;

&lt;p&gt;Generally speaking, SSL is really quite valuable, really important, and not
that difficult to set up.  It&amp;rsquo;s like &lt;a href=&quot;http://wiki.nginx.org/HttpSslModule&quot;&gt;three lines in Nginx&lt;/a&gt; and it&amp;rsquo;s
probably similar in just about every other system.  The only complication is
generating a request and then sending the request off and then getting a
response back and making sure that you &lt;a href=&quot;http://www.digicert.com/ssl-certificate-installation-nginx.htm&quot;&gt;concatenate things in the right
order&lt;/a&gt; so that Nginx will send it.  It&amp;rsquo;s really quite straightforward
and really quite nice.  So, I highly recommend that you do that.&lt;/p&gt;

&lt;p&gt;Once you do, once you&amp;rsquo;ve gone ahead and set up SSL, make sure that all your
users are using it all the time.  That is if someone requests an HTTP page,
redirect them to the HTTPS page.  There&amp;rsquo;s a 301 permanent redirect, it&amp;rsquo;s just
the location header, it&amp;rsquo;s really quite straight forward.  The clever amongst you
will notice that this leaves a window of opportunity for an attacker to do
some interesting things.  They could &lt;a href=&quot;http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security#Applicability&quot;&gt;strip this redirect&lt;/a&gt;, for
instance.  They could man-in-the-middle you at that point and say, &amp;ldquo;Okay, I&amp;rsquo;m
going to keep you on HTTP but I&amp;rsquo;m going to do the HTTPS connection over here to
the server and then I&amp;rsquo;ll just forward the information to you.&amp;rdquo;  They can keep
you on HTTPS &amp;ndash; or HTTP by doing so.  To get back to the concept of client-side
and browser-side, you can actually instruct the browser to &lt;em&gt;only&lt;/em&gt; connect to
your website over HTTPS regardless of what the user actually types into the
address bar.  You do that by setting a &lt;a href=&quot;http://www.html5rocks.com/en/tutorials/security/transport-layer-security/#closing-the-open-window&quot;&gt;&lt;code&gt;Strict-Transport-Security&lt;/code&gt;
header&lt;/a&gt;.  What this means is that the browser will do a transparent
redirect locally before it actually goes out to the network.  So, if I type in
&lt;code&gt;mikewest.org&lt;/code&gt;, or if I type in &lt;code&gt;http://mikewest.org&lt;/code&gt;, the browser will actually
switch that to HTTPS for me before it goes out to the network.  This means that
there&amp;rsquo;s not &amp;ndash; there&amp;rsquo;s only one window of opportunity for an attacker to strip
the SSL connection and that&amp;rsquo;s the very first time you connect to a site.  So,
connect from home in the dark with a hood over your head or something so that
you&amp;rsquo;re extra secure.  And then when you go out in to the wild and dangerous
world, you&amp;rsquo;ll be guaranteed that you go to HTTPS and not http.  If you&amp;rsquo;d like
to see the list of websites that is actually already set up within Chrome or
within Firefox, then go to &amp;lt;chrome://net-internals&amp;gt; and check.&lt;/p&gt;

&lt;p&gt;So, I can look at &lt;code&gt;mikewest.org&lt;/code&gt; and you&amp;rsquo;ll see that it&amp;rsquo;s in strict mode that
include &amp;ndash; doesn&amp;rsquo;t include subdomains and there&amp;rsquo;s some nother stuff that I&amp;rsquo;ll
talk about in just a minute. So, Strict Transport Security, it&amp;rsquo;s a good
thing, I highly recommend that you set it up.  This means you have SSL and all
your users use it all the time, or as close to all the time as you could possibly
get.&lt;/p&gt;

&lt;p&gt;If you want even more security &amp;ndash; well, actually this is something that you
should do even if you don&amp;rsquo;t want security.  Even if you don&amp;rsquo;t care at all, you
should do this anyway.  &lt;code&gt;Set-Cookie&lt;/code&gt;, whenever you set cookies, make sure that
you set a &amp;ndash; the &lt;code&gt;secure&lt;/code&gt; flag, which means that they are only sent over SSL and
never sent over HTTP and you set the &lt;code&gt;HttpOnly&lt;/code&gt; flag which means your cookies
are not accessible from JavaScript.  This means even if someone can inject
JavaScript into your page and, even if it gets past your policy and even if it&amp;rsquo;s
executed, they still won&amp;rsquo;t be able to steal users authentication tokens because
&amp;ndash; well, not easily anyway.  They won&amp;rsquo;t be able to do it via JavaScript.
They&amp;rsquo;ll have to find other ways in your site to expose the value of the cookie.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Public-Key-Pins&lt;/code&gt; is a mechanism of making your security even more secure.  So,
the weakest link in SSL right now are the people that issue SSL certificates,
the &lt;a href=&quot;http://en.wikipedia.org/wiki/Certificate_authority&quot;&gt;Certificate Authorities&lt;/a&gt;.  It&amp;rsquo;s the case that any certificate authority
has the authority to issue certificates for any origin on the web.  So, I can
issue a &lt;code&gt;google.com&lt;/code&gt; certificate, you can issue a &lt;code&gt;google.com&lt;/code&gt; certificate, it&amp;rsquo;s
just a beautiful world where we all have this ability. Google, however, would
prefer that not everyone have this ability.  Since we can&amp;rsquo;t change the CA system
as it is, we can instead look to things that ensure that the certificate is only
acceptable if it meets whatever requirements we set up.  In this case,
&lt;code&gt;Public-Key-Pins&lt;/code&gt; gives us the ability to send a header that says only accept
certificates whose public key matches this hash.  This means we only accept
certificates that we have signed, not that &lt;em&gt;anyone&lt;/em&gt; has signed but that &lt;em&gt;we&lt;/em&gt;
have signed.  This gives you the ability to only accept &lt;em&gt;certain&lt;/em&gt; certificates
and not &lt;em&gt;all&lt;/em&gt; certificates that are valid for a particular origin.  It&amp;rsquo;s really
quite valuable especially if your site is a high-value target that&amp;rsquo;s under attack.&lt;/p&gt;

&lt;p&gt;I haven&amp;rsquo;t set this up on my site because it is incredibly easy to screw up.  If
I lose my keys, then people would no longer be able to access my website because
I would generate a new SSL cert but, for the max age of the pinning, which in
this case is &amp;ndash; I don&amp;rsquo;t know, some long amount of time, I think that&amp;rsquo;s a month
&amp;ndash; people would go to my website and then they get an SSL error even though I&amp;rsquo;ve
set up everything on my end.  So, you need to be really, really sure that you&amp;rsquo;re
doing everything right before you start implementing this.&lt;/p&gt;

&lt;p&gt;If you want to go a step further, you can talk to Chrome and you can talk to
Firefox about having your website &lt;a href=&quot;http://src.chromium.org/viewvc/chrome/trunk/src/net/http/transport_security_state_static.json&quot;&gt;hard-coded into Chrome as being on the HSTS
list&lt;/a&gt;.  What this means is that there&amp;rsquo;s no window of opportunity for an
attacker to strip SSL on your site.  So, &lt;code&gt;mail.google.com&lt;/code&gt;, &lt;code&gt;paypal.com&lt;/code&gt;, a
wide variety of sites had chosen to do this.  They&amp;rsquo;re basically hard-coded into
Chrome as a list of sites that should always be HSTS, that should always use
Strict Transport Security.  And if your site is one those sites, just &lt;a href=&quot;http://crbug.com/new&quot;&gt;file a
bug&lt;/a&gt; and we&amp;rsquo;re happy to add any site and every site but beware
of the consequences because if you&amp;rsquo;ve then screwed up your SSL then no one can
get to your site, ever, with Chrome.&lt;/p&gt;

&lt;p&gt;That is Transport Level &amp;ndash; &lt;a href=&quot;http://src.chromium.org/viewvc/chrome/trunk/src/net/http/transport_security_state_static.json&quot;&gt;Transport Layer Security&lt;/a&gt;.  There&amp;rsquo;s one more
topic that I was going to talk about but I think I&amp;rsquo;m going to skip it because
it&amp;rsquo;s not particularly important.  The slides are online so please feel free to
skim through all the &lt;code&gt;&amp;lt;iframe sandbox&amp;gt;&lt;/code&gt; stuff.  It&amp;rsquo;s pretty interesting but
it&amp;rsquo;s not critical.&lt;/p&gt;

&lt;p&gt;What I think is critical is, again, one more time, just so everyone remembers,
&lt;a href=&quot;https://mkw.st/r/csp&quot;&gt;Content Security Policy&lt;/a&gt;.  It&amp;rsquo;s really important.  I think it&amp;rsquo;s the
single biggest step forward that we&amp;rsquo;ve made in quite some time with regard to
mitigating the risk of cross-site scripting attacks.  It&amp;rsquo;s not perfect.
Attackers will still attack you after you have a policy but at least you&amp;rsquo;ve
raised the bar to the point where attacking you is hard as opposed to not so
hard.  Thank you for your time.&lt;/p&gt;

&lt;h2 id=&quot;qa&quot;&gt;Q&amp;amp;A&lt;/h2&gt;

&lt;p&gt;Do you have any questions?  I&amp;rsquo;d be really happy to answer them.  Yeah?&lt;/p&gt;

&lt;p&gt;I mean, maybe, depending on the question.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; So, this one&amp;rsquo;s going to be hopefully challenging.  So, we were on quite a big
web service and we really rely on advertising on all pages.  So, what we get a
lot is, from security web people like people in this room, is use f-ing SSL
and we cannot do that because of all the advertising.  Most advertisers do not
use SSL to serve ads.  Do you have any suggestions what we could do about it?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; I &amp;ndash; well, the flip suggestion would be find advertisers that serve over
SSL.  The less flip suggestion is that we&amp;rsquo;re moving in that direction.
Advertisers in general are starting to understand that they simply &amp;ndash; they can&amp;rsquo;t
embed into it &amp;ndash; SSL sites.  And because of that, they&amp;rsquo;re going to start losing
revenue.  It&amp;rsquo;s not happening as quickly as I&amp;rsquo;d like, but generally speaking, the
trend is for everything on the net to be encrypted.  If you look at &lt;a href=&quot;http://www.chromium.org/spdy&quot;&gt;SPDY&lt;/a&gt;, if
you look at &lt;a href=&quot;http://blog.chromium.org/2013/06/experimenting-with-quic.html&quot;&gt;QUIC&lt;/a&gt;, if you look at HTTP2 which is currently in discussion, the
general trend in those discussions is starting with SSL, and that there just
isn&amp;rsquo;t a non-encrypted variant.  There&amp;rsquo;s some discussion around that,
specifically around caching because encryption makes caching difficult.  But
generally speaking, the trend is towards encryption and the trend, specifically
with new protocols, is to only have encryption and to simply not have a
non-encrypted channel.&lt;/p&gt;

&lt;p&gt;So, my answer would be that it gets better but they we&amp;rsquo;re going to have to wait
for that betterness.&lt;/p&gt;

&lt;p&gt;For now, I would suggest using advertisers that can serve over SSL like Google,
for instance.  But generally speaking, I honestly believe that this is going to
be a feature that website owners are going to start asking for more and more.
And it&amp;rsquo;s up to website owners and publishers to put pressure onto advertisers so
that they actually start doing the right thing.  Until that pressure, until that
market pressure exists, it&amp;rsquo;s going to be very difficult to move advertisers
towards a more secure world.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; Hi.  Thank you for this talk.  What&amp;rsquo;s your opinion on this plugins that
came last year like &lt;a href=&quot;https://www.eff.org/https-everywhere&quot;&gt;HTTPSEverywhere&lt;/a&gt; for Firefox as well as Adblock Plus
which has been, I believe, two or three months ago.  In Germany, there was a
big announcement of all these media sites serving, saying to you. You have an
Adblocker, please, please disable it because we are relying on advertising,
for example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; I think those are &amp;ndash; I guess I would say that those are two completely
different questions.  I think &lt;a href=&quot;https://www.eff.org/https-everywhere&quot;&gt;HTTPSEverywhere&lt;/a&gt; is wonderful.  I highly
encourage that you install HTTPSEverywhere.  It&amp;rsquo;s a plugin, an extension or a
plugin depending on your browser from the EFF, the &lt;a href=&quot;https://www.eff.org/&quot;&gt;Electronic Freedom&amp;hellip;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; Foundation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt;  Yes, I don&amp;rsquo;t &amp;ndash; it&amp;rsquo;s just &lt;a href=&quot;https://www.eff.org/&quot;&gt;EFF&lt;/a&gt; and it&amp;rsquo;s awesome. I &lt;a href=&quot;https://supporters.eff.org/donate&quot;&gt;give them
money&lt;/a&gt;, I just don&amp;rsquo;t know their name.&lt;/p&gt;

&lt;p&gt;Generally speaking, I would highly recommend that you install it because what
it does is &amp;ndash; has a list of all services or lots of services that serve things
over HTTPS but for whatever reason give you HTTP options.  It forces you onto
HTTPS.  So, it&amp;rsquo;s kind of like a client-side version of the Strict Transport
Security that we talked about.  And then, I recommend that you install it but
understand that not every publisher actually expects you to use HTTPS, so, it
breaks sometimes.  You have to understand that maybe for this site, you have
to turn it off and it&amp;rsquo;s a little bit more work but you&amp;rsquo;re certainly more
secure because you&amp;rsquo;re sending the vast majority of your traffic over HTTPS
and that&amp;rsquo;s a very good thing.  AdBlock is kind of a completely different
question and I&amp;rsquo;m going to ignore it.&lt;/p&gt;

&lt;p&gt;I won&amp;rsquo;t actually.&lt;/p&gt;

&lt;p&gt;AdBlock &amp;ndash; I don&amp;rsquo;t understand Adblock.  I understand why people use it because
ads are often annoying. But for good or for ill, advertising is absolutely
central to financing the web, period, whether you like it or not.  Given that,
I think it&amp;rsquo;s problematic if a large portion of the populace is blocking ads.
I&amp;rsquo;m not going to tell you to stop blocking ads because you&amp;rsquo;re not going to.
But generally speaking, I think it&amp;rsquo;s the wrong thing to do.  I think the right
thing to do is to vote with your feet and if you don&amp;rsquo;t like the ads on a
particular publisher, don&amp;rsquo;t visit that publisher.  I understand there are
reasons that people use it. We&amp;rsquo;ve talked about it yesterday or the day before.
But generally speaking, I see it as really problematic and I find that when
people complain about ads in the web, like, I find it unsympathetic, but of
course I would because I work for Google so, who knows?  Feel free to ignore
that.&lt;/p&gt;

&lt;p&gt;We&amp;rsquo;ll talk afterwards, okay? It&amp;rsquo;s not really this topic so we&amp;rsquo;ll talk
afterwards.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; Yeah, sorry.  I quite like the reporting feature which we saw before and &amp;ndash; but
there was just a question on twitter.  Is there some way to prevent misuse?
Because like the URL for reporting is then public and basically everyone can
submit anything there, so, how to use a tech if it&amp;rsquo;s really from a browser or&amp;hellip;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; Yeah.  So, we do &amp;ndash; we &amp;ndash; First, I would suggest that you should
already have things in place that do rate-limiting.  So, if you&amp;rsquo;re being DDOS&amp;rsquo;d
then you should have mechanisms in place, and this isn&amp;rsquo;t gonna make that any
worse. Second I would say, that for same-origin reporting mechanisms, so, if
&lt;code&gt;example.com&lt;/code&gt; reports to &lt;code&gt;example.com&lt;/code&gt;, we send cookies.  If example.com reports
to something else then we don&amp;rsquo;t send cookies.  So, at that point, you can use the
cookies as some sort of authentication mechanism and say that, you know, this is
coming from this user. What you can also do is have a token, a &lt;a href=&quot;http://en.wikipedia.org/wiki/Cross-site_request_forgery&quot;&gt;CSRF token&lt;/a&gt; in
the reporting URL and say that for this page, you go to this URL, for this page,
you go to that URL, just with GET parameters and then verify that those
parameters are actually what you expect them to be.  So, in the same way that
you verify form submissions, you can also verify these sorts of POSTs. And I
think that would take care of most of the mechanisms.&lt;/p&gt;

&lt;p&gt;You&amp;rsquo;re making him run, that&amp;rsquo;s just mean!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; I&amp;rsquo;ll raise about full HTTPS, what is the impact first about SEO, how Google
look about HTTPS for the website, have an impact?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; I have no idea but Google serves basically everything itself over SSL,
almost everything.  And generally speaking, Google as a company wants people to
be using SSL.  I&amp;rsquo;d be shocked if SSL had a negative impact but I am not a
quote-unquote &amp;ldquo;SEO expert&amp;rdquo;, so don&amp;rsquo;t take my word for anything.  Talk to people
who know something about SEO.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; Just a last comment, when you have a big website with lots of view, if you
use full SSL, of course, we need to have a bigger hosting environment.  How many
percentage?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; Not significantly.  So, there is kind of this general common knowledge
that SSL is much slower than HTTP.  It&amp;rsquo;s not that slow.  I think you&amp;rsquo;re going
to &amp;ndash; I&amp;rsquo;m going to quote it wrong.  There&amp;rsquo;s a &amp;ndash; there are some really smart
people at Google.  One of them is &amp;ndash; what&amp;rsquo;s the guy&amp;rsquo;s name?  Smart guy at
Google, help me out.  Violet &amp;ndash; SSL something &amp;ndash; &lt;a href=&quot;https://www.imperialviolet.org/&quot;&gt;ImperialViolet&lt;/a&gt;, there
we go. Oh, and look, that&amp;rsquo;s like &amp;ndash; that&amp;rsquo;s the exact article I wanted to go to.
That is sweet.  So, there&amp;rsquo;s &lt;a href=&quot;https://www.imperialviolet.org/2010/06/25/overclocking-ssl.html&quot;&gt;a good article on ImperialViolet.org called
&amp;ldquo;Overclocking SSL&amp;rdquo;&lt;/a&gt;, where it talks a little bit about the
impact of SSL.  I want to say, yeah, one &amp;ndash; less than 1% of the CPU load, less
than 10K of memory per connection, less than 2% of network overhead.  There is
overhead, it is minimal.  This was 2010.  My suspicion is that it&amp;rsquo;s even lower
at this point.  So, if you have set things up poorly, then your site&amp;rsquo;s going to
be slow.  If, however, you follow the best practices for setting up SSL
connections and do the right things with regard to &lt;a href=&quot;http://tools.ietf.org/html/draft-bmoeller-tls-falsestart&quot;&gt;false-start&lt;/a&gt;
and a variety of other code, weird configuration options, you&amp;rsquo;re going to have a
site that&amp;rsquo;s exactly as fast &amp;ndash; within 1% of &amp;ndash;  non-SSL sites.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; I have one more question about the SSL thing which is, are there any
disadvantages in using a free SSL provider like you were showing in comparison
to the quite expensive other ones?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; Yeah.  I don&amp;rsquo;t get it.  I think Thawte would love for you to believe
that their certificates are more valuable.  They are not.  You get 204 &amp;ndash; 2048
bits of encryption with any certificate ever.  Certs are certs.  They are a text
file that&amp;rsquo;s like that long, there&amp;rsquo;s no reason to pay thousands and thousands of
Euros.  It&amp;rsquo;s kind of a ridiculous racket.  They can do that because people trust
them.  So, if you&amp;rsquo;re doing &amp;ndash; the only reason &amp;ndash; sorry, the only reason that I would
suggest using any of these services that are, you know, widely known and widely
trusted is that some networks, especially inside of enterprises for whatever
reason, only trust certificates from certain providers.  Generally speaking,
&lt;a href=&quot;https://www.startssl.com/&quot;&gt;StartSSL&lt;/a&gt;, which is the one that I recommend and the one that I use, is
well-supported across the world but you would have to test in the specific
enterprise whether they&amp;rsquo;ve, for whatever reason, disabled certificates from
people other than, like, the two CAs that they trust.  So, the only reason
that&amp;rsquo;s valuable is because it&amp;rsquo;s a racket.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; You just showed us this http header was &amp;ndash; the pin where&amp;hellip;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; Uh-hmm.  Yeah.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; Do we need a &lt;a href=&quot;https://www.startssl.com/&quot;&gt;StartSSL&lt;/a&gt; or some provider like that anyway or&amp;hellip;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; Yeah, yeah.  You&amp;rsquo;d have to have a cert before you can pin a cert, so
pinning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; Maybe somewhat, self-sign it to&amp;hellip;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; You can self-sign it and you can pin a self-signed certificate but the
browser isn&amp;rsquo;t going to trust that anymore.  There&amp;rsquo;s been &lt;a href=&quot;https://www.imperialviolet.org/2011/06/16/dnssecchrome.html&quot;&gt;some discussion around
making self-signed certificates less terrible in terms of their
presentation&lt;/a&gt; but I don&amp;rsquo;t think that&amp;rsquo;s going to roll out to the web.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; I see your point before that &lt;a href=&quot;http://en.wikipedia.org/wiki/Extended_Validation_Certificate&quot;&gt;EV SSL&lt;/a&gt; isn&amp;rsquo;t worth a lot really.  Why in
browsers do &amp;ndash; do browser producers actually change the icon?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; That is an excellent question.  You would have to talk with whoever
made that decision.&lt;/p&gt;

&lt;p&gt;I don&amp;rsquo;t think there&amp;rsquo;s any value to EV certificate. Basically, the certification
means that you have a lot of money and that you paid someone.  And that gives
you your name in the URL bar and I guess that has some value, and if you&amp;rsquo;re a
company then you have money to burn anyway so, hey, why not throw money at SSL.
But generally speaking, there is no difference, period, between the encryption
that you get with a self-signed certificate and a totally expensive EV
certificate.  The encryption is exactly the same.&lt;/p&gt;

&lt;p&gt;Great. Thank you very much.&lt;/p&gt;

&lt;p&gt;If you have any questions at all&amp;hellip;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; Thank you, Michael.  We&amp;rsquo;ll follow-up with our closing keynote.  Just a moment.&lt;/p&gt;

</content>
    </entry>

    
    <entry>
        <title type='text'>Debugging runtime errors with 'window.onerror' in Blink</title>
        <link rel="alternate" href="https://mikewest.org/2013/08/debugging-runtime-errors-with-window-onerror" />
        <id>https://mikewest.org/2013/08/debugging-runtime-errors-with-window-onerror</id>
        <updated>2013-08-08T00:00:00+02:00</updated>
        <published>2013-08-08T00:00:00+02:00</published>
        <content type='html'>&lt;p&gt;After working with Blink&amp;rsquo;s implementation of &lt;code&gt;window.onerror&lt;/code&gt; a little bit
over the last week or so, I&amp;rsquo;m somewhat amazed that anyone ever used it for
anything at all. For those of you to whom the API is news, the current
implementation in Chrome&amp;rsquo;s stable channel (28) looks a little bit like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;window.onerror = function (message, filename, lineno) {
    // Do some centralized error reporting here, for example, by POSTing
    // the error message, filename, and line number to a collection
    // server for later processing.
  
    return true; // The exception is handled, not reported to the user.
};

...

throw new Error('OMG!');
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&amp;lsquo;window.onerror&amp;rsquo; acts something like a global try/catch block, allowing you
to gracefully handle uncaught exceptions you didn&amp;rsquo;t expect to see. This, in
theory, is brilliant.&lt;/p&gt;

&lt;p&gt;Two issues have made it less than brilliant in practice:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Unlike a local try/catch block, the &lt;code&gt;window.onerror&lt;/code&gt; handler doesn&amp;rsquo;t have
direct access to the exception object, and is executed in the global
context rather than locally where the error occurred. That means that
developers don&amp;rsquo;t have access to a call stack, and can&amp;rsquo;t build a call stack
themselves by walking up the chain of a method&amp;rsquo;s callers.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Browsers go to great lengths to sanitize the data provided to the handler
in order to prevent unintentional data leakage from cross-origin scripts.
If you host your JavaScript on a CDN (as you ought), you&amp;rsquo;ll get &amp;ldquo;Script
error.&amp;rdquo;, &amp;ldquo;&amp;rdquo;, and 0 in the above handler. That&amp;rsquo;s not particularly helpful.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are a few other concerns, but those are the big two. I&amp;rsquo;m happy to say
that recent patches have addressed many of the concerns in Blink.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Christophe Dumez &lt;a href=&quot;http://crbug.com/264197&quot;&gt;added the column number to the handler&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;After a lot of back-and-forth, Hixie &lt;a href=&quot;http://html5.org/r/8086&quot;&gt;added an &amp;lsquo;error&amp;rsquo; parameter to the
&lt;code&gt;onerror&lt;/code&gt; handler in the WHATWG spec&lt;/a&gt;. This, as you might imagine,
contains the exception that was thrown, just as you&amp;rsquo;d get in a &lt;code&gt;catch&lt;/code&gt;
block. The &lt;a href=&quot;http://crbug.com/147127&quot;&gt;Blink implementation landed last week&lt;/a&gt;, which means that you
can now access the stack trace in your handler via something like the
following:&lt;/p&gt;

    &lt;pre&gt;&lt;code&gt;window.onerror = function (message, filename, lineno, colno, error) {
    console.log(&quot;This is a stack trace! Wow! --&amp;gt; %s&quot;, error.stack);
};
&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Blink &lt;a href=&quot;http://crbug.com/159566&quot;&gt;now follows&lt;/a&gt; Mozilla&amp;rsquo;s and WebKit&amp;rsquo;s practice of enabling full
detail in exceptions generated from cross-origin scripts that are served
with proper access-control headers and attributes. If you add a
&lt;code&gt;crossorigin&lt;/code&gt; attribute to a &lt;code&gt;script&lt;/code&gt; tag, and serve that script with an
&lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt; header that allows access to the document
loading the script, then you&amp;rsquo;ll be given unsanitized data in your error
handlers. That might look something like this:&lt;/p&gt;

    &lt;pre&gt;&lt;code&gt;&amp;lt;script crossorigin=&quot;anonymous&quot; src=&quot;http://cdn.example.com/script.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

    &lt;p&gt;Note that this is a bit tricky: you&amp;rsquo;ll need to make quite sure that your
server is properly configured. If a script has a &lt;code&gt;crossorigin&lt;/code&gt; attribute
but the server doesn&amp;rsquo;t send appropriate CORS headers, the script load
will fail miserably.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://code.google.com/p/v8/issues/detail?id=2822&quot;&gt;Stringification of custom errors is (slightly) improved&lt;/a&gt; for the case
where an Error object is directly set as the prototype of your custom
error. Handlebars, for instance, created a &lt;code&gt;Handlebars.Exception&lt;/code&gt; object
with code like this:&lt;/p&gt;

    &lt;pre&gt;&lt;code&gt;Handlebars.Exception.prototype = new Error();
&lt;/code&gt;&lt;/pre&gt;

    &lt;p&gt;V8 didn&amp;rsquo;t support that very well in &lt;code&gt;window.onerror&lt;/code&gt;: the stringification
looked something like &lt;code&gt;[object Object]&lt;/code&gt;, which wasn&amp;rsquo;t particularly useful
for anyone. Now you&amp;rsquo;ll get the expected message, as long as you haven&amp;rsquo;t
overridden the &lt;code&gt;toString&lt;/code&gt; method.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;I&amp;rsquo;m still knee-deep in the Worker implementation, which is a bit of mess
really. I expect to &lt;a href=&quot;http://crbug.com/269538&quot;&gt;fix the sanitization&lt;/a&gt; shortly, and I think it
shouldn&amp;rsquo;t be too difficult to &lt;a href=&quot;http://crbug.com/270005&quot;&gt;add the &lt;code&gt;error&lt;/code&gt; property to the Worker&amp;rsquo;s
&lt;code&gt;onerror&lt;/code&gt; handler&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I think this set of changes will make centralized error reporting a bit more
realisticly possible in the near future. I&amp;rsquo;d love for you folks to start
banging on these initial implementations now so that I can fix bugs and clean
up edge-cases now, before these start rolling into Stable. When you see a bug
please do file it at &lt;a href=&quot;http://crbug.com/new&quot;&gt;http://crbug.com/new&lt;/a&gt;, and ping me the bug ID
(&lt;a href=&quot;https://google.com/+MikeWest&quot;&gt;+Mike West&lt;/a&gt;, &lt;a href=&quot;https://twitter.com/mikewest&quot;&gt;@mikewest&lt;/a&gt;, or &lt;a href=&quot;&amp;#109;&amp;#097;&amp;#105;&amp;#108;&amp;#116;&amp;#111;:&amp;#109;&amp;#107;&amp;#119;&amp;#115;&amp;#116;&amp;#064;&amp;#099;&amp;#104;&amp;#114;&amp;#111;&amp;#109;&amp;#105;&amp;#117;&amp;#109;&amp;#046;&amp;#111;&amp;#114;&amp;#103;&quot;&gt;&amp;#109;&amp;#107;&amp;#119;&amp;#115;&amp;#116;&amp;#064;&amp;#099;&amp;#104;&amp;#114;&amp;#111;&amp;#109;&amp;#105;&amp;#117;&amp;#109;&amp;#046;&amp;#111;&amp;#114;&amp;#103;&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Enjoy Blink&amp;rsquo;s newly more-usable error reporting!&lt;/p&gt;

</content>
    </entry>

    
    <entry>
        <title type='text'>Securing the Client Side</title>
        <link rel="alternate" href="https://mikewest.org/2013/02/securing-the-client-side-devoxx-2012" />
        <id>https://mikewest.org/2013/02/securing-the-client-side-devoxx-2012</id>
        <updated>2013-02-25T00:00:00+01:00</updated>
        <published>2013-02-25T00:00:00+01:00</published>
        <content type='html'>&lt;p&gt;In November, 2012, I attended Devoxx in Antwerp for the first time to present
some recent developments in client-side security. &lt;a href=&quot;http://www.html5rocks.com/en/tutorials/security/content-security-policy/&quot;&gt;Content Security
Policy&lt;/a&gt; of course was at the top of my list. I think the presentation
does a nice job walking through the rationale behind some practices I&amp;rsquo;d like to
see spread.&lt;/p&gt;

&lt;p&gt;In the interests of making the presentation as accessible (and indexable) as
possible, a full transcript of the presentation is below, along with an embed of
the video and slides.&lt;/p&gt;

&lt;h2 id=&quot;video&quot;&gt;Video&lt;/h2&gt;

&lt;iframe src=&quot;http://www.parleys.com/dist/share/parleysshare.swf?sv=true&amp;amp;pageId=3521&quot; allowfullscreen=&quot;true&quot; mozallowfullscreen=&quot;true&quot; webkitallowfullscreen=&quot;true&quot; frameborder=&quot;0&quot; title=&quot;'Securing the Client Side' -- Devoxx 2012: Video&quot; width=&quot;606&quot; height=&quot;403&quot;&gt;&lt;/iframe&gt;

&lt;h2 id=&quot;slides&quot;&gt;Slides&lt;/h2&gt;

&lt;iframe src=&quot;https://speakerdeck.com/player/00342360618601301a9912313d095c59&quot; allowfullscreen=&quot;true&quot; mozallowfullscreen=&quot;true&quot; webkitallowfullscreen=&quot;true&quot; frameborder=&quot;0&quot; title=&quot;'Securing the Client Side' -- Devoxx 2012: Slides&quot; width=&quot;606&quot; height=&quot;403&quot;&gt;&lt;/iframe&gt;

&lt;h2 id=&quot;transcript&quot;&gt;Transcript&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; Got a cell phone in there, who knows&amp;hellip;&lt;/p&gt;

&lt;p&gt;The topic of today is, or, of this talk anyway, is &amp;ldquo;Securing The Client Side&amp;rdquo;.
It&amp;rsquo;s kind of, I think, an interesting topic for a Java conference, because most
Java programs have very little to do with actually building HTML and pushing it
out to clients.  It is, however, the case that if you want the largest market
possible, the target of your language or whatever your application is, is going
to be JavaScript, it&amp;rsquo;s going to CSS and it&amp;rsquo;s going to be HTML. That gives you
the ability to push your application out to a huge audience that you simply
wouldn&amp;rsquo;t have access to if you tried to deploy something in a more native way.
The web is simply the largest platform out there.&lt;/p&gt;

&lt;p&gt;And a consequence of this is that we&amp;rsquo;re slowly seeing more and more of the
application logic being moved down to the client side. It&amp;rsquo;s moving out of these
large back-end systems and moving down into JavaScript and executing then on a
client&amp;rsquo;s computer, on an untrusted machine, as opposed to a machine, the server,
that you have complete control over. There are a couple of things that you can
do on the server side in order to ensure that your application is secure, to
ensure that no one can write things into your application that you don&amp;rsquo;t want,
and to ensure that the code that your application delivers is secure when it
actually gets to the client.&lt;/p&gt;

&lt;p&gt;We&amp;rsquo;re not going to talk about that today.&lt;/p&gt;

&lt;p&gt;Instead, we&amp;rsquo;re going to focus very specifically on what you can do in the
browser, in order to ensure some measure of security for your application. It&amp;rsquo;s
simply the case that the browser is an untrusted environment, so you need to be
very careful about what you&amp;rsquo;re doing. But at the same time, there are some new
capabilities coming out in browsers of today, that allow you to ensure that your
application is delivered in a way that maintains some degree of security.&lt;/p&gt;

&lt;p&gt;The web is simply a scary place. Have any of you seen a screen like this? In
Chrome or any other browser?  Most browsers today have some sort of Safe
Browsing system which tells you when you&amp;rsquo;re visiting a site that we know could
be problematic. So, if we&amp;rsquo;ve seen a lot of malware on a site, we have mechanisms
by which we can inform the browser that a specific website might be problematic.&lt;/p&gt;

&lt;p&gt;It&amp;rsquo;s most often the case however, that the things that we&amp;rsquo;re really worried
about aren&amp;rsquo;t pervasive and aren&amp;rsquo;t persistent on a website.&lt;/p&gt;

&lt;p&gt;It&amp;rsquo;s very difficult for someone like Google or Mozilla to detect malware on a
site, if the site itself is benign.  There are a variety of attacks that can
allow someone to inject code or inject content into a website that&amp;rsquo;s otherwise
perfectly benign, nd only affects the person who is actually visiting that page
at the moment. It&amp;rsquo;s called a cross-site scripting attack.  And there are a wide
variety of mechanisms that allow it to occur.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;m going to talk about two things that you can do to reduce the capabilities of
someone who would be attacking your sites and to mitigate the effects of any
attack that did get past your defenses.&lt;/p&gt;

&lt;p&gt;But before I start talking about things that you can do to defend, I want to
talk about one thing that I see as an absolute prerequisite for anything&amp;hellip; for
any discussion of security on the web.&lt;/p&gt;

&lt;p&gt;You must, &lt;em&gt;must&lt;/em&gt; send data and accept data over a secure channel.  There&amp;rsquo;s
really no excuse these days for using HTTP as opposed to HTTPS to deliver an
application.  Applications &lt;em&gt;must&lt;/em&gt; be delivered over HTTPS because that&amp;rsquo;s the
only mechanism by which you can ensure that there&amp;rsquo;s even a modicrum of a chance
that the data that you send out and the data that the user receives are
identical.&lt;/p&gt;

&lt;p&gt;Our view of the web kind of looks like this. We think about it.  I have a
laptop.  I go out directly to a server.  I pull some information down.  I do
something locally and then I send more information up to the server.  We think
about these direct connections, but of course it&amp;rsquo;s the case that there is no
direct connection between me and a server.&lt;/p&gt;

&lt;p&gt;Instead, I&amp;rsquo;d go to a coffee shop.  And in that coffee shop, I hook up to their
Wi-Fi network and then, in order to transmit my requests up to the server, it
hops and hops and hops through a variety of routers and a variety of different
servers until it actually hits the end point that I care about.&lt;/p&gt;

&lt;p&gt;That&amp;rsquo;s a lot of things that I have to trust.  It&amp;rsquo;s a lot of different servers
that I need to ensure that I &amp;ndash; if I want to ensure that the information gets
from A to B intact, I need to trust each of those points in between.  If you&amp;rsquo;re
sending information over HTTP, it&amp;rsquo;s very likely that something like this could
happen.  It&amp;rsquo;s called the man-in-the-middle attack.  I send information over
HTTP, some malicious server in between me and the end point takes that
information, modifies it in some way and then sends it on, acting as a proxy
between me and the server that I actually care about.&lt;/p&gt;

&lt;p&gt;At this point, it&amp;rsquo;s pretty much game over.  If I&amp;rsquo;m sending information over an
unencrypted channel, that man-in-the-middle can take the information, either
read it, modify it, do really whatever they want.  And there&amp;rsquo;s no way to detect
this sort of thing.  Because HTTP has no sort of encryption associated with it
and no sort of signature associated with it which means that the information
that I receive, I&amp;rsquo;d simply have to blindly trust that it&amp;rsquo;s the information the
server actually sent down to me.  That&amp;rsquo;s something that I don&amp;rsquo;t think anyone
should be doing when writing an application.  When writing an application, you
should instead be very certain that you&amp;rsquo;re sending information over HTTPS.&lt;/p&gt;

&lt;p&gt;HTTPS gives you a mechanism by which you can first encrypt the connection
between you and the server, it still hops over a wide variety of routers in
between you and the server.  But none of those routers have the ability to read
the information.  Because they don&amp;rsquo;t have the private key that exists on the
server.&lt;/p&gt;

&lt;p&gt;At that point, you have some measure of security, some measure of privacy that
is, in that the information can&amp;rsquo;t be read.  Second, you have a measure of
security in that the information can&amp;rsquo;t be modified as it&amp;rsquo;s sent back down to you
without reencrypting the information using the same key as the server.  This is
very difficult to do.  It&amp;rsquo;s not impossible.  So this isn&amp;rsquo;t a completely secure
solution but it&amp;rsquo;s miles better than HTTP where you have absolutely no guarantees
whatsoever.&lt;/p&gt;

&lt;p&gt;Anyone who&amp;rsquo;s running a server should still listen on HTTP ports because most
people will just type in the server name into the browser and the browser will
default to HTTP, would go out to the website and then something like this should
happen.  You should be doing a redirect &amp;ndash; that&amp;rsquo;s kind of cut off on the side
which is annoying.&lt;/p&gt;

&lt;p&gt;What you see at the top is a &lt;code&gt;curl&lt;/code&gt;, a &lt;code&gt;HEAD&lt;/code&gt; request to &lt;code&gt;mkw.st&lt;/code&gt;.  It&amp;rsquo;s going
over HTTP and at the bottom you&amp;rsquo;ll see a location header, which redirects me to
the HTTPS server.  This is good, this means that I&amp;rsquo;ll &amp;ndash; most of my connections
will be over HTTPS.  But it leaves the vulnerability because that first
connection is going out over HTTP.  It&amp;rsquo;d be nice if we can somehow inform the
browser that it should default to HTTPS as opposed to defaulting to HTTP, as it
turns out we can.  There&amp;rsquo;s a new header called
&lt;a href=&quot;http://www.html5rocks.com/en/tutorials/security/transport-layer-security/&quot;&gt;&lt;code&gt;Strict-Transport-Security&lt;/code&gt;&lt;/a&gt;. Strict Transport Security says, I&amp;rsquo;m
sending this information over HTTPS and next time you connect to the server,
forget about HTTP.  Even if the user types in &lt;code&gt;http://servername&lt;/code&gt;, go over
HTTPS.  Do the redirection client side as opposed to making a request and
letting it happen server side.&lt;/p&gt;

&lt;p&gt;There&amp;rsquo;s a &lt;code&gt;max-age&lt;/code&gt; associated with this, so you can say for a month, do this
sort of thing or for a year or for however long you actually trust that you&amp;rsquo;ll
keep your certificates up-to-date.  And there&amp;rsquo;s a mechanism by which you can
also say that all subdomains of this domain, should also be protected by Strict
Transport Security.  This is really good for you guys to be doing.  I would, so
I would very much recommend that anyone who&amp;rsquo;s writing an application that&amp;rsquo;s
delivered over the web, go to &lt;a href=&quot;https://startssl.com/?app=0&quot;&gt;startssl.com&lt;/a&gt; or any of a number of
other certificate delivery websites where you can sign up, get a certificate,
associate it with your website and ensure that your application is being
delivered in a secure fashion.&lt;/p&gt;

&lt;p&gt;Once you&amp;rsquo;ve done that, go ahead and set up &lt;code&gt;Strict-Transport-Security&lt;/code&gt; headers
in your website, so you&amp;rsquo;ll ensure that your users are always visiting your site
over HTTPS.  It&amp;rsquo;s really almost a no-brainer.  StartSSL in particular, is great
for people with really small applications.  It&amp;rsquo;s also good for large
applications, but for people that don&amp;rsquo;t need these warranties that are
associated with larger certificate manufacturers.  StartSSL is absolutely free.
They only charge you for the work that they do.  So, if you don&amp;rsquo;t care about
authentication &amp;ndash; no, not authentication.  If you don&amp;rsquo;t care about verification,
then you can get a free certificate for your app that is &amp;ndash; that works on all
browsers, which is great.&lt;/p&gt;

&lt;p&gt;If you do care about verification, or you want wild card certificates for
something on those lines.  The &lt;a href=&quot;https://startssl.com/?app=2&quot;&gt;level two verification&lt;/a&gt; is
like, 60 bucks, 60 US dollars for two years.  You get unlimited certificates
associated with that. Given this sort of thing, there&amp;rsquo;s really no excuse to not
have certificates even for the smallest of projects.&lt;/p&gt;

&lt;p&gt;With that out of the way, with that as a basis upon which we can build
everything else, let&amp;rsquo;s talk about the sorts of attacks that I would like to help
you defend against.  The most common is a script injection.  So if we go to
Google.com, over HTTPS of course, we might see something like this.  An alert
box popping up that says &amp;ldquo;XSS&amp;rdquo;.  This is kind of the very typical thing that if
you pay a penetration tester to go out to your website and show you the
vulnerabilities, this is most likely what you&amp;rsquo;ll see. You&amp;rsquo;ll see &amp;ndash; I was able
to inject script in to your site and that script executed and popped up an alert
box.&lt;/p&gt;

&lt;p&gt;It isn&amp;rsquo;t very scary though, right? It&amp;rsquo;s just an alert box.  So, why should we
really even care about it?  What&amp;rsquo;s more interesting of course, is to pop up the
user&amp;rsquo;s cookies and show them that by executing script on their site, you have
access to all of the information associated with that origin.&lt;/p&gt;

&lt;p&gt;The web is generally protected by the &lt;a href=&quot;http://en.wikipedia.org/wiki/Same_origin_policy&quot;&gt;same-origin policy&lt;/a&gt;. That
is, a website consists or the origin of a website consists of a scheme, a host
and a port: that is (&lt;code&gt;HTTPS&lt;/code&gt;, &lt;code&gt;google.com&lt;/code&gt;, 443).  It&amp;rsquo;s simply the case that,
that website should never have access to information on separate origin. So,
Google should never have access to my bank&amp;rsquo;s information for instance.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;[pause to resolve beard issues.]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This of course, is the downside of beards.  Beards are generally excellent.  I
highly recommend them, but if you have a microphone on your face, it makes it
slightly difficult.&lt;/p&gt;

&lt;p&gt;Regardless, &lt;code&gt;document.cookie&lt;/code&gt; can be read by any JavaScript that&amp;rsquo;s associated
with a particular domain or a particular origin. Generally, things are protected
by the same origin policy; that is Google can&amp;rsquo;t directly access anything from my
bank.  But if I&amp;rsquo;m able to inject some malicious JavaScript into the context of
&lt;code&gt;google.com&lt;/code&gt; or any other website, the browser has no mechanism of
distinguishing between a maliciously injected piece of content and a piece of
content that was injected intentionally by the browser or by the&amp;ndash;by the author
of the site.&lt;/p&gt;

&lt;p&gt;So, we see two alert boxes here and if we actually saw this when an attack was
going on, there will be some measure of protection going on.  But usually what
we see is absolutely nothing.  We visit a site it looks just like any normal
site.  We interact with it and transparently in the background, the person who&amp;rsquo;s
attacking the site is either exfiltrating sensitive information pushing out my
cookies to a third party server in order to steal my session or wide variety of
other things.&lt;/p&gt;

&lt;p&gt;Generally speaking, if someone is able to execute JavaScript on your site, it&amp;rsquo;s
more or less game over.  They have complete control over the site and they have
complete control over the information associated with that site which is pretty
problematic.&lt;/p&gt;

&lt;p&gt;This is a really excellent website to go to.  If you&amp;rsquo;re interested in how a
cross-site scripting attack might look.  It&amp;rsquo;s called the &lt;a href=&quot;https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet&quot;&gt;XSS cheat
sheet&lt;/a&gt; and it&amp;rsquo;s delivered by &lt;a href=&quot;https://www.owasp.org/&quot;&gt;OWASP&lt;/a&gt; which is security &amp;ndash; an
org &amp;ndash; an organization of people who are interested in security and put together
a lot of documentation, a lot of trainings along these lines.  It&amp;rsquo;s a really
long document because there are an incredible amount of ways of injecting code
into a site that doesn&amp;rsquo;t properly escape its output.&lt;/p&gt;

&lt;p&gt;JavaScript is really interesting in that it accepts a wide variety of syntax and
it&amp;rsquo;s very difficult to insure that you escaped everything correctly such that
JavaScript doesn&amp;rsquo;t execute.  If you simply echo any information that&amp;rsquo;s been
delivered by a user or any user generated content in general.&lt;/p&gt;

&lt;p&gt;There are two things that you need to do in order to protect against cross-site
scripting attacks.  And if you do these two things perfectly, you are a hundred
percent guaranteed you&amp;rsquo;ll never have a cross-site scripting attack on your site.&lt;/p&gt;

&lt;p&gt;First, you need to validate all the information that comes into your website.
So, if there&amp;rsquo;s a form where you accept someone&amp;rsquo;s phone number, you want to
insure that you only accept phone numbers, that you don&amp;rsquo;t accidentally accept
JavaScript.  One mechanism might be scripting out everything that isn&amp;rsquo;t the
number, right?  Then you&amp;rsquo;re more or less guaranteed you have something that you
can safely put into your database that you can safely deal with on the back end.&lt;/p&gt;

&lt;p&gt;The next thing you want to do is ensure that you correctly escape every piece of
output that you &amp;ndash; that you write to a site.  So, if you have any content that
comes from a user or any sort of untrusted source, then you want to insure that
you escape that output correctly when you write it out to the&amp;ndash;to the screen.&lt;/p&gt;

&lt;p&gt;I said you need to do it perfectly and unfortunately escaping output is much
more complex than it seems.  Here we have a little bit of HTML and what you &amp;ndash;
what you notice here is that there are five different contexts in which
information could be output.  This is a more or less exhaustive list.&lt;/p&gt;

&lt;p&gt;You have style information, you have raw HTML, that&amp;rsquo;s inside the &lt;code&gt;p&lt;/code&gt; tag, you
have a URL that&amp;rsquo;s inside of an attribute, you have information that&amp;rsquo;s been
written out directly into script, never ever do this, right?  Never write
information with the script, that&amp;rsquo;s just a bad idea.  And then you have
information it&amp;rsquo;s written into a comment on a site.  You usually see this as
debug information where people just write out information, so that they can
figure out what&amp;rsquo;s going on, on their own site.&lt;/p&gt;

&lt;p&gt;Unfortunately, each of these contexts has different escaping rules.  And you
need to be very sure that you&amp;rsquo;re escaping content correctly for the context in
which you find yourself.  Again, if you go to that website, I pointed to
earlier, it gives you some information about these contexts and about what the
rules might be.&lt;/p&gt;

&lt;p&gt;For instance, inside of an attribute, you need to be very sure that you&amp;rsquo;d
correctly escape quotes and it&amp;rsquo;s also the case that quotes aren&amp;rsquo;t actually
necessary.  So, you want to make sure that you escape the contents in a such a
way that it&amp;rsquo;s interpreted as an HTML attribute as opposed to a potentially a
script.&lt;/p&gt;

&lt;p&gt;Fortunately, this is a completely solved problem. It&amp;rsquo;s been solved at least
since 2009 when Google released an &lt;a href=&quot;http://googleonlinesecurity.blogspot.de/2009/03/reducing-xss-by-way-of-automatic.html&quot;&gt;automatic context-aware
escaper&lt;/a&gt;.  There are escaping mechanisms in basically every
toolkit that people use nowadays.  So, if you use Rails or Django or whatever
Java people use.  Then there are, I guarantee you, mechanisms by which you can
escape the content, which you can guarantee that the content is being escaped
correctly when it&amp;rsquo;s delivered.&lt;/p&gt;

&lt;p&gt;As I said however, you have to be absolutely perfect about the way you do this.
You have to ensure that you perfectly escape every piece of output that goes to
the site.&lt;/p&gt;

&lt;p&gt;Unfortunately, it&amp;rsquo;s the case that attackers will spend much more time trying to
find a single tiny hole in your application than you will spend defending your
application to maintain the status quo. You&amp;rsquo;re going to be busy building new
features.  You&amp;rsquo;re not going to be very busy looking at every piece of HTML that
you ever generate and ensuring that the escaping that you do is correct for the
individual context.&lt;/p&gt;

&lt;p&gt;Empirically, we see that people make mistakes, it&amp;rsquo;s simply the case.  And it&amp;rsquo;s
not even the case that you have to make a mistake.  A browser vendor might make
a mistake as well. If you look at old versions of IE, it&amp;rsquo;s very much the case.
That strange things need to be done in order to insure that content isn&amp;rsquo;t
executed as script. They&amp;rsquo;re simply bugs in the way that browsers parse things.&lt;/p&gt;

&lt;p&gt;It&amp;rsquo;s a losing battle, in other words, to ensure that every piece of content is
correctly escaped for every browser that a user might come to your site with,
but it&amp;rsquo;s something that&amp;rsquo;s very difficult to do.&lt;/p&gt;

&lt;p&gt;So, we make mistakes, browser vendors make mistakes.  It&amp;rsquo;d be really nice if we
could simply instruct the browser in some way that this piece of code is valid
and this piece of code is invalid.  I mean for you to execute this piece of
code, but this other thing over here, why don&amp;rsquo;t you leave it alone for a little
while.&lt;/p&gt;

&lt;p&gt;This boils down, I think to the &lt;a href=&quot;http://en.wikipedia.org/wiki/Principle_of_least_privilege&quot;&gt;principle of least privilege&lt;/a&gt;.  The idea
is that every application, or every piece of an application should have the
minimum level of privilege necessary in order to do its job correctly.  This is
really quite common in the UNIX world where you see a process start as root, set
things up, and then immediately fork and drop down with &lt;code&gt;setuid&lt;/code&gt; in order to
have fewer privileges, in order to insure that it doesn&amp;rsquo;t have access to things
that it shouldn&amp;rsquo;t have access to.&lt;/p&gt;

&lt;p&gt;This is why you usually end up with like the MySQL or a PHP user on a variety of
systems.  Those users have fewer privileges than root and the system make sure
that the application runs as that user as opposed to a user with higher
privileges.&lt;/p&gt;

&lt;p&gt;The good thing here is that if you minimize the privilege that an application
has, then when an attacker finds a hole &amp;ndash; and it will be a &amp;ldquo;when&amp;rdquo; not an &amp;ldquo;if&amp;rdquo;
&amp;ndash; then the attacker has a reduced surface area with which to work. They don&amp;rsquo;t
have the ability to, for instance, write directly to the disc. And in that case,
you protected yourself simply by minimizing the value of the &amp;ndash; of this
application as a target.&lt;/p&gt;

&lt;p&gt;Has anyone read &lt;a href=&quot;http://www.amazon.com/exec/obidos/ASIN/0596517742/wrrrldwideweb&quot;&gt;&amp;ldquo;JavaScript: The Good Parts&amp;rdquo; by Douglas Crockford&lt;/a&gt;?
Yes, a good number of you.  I think this actually fits very well into the
concept of least privilege.&lt;/p&gt;

&lt;p&gt;&amp;ldquo;JavaScript: The Good Parts&amp;rdquo; has basically the single theorem that there is a
beautiful language hidden inside of JavaScript.  The JavaScript itself is kind
of large and has become ugly in a variety of ways.  But there&amp;rsquo;s a beautiful core
and if you limit yourself to this core, if you restrict yourself from using some
of the more esoteric features, then you have a much easier language to
understand but also an easier language to program in and to reason about.&lt;/p&gt;

&lt;p&gt;My contention is that you can do the exact same thing for HTML and if you can do
the exact same thing for your applications.  You can explain to the browser that
certain things, even though you would be allowed to do them, shouldn&amp;rsquo;t be
allowed within the context of this individual site.&lt;/p&gt;

&lt;p&gt;The way that you do this is via &lt;a href=&quot;http://www.html5rocks.com/en/tutorials/security/content-security-policy/&quot;&gt;Content Security Policy&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Content Security Policy was &lt;a href=&quot;http://blog.mozilla.org/security/2011/03/22/creating-a-safer-web-with-content-security-policy/&quot;&gt;originally invented by Mozilla about three, four
years ago&lt;/a&gt;.  It was implemented in Mozilla, I believe, Firefox 4
and has been slowly improved and steadily improved since then.  It&amp;rsquo;s now on the
W3C on standards track.  I believe, actually today it will moved from working
draft to candidate recommendation which is the next step would be proposed
recommendation and at that point everyone should implement it.&lt;/p&gt;

&lt;p&gt;Content Security Policy gives you exactly this mechanism.  It allows you to very
&amp;ndash; to very clearly explain to the browser which things on the page, which pieces
of content are intentional and which pieces of content should never be executed.
 It allows you then to &amp;ndash; well, let&amp;rsquo;s look at &lt;code&gt;mikewest.org&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;mikewest.org&lt;/code&gt; is my website and it has a variety of pieces of content.  It
has images, it uses some web fonts, it uses some script and some style.  And we
can very clearly explain to the browser that certain pieces of information or
certain sources of information are trusted. And any other source, if someone was
able to inject content into my website because it is, of course, incredibly high
value then you would be able to very clearly distinguish between the injected
information and the intentional information.&lt;/p&gt;

&lt;p&gt;The policy is an HTTP header it can also be injected as a meta tag in Chrome. It
looks something like this, &lt;code&gt;Content-Security-Policy&lt;/code&gt; is the name of the header
and then we set &amp;ndash; we walk through a variety of directives.  And each of these
directives allows you to very granularly control the information that is
delivered to a website or that the browser should interpret as part of the
website.&lt;/p&gt;

&lt;p&gt;We start out by making it secure by default.  So, we set a &lt;code&gt;default-src&lt;/code&gt; of
&lt;code&gt;'none'&lt;/code&gt;.  This means if we left it at that, then no content would run on the
site whatsoever.  It would render HTML, so the things that are contained within
the &amp;ndash; excuse me, within the website itself but no images would load, the script
would execute, the style would load, no web fonts, no media, no XHR.&lt;/p&gt;

&lt;p&gt;Basically, it turns off anything that could inject the content into the page.
Then we slowly loosen this policy by saying for instance that
&lt;code&gt;mikewestdotorg.hasacdn.net&lt;/code&gt; is a valid source of style.  So, I can load a
stylesheet from this origin.  And if it comes from this origin then the browser
will allow it.  If a style sheet comes from a different origin and is somehow
injected into the page, the browser will simply not execute it, will not render
that information.&lt;/p&gt;

&lt;p&gt;We can skip down to &lt;code&gt;script-src&lt;/code&gt; which does the same thing.  It says
&lt;code&gt;mikewestdotorg.hasacdn.net&lt;/code&gt; and &lt;code&gt;ssl.googleanalytics.com&lt;/code&gt; are both valid
sources of script.  If I load script from these origins they&amp;rsquo;re trusted.  If I
load it from any other origin, it&amp;rsquo;s untrusted, so if someone was able to inject
the script tag into my site they would need to ensure that their malicious
script existed on one of these two servers which will be a very difficult
problem indeed.&lt;/p&gt;

&lt;p&gt;This is a more or less complete list of all of the directives that are available
in &lt;a href=&quot;http://w3.org/TR/CSP/&quot;&gt;Content Security Policy 1.0&lt;/a&gt;.  Content Security Policy 1.0 is going
to &amp;ndash; as I said is going to the next step in the standards track today.  It&amp;rsquo;s
implemented in Firefox.  It&amp;rsquo;s implemented in Chrome.  It&amp;rsquo;s implemented in Safari
6 and IE 10 implements a single directive, so they&amp;rsquo;re working on it.  They&amp;rsquo;re
not quite there yet.&lt;/p&gt;

&lt;p&gt;Opera is participating very heavily in the standards process, so we expect that
Opera will probably be 13 will have something like this but at the moment, it&amp;rsquo;s
&lt;a href=&quot;http://caniuse.com/#feat=contentsecuritypolicy&quot;&gt;across about half the browsers that you&amp;rsquo;ll see on the web&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;default-src&lt;/code&gt;, we talked about &lt;code&gt;script-src&lt;/code&gt;, &lt;code&gt;object-src&lt;/code&gt; allows to control
plug-ins that exist on the sites.  You could say, you know, Flash files only
from this style, images, media allows you to control HTML5 videos, so if I&amp;rsquo;m
loading video information or subtitles or something on those lines that&amp;rsquo;s
controlled the via media source.  &lt;code&gt;frame-src&lt;/code&gt; allows me to determine which items
I can load into frames in a website.  So, I might say that I only want to load
YouTube videos, so I would allow &lt;code&gt;https://youtube.com&lt;/code&gt; as a valid frame source
and no other frame will then render on my page.&lt;/p&gt;

&lt;p&gt;This gives you the ability to then very granularly determine which pieces of
information should be part of your site and which pieces of content or which
sources of content should never be allowed access to your website.&lt;/p&gt;

&lt;p&gt;It has a down side however.  The main &amp;ndash; or not really a down side. I think it&amp;rsquo;s
an up side, but a lot of people see it as a down side so I talk about it that
way.&lt;/p&gt;

&lt;p&gt;The main vulnerability that we see in cross-site scripting attacks is inline
JavaScript. That is I write some &amp;ndash; I request a page in such a way that causes
it to write out the script tag or to write information into a context that gets
executed as script. Content Security Policy takes more or less a &lt;a href=&quot;http://www.youtube.com/watch?v=aCbfMkh940Q&quot;&gt;&amp;ldquo;take off and
nuke it from orbit&amp;rdquo;&lt;/a&gt; approach to inline script: that is, it bans it
completely.&lt;/p&gt;

&lt;p&gt;This is actually, I think a good thing.  It&amp;rsquo;s enforces the strict separation of
content behavior and rendering that we see in HTML, JavaScript and CSS.  We&amp;rsquo;ve
been talking about this for years as best practice, that you should separate
your page out into: an HTML page that has clean mark up, a JavaScript file that
enhances the behavior of the page in some way, and then a script or a CSS file
that enhances the rendering, and makes things look pretty.&lt;/p&gt;

&lt;p&gt;What we see here is in inline &lt;code&gt;script&lt;/code&gt; tag that defines some functionality.  We
see an inline event handler that associates that functionality with a click on a
&lt;code&gt;button&lt;/code&gt;.  And then we see a JavaScript URL that&amp;rsquo;s in a link that associates
again this functionality that we define with the click on a link.&lt;/p&gt;

&lt;p&gt;All of these can be trivially rewritten by extracting the JavaScript out into a
separate JavaScript file, loading that JavaScript file in my HTML and
associating the handler &amp;ndash; the handlers of the events via JavaScript as opposed
to doing it within the content of the mark up.&lt;/p&gt;

&lt;p&gt;This I think is a good thing regardless of whether you use Content Security
Policy.  Again, it gives you this clean separation between your mark up and your
behavior and allows you to edit each independently.  It gives you a very clear
picture of where your behavior is happening and where your mark up is happening.
 And it gives us the ability to very clearly distinguish between code that&amp;rsquo;s
been maliciously injected into your site and code that exists on a trusted
source of information.&lt;/p&gt;

&lt;p&gt;That is, if I have an external JavaScript file the browser can be very clearly
determine what the origin of that file is if on the other hand I have an inline
script.  It&amp;rsquo;s simply impossible for the browser to make a distinction between
inline JavaScript that&amp;rsquo;s been maliciously injected and inline JavaScript that
you intended to have on your page.&lt;/p&gt;

&lt;p&gt;So again, Content Security Policy allows you to reduce the privilege of your
website in a way that protects you from this sort of attack.  It allows you to
say that I&amp;rsquo;m not using inline JavaScript on my site and I don&amp;rsquo;t want inline
JavaScript to ever execute.  This gives you the ability to instruct the browser
to help you out.  The browser can then be your friend. It can help you ensure
that only the information that you&amp;rsquo;ve actually delivered is getting execute in
the context of the website.&lt;/p&gt;

&lt;p&gt;What&amp;rsquo;s also interesting about Content Security Policy is a reporting function.
It&amp;rsquo;s almost never the case that you can cleanly deploy in your Content Security
Policy onto an existing application without breaking something.  Content
Security Policy gives you a mechanism of doing first a reporting mode where you
say okay.  I want to try this policy out on my application.  And you can deploy
it to actual users.&lt;/p&gt;

&lt;p&gt;If you use Content Security Policy report only then the policy will be evaluated
by the browser and will be interpret &amp;ndash; or each load of a resource will be
interpreted against the policy or validated against the policy, if it passes,
great.  If it doesn&amp;rsquo;t pass the load will go through, but it will send to a POST
out to an end point of your specification.  So you specify &lt;code&gt;report-uri&lt;/code&gt; as
&lt;code&gt;example.com/csp-violations&lt;/code&gt; and it will send some JSON to you that it&amp;rsquo;ll help
you identify the things that are breaking on your website or the things that
would break based upon this policy.&lt;/p&gt;

&lt;p&gt;So this gives you a deployment mechanism that&amp;rsquo;s relatively straightforward.  You
deploy a policy as report only.  You look at the reports that are coming in.
You fix bugs on your website that are causing these reports or you tweak the
policy because perhaps there&amp;rsquo;s a section of your website that you didn&amp;rsquo;t
actually look at.&lt;/p&gt;

&lt;p&gt;Once you have a policy in place that&amp;rsquo;s not generating a large number of
violation reports, you can deploy that policy as an active policy.  What&amp;rsquo;s nice
is that you&amp;rsquo;ve actually have a active policy and a reporting policy existing at
the same time, so you can have a very loose policy like this one which simply
says only load resource over HTTPS, that is no mixed content of any sort.  I&amp;rsquo;m
serving my site over HTTPS.  I don&amp;rsquo;t want to load any information over HTTP.
&lt;code&gt;default-src&lt;/code&gt; of &lt;code&gt;https:&lt;/code&gt; will allow you to do that, simply says no source that
isn&amp;rsquo;t HTTPS should be allowed to deliver content.  This is a relatively loose
policy because it says any host that&amp;rsquo;s on HTTPS, so &lt;code&gt;https://evil.com&lt;/code&gt; would
also match but at least it&amp;rsquo;s secure, right?  So that&amp;rsquo;s good.&lt;/p&gt;

&lt;p&gt;What&amp;rsquo;s nice here is that you can deploy this sort of loose policy and the loose
policy is more or less guaranteed to work on your site and you can test the
policy at the same time by setting a report only flag.  So, you can both have
headers active at the same time.&lt;/p&gt;

&lt;p&gt;The CSP report looks like this. As you see it gives you the URL that cause
problems.  It tells you what resource it tried to load.  It tells you the policy
that was active and which directive was violated.  So, it gives you some
information that allows you to debug the problems that you&amp;rsquo;ll see when you start
to deploying CSP to your website.&lt;/p&gt;

&lt;p&gt;You can, of course also use a report in an active policy, so if you deploy a CSP
or a Content Security Policy to your site you want to know if people are
attacking your website and this allows you to send reports based on violations.&lt;/p&gt;

&lt;p&gt;So, once you&amp;rsquo;re sure that all the code that you deliver matches the policy, you
can start getting reports about attacks that are existing against your site.
And this will give you information to help figure out where those attacks are
coming from which can be quite useful.&lt;/p&gt;

&lt;p&gt;There&amp;rsquo;s a good article &amp;ndash; this is just really just scratching the surface of
Content Security Policy.  If you&amp;rsquo;re interested and I really hope you are because
this is the most important thing that&amp;rsquo;s happened in web security I think for the
last two or three years.  &lt;a href=&quot;http://www.html5rocks.com/en/tutorials/security/content-security-policy/&quot;&gt;Content Security Policy on HTML5Rocks&lt;/a&gt;.  You
should go to &lt;a href=&quot;http://www.html5rocks.com/&quot;&gt;HTML5Rocks&lt;/a&gt; anyway by the way.  It&amp;rsquo;s a great website, that
gives you a lot of information about HTML5 and new features that are coming out.&lt;/p&gt;

&lt;p&gt;There&amp;rsquo;s specifically an &lt;a href=&quot;http://www.html5rocks.com/en/tutorials/security/content-security-policy/&quot;&gt;article about Content Security Policy&lt;/a&gt; that I
happen to think is relatively well written.  And it gives you some good
information about how you can start using Content Security Policy, what the
purpose is, how it works and how you can deploy of any websites.&lt;/p&gt;

&lt;p&gt;I think this is really important and I think it&amp;rsquo;s quite &amp;ndash; it&amp;rsquo;s not easy to
deploy this on existing applications, but there&amp;rsquo;s really no reason at all that
you can&amp;rsquo;t deploy it on new applications that you&amp;rsquo;re building.&lt;/p&gt;

&lt;p&gt;So, anytime you start building an application think about the resources that
you&amp;rsquo;re using and think about the ways in which you can restrict the browser from
loading resources that you don&amp;rsquo;t want the browser to load.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://w3.org/TR/CSP11/&quot;&gt;Content Security Policy 1.1&lt;/a&gt; is in editor&amp;rsquo;s draft right now.  I&amp;rsquo;m
working with the standards body on this so if you guys have questions at all
afterwards or if you have suggestions about things that you think could be
added to a policy like this please do let me know.  There&amp;rsquo;s a &amp;ndash; the working
group is the &lt;a href=&quot;http://www.w3.org/2011/webappsec/&quot;&gt;Web Applications Security working group&lt;/a&gt; if you have
any questions at all you can join &lt;a href=&quot;http://lists.w3.org/Archives/Public/public-webappsec/&quot;&gt;public-webappsec@w3.org&lt;/a&gt;
and participate in all the discussion.&lt;/p&gt;

&lt;p&gt;So this is a place that still rapidly in development, so if you have suggestions
we&amp;rsquo;d be very interested in hearing about them.&lt;/p&gt;

&lt;p&gt;So, that&amp;rsquo;s Content Security Policy.  I think it&amp;rsquo;s incredibly important; it&amp;rsquo;s a
really good way to reduce the privileges of a website down to the level that you
actually need in order to do your job.&lt;/p&gt;

&lt;p&gt;Another mechanism that HTML5 is starting to provide that does more or less the
same thing or gives you many of the same ideas is called
&lt;a href=&quot;http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/&quot;&gt;Sandboxing&lt;/a&gt;.  Sandboxing allows you to include an &lt;code&gt;iframe&lt;/code&gt; on your
website in such a way that it runs with reduced privileges.  Again, if we think
about the single origin or the same origin model we have &lt;code&gt;example.com&lt;/code&gt; and
&lt;code&gt;mybank.com&lt;/code&gt;. If &lt;code&gt;example.com&lt;/code&gt; frames &lt;code&gt;mybank.com&lt;/code&gt; so it loads MyBank in a
frame, then it doesn&amp;rsquo;t actually have any access to that frame.  It can&amp;rsquo;t use
JavaScript to reach in to the frame and the bank can&amp;rsquo;t reach out of the frame
into the parent&amp;rsquo;s in order to do any sort of damage.&lt;/p&gt;

&lt;p&gt;This is a good thing and it allows you to include untrusted content on your
website in a way that it can&amp;rsquo;t interfere with your website.  So, the &lt;code&gt;iframe&lt;/code&gt; in
and of itself can act kind of like a sandbox, but if you include same origin
content &amp;ndash; that is, if &lt;code&gt;example.com&lt;/code&gt; includes a page from &lt;code&gt;example.com&lt;/code&gt; in a
frame for example a comment or something along these lines, then, because they
exist in the same origin, the parent can reach down into the child and the child
can reach up into the parent.&lt;/p&gt;

&lt;p&gt;Both of these might be useful, but generally speaking they&amp;rsquo;re not.  Generally,
if you&amp;rsquo;re including content in an &lt;code&gt;iframe&lt;/code&gt; you wanted to be in someway separate
from the page that exist within. Sandboxing is an at &amp;ndash; or sandbox is an
attribute that you can apply to an &lt;code&gt;iframe&lt;/code&gt; but does exactly this.&lt;/p&gt;

&lt;p&gt;It works very similarly to browsers that you see these days, where you have a
brow &amp;ndash; well, I&amp;rsquo;ll talk about this eventually.&lt;/p&gt;

&lt;p&gt;The attribute is quite straightforward.  If you apply a &lt;code&gt;sandbox&lt;/code&gt; attribute to
an &lt;code&gt;iframe&lt;/code&gt; then a couple of things happen immediately.  First no plug-ins can
be loaded within this &lt;code&gt;iframe&lt;/code&gt;, no script can be loaded, forms cannot be
submitted, top level navigation simply won&amp;rsquo;t work. That is, if I apply
&lt;code&gt;target=&quot;_blank&quot;&lt;/code&gt; or &lt;code&gt;target=&quot;_top&quot;&lt;/code&gt; to a link within an &lt;code&gt;iframe&lt;/code&gt; usually
that&amp;rsquo;ll navigate my entire page, the window as opposed to the frame, sandboxing
blocks this. No pops-ups, no &lt;code&gt;window.open&lt;/code&gt;, modal dialogs, things along these
lines can&amp;rsquo;t be created from within the context of the sandboxed &lt;code&gt;iframe&lt;/code&gt;.  No
auto-play.  So, if I have video within this link auto-play won&amp;rsquo;t work, no
pointer lock and no seamless &lt;code&gt;iframe&lt;/code&gt;s.&lt;/p&gt;

&lt;p&gt;What&amp;rsquo;s really important and what I failed to write here is that sandboxing
actually will push the frame into a completely separate origin, regardless of
from where it was loaded. That is if I load the page from &lt;code&gt;example.com&lt;/code&gt; in a
frame it won&amp;rsquo;t act as though it&amp;rsquo;s &lt;code&gt;example.com&lt;/code&gt; or won&amp;rsquo;t act as though that&amp;rsquo;s
its origin.  It will instead have what&amp;rsquo;s called a &amp;ldquo;unique origin&amp;rdquo; and a &lt;a href=&quot;http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#sandboxOrigin&quot;&gt;unique
origin&lt;/a&gt; is one that matches no other origin ever.  That is, it
has no access to any data from any origin at all.&lt;/p&gt;

&lt;p&gt;This can be quite useful because it gives you the ability to load content &amp;ndash;
load untrusted content in a way that simply can&amp;rsquo;t do any damage at all to your
website.  If script can&amp;rsquo;t execute in the context, it doesn&amp;rsquo;t matter if someone
can maliciously inject script because it&amp;rsquo;s simply won&amp;rsquo;t execute, they won&amp;rsquo;t be
able to navigate your page, they won&amp;rsquo;t be able to create pop-up&amp;rsquo;s, they won&amp;rsquo;t be
able to move or bust out of the frame and move users through an area that they
weren&amp;rsquo;t trusted to do.&lt;/p&gt;

&lt;p&gt;You can of course loosen these restrictions and this would be the minimal
sandbox that you can create.  There&amp;rsquo;s still no plug-ins and there&amp;rsquo;s still no
seamless &lt;code&gt;iframe&lt;/code&gt;s, but everything else can be enabled.  What&amp;rsquo;s nice about this
is that you can create a sandbox that gives only the minimum level of privilege
necessary to a website, in order for it to do the work that website needs to do.&lt;/p&gt;

&lt;p&gt;This concept allows you to separate the concerns within your application, so you
can actually break your application into a variety of pieces, and now we&amp;rsquo;ll come
back to the concept of the browser.&lt;/p&gt;

&lt;p&gt;If you look at how Chrome works, you have a browser process that has all the
privileges in the world, all the privileges of a normal application running on
your system.  They can go out through the web and get information, they can go
to your disk and get information or write information to random files on your
disk, it can execute arbitrary code and so on.  It&amp;rsquo;s an application with all the
privilege in the world but it&amp;rsquo;s a very thin application, it doesn&amp;rsquo;t do much,
instead a lot of the work is delegated out to renderer processes.  More or less
you can think of every tab is a separate renderer process.&lt;/p&gt;

&lt;p&gt;The renderer process is ask the browser for information, the browser determines
whether or not the renderer should get the information, delivers the information
to the renderer, allows it to do its work and awaits a response.  The renderer
grabs HTML untrusted content from the web, does a lot processing on it in order
to build a render tree and then sends that tree back up to the browser once it&amp;rsquo;s
verified that it&amp;rsquo;s trusted.&lt;/p&gt;

&lt;p&gt;What this means is that the renderer doesn&amp;rsquo;t actually need any of these
privileges.  It doesn&amp;rsquo;t need to go out to the web, the browser does that for it.
 It doesn&amp;rsquo;t needs to write things to the disk&amp;ndash;again, that&amp;rsquo;s what the browser is
there for.&lt;/p&gt;

&lt;p&gt;So, you separate the privileges of your web app or you take the application, you
break it into pieces and give each piece only those privileges that are actually
necessary in order for it to do its job.  This allows you to build applications
in such a way that each components can live inside of a sandboxed &lt;code&gt;iframe&lt;/code&gt;.  So,
what you would basically end up doing is creating an API for your application
based on messaging. So it would be asynchronous API by which you pass messages
into a sandbox, allow that sandbox to do some sort of interesting work based
upon the message that you passed in.  And then ask the sandbox to send
information back up to the parent in order to delegate that work to another
process or to do some sort of rendering out to the website.  This could look
something like this, so here&amp;rsquo;s a toy example of how this might work.&lt;/p&gt;

&lt;p&gt;We have a Content Security Policy associated with this page that says
&lt;code&gt;script-src&lt;/code&gt; of &lt;code&gt;'self'&lt;/code&gt;, so only script that&amp;rsquo;s loaded from my current origin
can be executed within the context of this page, of this protected resource.  We
load a script called &lt;code&gt;main.js&lt;/code&gt; and we have an &lt;code&gt;iframe&lt;/code&gt; on the page that loads
&lt;code&gt;sandbox.html&lt;/code&gt;.  The sandbox allows scripts, but allows nothing else.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;main.js&lt;/code&gt; looks something like this and we&amp;rsquo;ll talk about it in a little bit more
detail later on, but the idea is simply that we bind an event handler to the
&lt;code&gt;button&lt;/code&gt; and when I click on the &lt;code&gt;button&lt;/code&gt;, we pass a message into the &lt;code&gt;iframe&lt;/code&gt;
and we listen for a response, so we listen for messages on the page and we pass
messages into the &lt;code&gt;iframe&lt;/code&gt;.  This is a very, very simple messaging API using
&lt;code&gt;window.&lt;/code&gt; &amp;ndash; I&amp;rsquo;m sorry, &lt;code&gt;iframe.contentwindow.postmessage&lt;/code&gt;.  So, we grab the
&lt;code&gt;iframe&lt;/code&gt;, we grab its content and then we post the message to that.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;iframe&lt;/code&gt; looks something like this. The &lt;code&gt;iframe&lt;/code&gt; loads in
&lt;a href=&quot;http://handlebarsjs.com/&quot;&gt;Handlebars&lt;/a&gt; which is a templating library.  And it&amp;rsquo;s a templating
library that does a couple of things for performance reasons that are a little
bit dangerous.  Specifically it&amp;rsquo;s uses &lt;code&gt;eval&lt;/code&gt; in order to generate a function
and executes this function in order to actually do the work of templating.  So,
it&amp;rsquo;s takes untrusted code. It evaluates in some sort of context and creates a
function which could be executed.  This is a bit dangerous and Content Security
Policy of &lt;code&gt;'self'&lt;/code&gt; will actually block you from doing this. It&amp;rsquo;ll block you from
using untrusted content in the context of an &lt;code&gt;eval&lt;/code&gt;.  It&amp;rsquo;ll block &lt;code&gt;eval&lt;/code&gt;
entirely in fact.&lt;/p&gt;

&lt;p&gt;This means that Handlebars could not execute inside the context of the page. So,
if I look at &lt;code&gt;index.html&lt;/code&gt;, Content Security Policy will actually block
Handlebars from executing.  However inside the context of the sandbox there is
no Content Security Policy because I haven&amp;rsquo;t set one: it&amp;rsquo;s a completely separate
HTML document.  It&amp;rsquo;s also a document that doesn&amp;rsquo;t have access to any of the
information that was in the main page, that was in the &lt;code&gt;index.html&lt;/code&gt;, so I can
more or less without issue allow JavaScript to execute in this context and allow
potentially dangerous JavaScript to execute in this context without worrying
about it stealing my information because there&amp;rsquo;s no information in this context
for it to steal.&lt;/p&gt;

&lt;p&gt;It listens for events or listens for message events, grabs the context that was
passed in and uses that context to populate a template, so Handlebars does its
work.  It uses &lt;code&gt;eval&lt;/code&gt;, it uses dangerous but very performant code in order to do
some templating and then I can pass that HTML back up to my parent frame and in
the parent frame you&amp;rsquo;ll see that it will actually using
&lt;code&gt;document.body.innerHTML&lt;/code&gt; to write this content out to the page.&lt;/p&gt;

&lt;p&gt;This is incredibly dangerous, you should really never do this inside the context
of an application because &lt;code&gt;innerHTML&lt;/code&gt; will execute scripts, so if I have a
script tag that&amp;rsquo;s pushed into a page via &lt;code&gt;innerHTML&lt;/code&gt; that will execute.&lt;/p&gt;

&lt;p&gt;The reason that I can do it in this context is because the page is protected by
Content Security Policy.  It says that even if dangerous content has been
injected into the page, no script will actually run.  The worse that an attacker
could do in this case is deface my website by making the sandbox… If they were
able to find a vulnerability in the sandbox the worst that they could do is
generate bad HTML, they couldn&amp;rsquo;t generate dangerous HTML that actually execute a
script and exfiltrated information.&lt;/p&gt;

&lt;p&gt;This gives you the ability to separate your application into pieces that need
special privileges and pieces that don&amp;rsquo;t need those privileges.  It allows you
to say that the main application is protected by a very strict Content Security
Policy, the pieces of the application that wouldn&amp;rsquo;t fit into that policy or that
would have issues. Maybe it&amp;rsquo;s a legacy application that you have very &amp;ndash; that
you have a very hard time rewriting for these piece &amp;ndash; for this new style of
programming.  You put that into a sandbox, you allow it execute within the
context of that sandbox and you build a very thin messaging API on top of the
sandbox and on top of the application itself in order to pass messages back and
forth between these two components.&lt;/p&gt;

&lt;p&gt;You separate out the concerns and you say that the one piece of the application
should be able to execute script, which should be able to execute potentially
dangerous scripts and the other piece of the application has no need of those
information whatsoever.  It should only rely upon this new API that you built.&lt;/p&gt;

&lt;p&gt;This gives you a really nice way of extracting pieces of your &amp;ndash; pieces of your
application but you don&amp;rsquo;t &amp;ndash; that don&amp;rsquo;t need privileges and to reduce these
privileges down to the minimum level that they actually need in order to do
their job.&lt;/p&gt;

&lt;p&gt;There&amp;rsquo;s one other thing that a sandbox can potentially be useful for and this
will be available in, we&amp;rsquo;ll say the near future. It&amp;rsquo;s in Chrome Canary right now
but it&amp;rsquo;s not quite there yet in other browsers. Specifically I&amp;rsquo;m talking about
the &lt;a href=&quot;http://www.whatwg.org/specs/web-apps/current-work/multipage/the-iframe-element.html#attr-iframe-seamless&quot;&gt;&lt;code&gt;seamless&lt;/code&gt; attribute&lt;/a&gt; and the &lt;a href=&quot;http://www.whatwg.org/specs/web-apps/current-work/multipage/the-iframe-element.html#attr-iframe-srcdoc&quot;&gt;&lt;code&gt;srcdoc&lt;/code&gt; attribute&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;These allow me first, to create an &lt;code&gt;iframe&lt;/code&gt; that seamlessly blends in with the
content of my page.  One of the things that you see with a normal &lt;code&gt;iframe&lt;/code&gt; is;
that it&amp;rsquo;s a completely separate document.  So, it has its own stylesheets, has
its own JavaScript and so on. The seamless attribute allows me to create an
&lt;code&gt;iframe&lt;/code&gt; in my page and allows CSS to flow down into that &lt;code&gt;iframe&lt;/code&gt;.  So, if I
have a paragraph in that &lt;code&gt;iframe&lt;/code&gt;, it&amp;rsquo;s going to use the paragraph style from my
documents not from its own &amp;ndash; or it can override them of course but the CSS
flows down into that document or into the &lt;code&gt;iframe&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The other nice thing is that the seamless &lt;code&gt;iframe&lt;/code&gt; shrink wraps itself to the
size of the content on the page.  So, instead of specifying that I have an
&lt;code&gt;iframe&lt;/code&gt; that&amp;rsquo;s, you know, 500 by 500.  I can simply say it&amp;rsquo;s a seamless
&lt;code&gt;iframe&lt;/code&gt; which means it will only be as big as the content, that&amp;rsquo;s been pushed
into that &lt;code&gt;iframe&lt;/code&gt;.  This is really quite nice.&lt;/p&gt;

&lt;p&gt;It works with the same-origin policy.  So, if I load content from my origin then
CSS flows down into it.  If I load content from my separate origin, CSS won&amp;rsquo;t
flow into it because I can actually use CSS to extract information from that
page with some of the new selector attributes that are out.&lt;/p&gt;

&lt;p&gt;What you also see here is a &lt;code&gt;srcdoc&lt;/code&gt; attribute.  This means, instead of making
an HTTP request down to a server to get information to populate this page or
this &lt;code&gt;iframe&lt;/code&gt;.  I can populate it simply by adding information to an attribute.
This means that all I have to do is correctly escape information for a single
context.  I can look at the information that the user has given me for example
for a comment on a webpage. I can escape that in such a way that it works within
the context of an attribute which is easier than trying to escape it for any
context whatsoever.  And that information is then used as the body of this
&lt;code&gt;iframe&lt;/code&gt;. So, instead of making an HTTP request, I can specify the content of
the &lt;code&gt;iframe&lt;/code&gt; directly within the context to the page itself.&lt;/p&gt;

&lt;p&gt;For something like comments, this can work quite well because what I can then do
is sandbox this &lt;code&gt;iframe&lt;/code&gt;.  So, that even if I completely screwed up when
escaping the information.  I can ensure that no plug-ins can run, no script can
run and so on.  But the content that&amp;rsquo;s actually being delivered into this
&lt;code&gt;iframe&lt;/code&gt; can be executed in a very safe way.  The sandbox attribute is supported
in WebKit quite well.  It&amp;rsquo;s in &amp;ndash; it&amp;rsquo;s been in &amp;ndash; it&amp;rsquo;s been in Chrome for quite
some time.  It&amp;rsquo;s in Safari 6 and it will be in new webkit browsers to come out.
It&amp;rsquo;s just been supported inside Firefox.  So, I think, Firefox 18 now has
support for the &lt;code&gt;sandbox&lt;/code&gt; attribute and it&amp;rsquo;s supported in IE 10.&lt;/p&gt;

&lt;p&gt;So, it&amp;rsquo;s &lt;a href=&quot;http://caniuse.com/#feat=iframe-sandbox&quot;&gt;in the new browsers that are coming out&lt;/a&gt;, but it has
really no downside for old applications.  They will be just as insecure as they
were before if you&amp;rsquo;re using this sort of attribute.  With that, I think I&amp;rsquo;ll ask
if anyone has any questions.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;d really before &amp;ndash; actually before I would suggest you go out and read &lt;a href=&quot;http://www.html5rocks.com/en/tutorials/security/content-security-policy/&quot;&gt;the
HTML5Rocks article&lt;/a&gt;.  I think Content Security Policy is the most
important thing that&amp;rsquo;s happened again in web security for quite some time.  I
think it&amp;rsquo;s really quite important and I would be thrilled if even one of you
started implementing Content Security Policy on your pages.  If you have any
questions about that at all, please drop me an email.  Please contact me &lt;a href=&quot;https://twitter.com/mikewest&quot;&gt;on
Twitter&lt;/a&gt; or in &lt;a href=&quot;https://plus.google.com/104437754419996754779/posts&quot;&gt;G+&lt;/a&gt; and if you have any questions right now.  I&amp;rsquo;d
be really happy to answer them.  Do we have like a mic anywhere?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; Yeah.  Yeah.  Yeah.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; Oh, yeah.  It&amp;rsquo;s over there.  Great.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; So, with the Content Security Policy, you said that you can&amp;rsquo;t also have
inline JavaScript anymore.  What about style, inline styles?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; It&amp;rsquo;s the same story.  There is a mechanism by which you can
allow inline style if you really need it.  So, if you have a legacy application
and you simply don&amp;rsquo;t have the time to rewrite it, you can allow inline style but
by default.  It&amp;rsquo;s &amp;ndash; if you set a &lt;code&gt;style-src&lt;/code&gt; then inline style will also be
removed because it&amp;rsquo;s just as dangerous as inline script.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; I agree.  Thanks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; Cool.  Great.  Thank you very much.  Oh, there was &amp;ndash; there
was another &amp;ndash; sorry.  There was another question.  If you have actually &amp;ndash; if
you have question just come up and ask.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; [INDISTINCT]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; The question is…&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo;&lt;/strong&gt; [INDISTINCT]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;raquo; MIKE WEST:&lt;/strong&gt; Yeah.  So, the question is: First of all, this looks
difficult.  So, you&amp;rsquo;re talking about sandboxing, correct?  Yeah.  So, building
this sort of API is work and you have to look at your application and determine
what the APIs actually are; what the components are and then build some sort of
messaging framework that pushes messages back and forth between various frames.&lt;/p&gt;

&lt;p&gt;You&amp;rsquo;re entirely correct.  It is more difficult than writing an application in
the current style, where you just had everything in a big block that all
executes in the same context.  It is more difficult and it &amp;ndash; I do think it&amp;rsquo;s
the case that frameworks will start to pick up that work.&lt;/p&gt;

&lt;p&gt;We see sandbox now being deployed in enough browsers that I think it will be
interesting for frameworks to start building things out on this way.  Until now,
it&amp;rsquo;s only been available in webkit which has made it less attractive for
framework developers.&lt;/p&gt;

&lt;p&gt;But this is something, if you look at Chrome applications or Chrome extensions.
This is something that we&amp;rsquo;re starting to force developers to do now.  We use it
all throughout Chrome and this is a mechanism of building applications that we
think has such good security characteristics that it&amp;rsquo;s worth the effort for us
to start asking people to develop in this way.&lt;/p&gt;

&lt;p&gt;You&amp;rsquo;re entirely correct, it&amp;rsquo;s more difficult.  My contention is simply that the
benefits outweigh the difficulty.&lt;/p&gt;

&lt;p&gt;It won&amp;rsquo;t be the case for every application, but a good example would be the
&lt;a href=&quot;http://youtu.be/GBxv8SaX0gg?t=17m22s&quot;&gt;office document reader inside of Chrome OS&lt;/a&gt;.  So, the office document
reader takes untrusted documents in &lt;code&gt;.doc&lt;/code&gt; format, parses them with JavaScript
and then renders them to the page.  And it does it in exactly this style where
you have a sandbox renderer that takes information.  So, you pass a document
into that renderer.  It does this work, it uses all this untrusted code or
evaluates untrusted code and then pass this information back to it&amp;rsquo;s parents in
a way that it doesn&amp;rsquo;t create new security vulnerabilities.&lt;/p&gt;

&lt;p&gt;So, it is difficult.  It&amp;rsquo;s not the easiest thing in the world and I don&amp;rsquo;t think
I would be ever claim that it is.  My claim is simply that the difficulty is
worth it because it gives you such good security characteristics.&lt;/p&gt;

&lt;p&gt;You know this piece of your application, even if it&amp;rsquo;s compromised, even if you
made huge mistakes, can&amp;rsquo;t access the information that is secure inside the
context of the non-sandbox piece of the application.  So, it&amp;rsquo;s difficult
problem, I agree with you but it&amp;rsquo;s one that I think that&amp;rsquo;s worth addressing.&lt;/p&gt;

&lt;p&gt;All right.  Thank you very much for your time.&lt;/p&gt;

&lt;p&gt;If you have any questions, I&amp;rsquo;ll probably be at the Google booth downstairs for a
lot of the time.  Actually, one more thing, there&amp;rsquo;s a talk in this room at I
think 4:00 &amp;ndash; I think 4:40 called something along the lines of &lt;a href=&quot;http://devoxx.com/display/DV12/Defensible+Development+with+Secure+HTTP+Headers&quot;&gt;Development with
Secure HTTP headers&lt;/a&gt;.  I think it&amp;rsquo;s going to be worthwhile.  So,
if you go &amp;ndash; if you&amp;rsquo;re interested at all in the other things that you can do,
other things that you can do, other things that you can instruct your browser
about in order to make your applications more secure.  I&amp;rsquo;d really suggest that
you get to that talk.  I think it&amp;rsquo;s been given by &lt;a href=&quot;https://twitter.com/thinksec&quot;&gt;Frank Kim
(@thinksec)&lt;/a&gt; and it should be really interesting.  So, 4:40, this
room, I&amp;rsquo;ll be here and I hope you guys are too.&lt;/p&gt;

&lt;p&gt;So, thank you very much!&lt;/p&gt;
</content>
    </entry>

    
    <entry>
        <title type='text'>Content Security Policy: Feature Detection</title>
        <link rel="alternate" href="https://mikewest.org/2012/05/content-security-policy-feature-detection" />
        <id>https://mikewest.org/2012/05/content-security-policy-feature-detection</id>
        <updated>2012-05-02T00:00:00+02:00</updated>
        <published>2012-05-02T00:00:00+02:00</published>
        <content type='html'>&lt;p&gt;&lt;a href=&quot;http://angularjs.org/&quot;&gt;AngularJS&lt;/a&gt;&amp;rsquo;s &lt;a href=&quot;https://groups.google.com/forum/?fromgroups#!topic/angular/NUT9q_fjMJQ&quot;&gt;latest release candidate&lt;/a&gt; is the first
framework I&amp;rsquo;ve seen that cleanly supports a &lt;a href=&quot;https://mikewest.org/2011/10/content-security-policy-a-primer&quot;&gt;content security policy&lt;/a&gt;
that restricts usage of &lt;code&gt;eval()&lt;/code&gt;, &lt;code&gt;new Function()&lt;/code&gt;, and the like. I&amp;rsquo;m thrilled
to see this happening, and it&amp;rsquo;s a testament to the priority that the Angular
developers place on security. CSP is quite simply one the best XSS-protection
mechanisms available to developers these days in modern browsers. The more
frameworks that hop on board, the faster sites can start adopting CSP, and
the safer we&amp;rsquo;ll all be on the net.&lt;/p&gt;

&lt;p&gt;All that said, the implementation isn&amp;rsquo;t as complete as it could be. Angular
requires that the developer manually opt into CSP-friendly mode via the
&lt;a href=&quot;http://docs.angularjs.org/api/angular.module.ng.$compileProvider.directive.ngCsp&quot;&gt;&lt;code&gt;ng-csp&lt;/code&gt;&lt;/a&gt; directive. This is error-prone at best, and introduces
complexity that would be better hidden away inside the framework. The Angular
developers recognize this shortfall, and are &lt;a href=&quot;https://twitter.com/#!/IgorMinar/status/197329318249111552&quot;&gt;explicitly requesting&lt;/a&gt;
some sort of feature detection API that would allow frameworks to query the
currently active policy to determine its boundaries, and fork their
implementation accordingly.&lt;/p&gt;

&lt;p&gt;This does seem like a great addition to the spec; I&amp;rsquo;d suggest the following
implementation:&lt;/p&gt;

&lt;p&gt;Add &lt;code&gt;document.[prefix]contentSecurityPolicy&lt;/code&gt; as an object that exists in
browsers that support CSP. This would enable trivial feature detection of CSP
as a whole, which would enable frameworks to make intelligent decisions about
how to proceed through the following use cases:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Is a policy enabled? If not, perhaps I’d like to set one via &lt;code&gt;meta&lt;/code&gt;
injection.&lt;/p&gt;

    &lt;p&gt;&lt;code&gt;document.contentSecurityPolicy.active&lt;/code&gt; is a boolean property: &lt;code&gt;true&lt;/code&gt; if
a policy is set, &lt;code&gt;false&lt;/code&gt; otherwise.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Can I execute &lt;code&gt;eval()&lt;/code&gt; or use &lt;code&gt;new Function()&lt;/code&gt;?&lt;/p&gt;

    &lt;p&gt;&lt;code&gt;document.contentSecurityPolicy.isWhitelisted('script-src', 'unsafe-eval')&lt;/code&gt;
returns &lt;code&gt;true&lt;/code&gt; if &lt;code&gt;unsafe-eval&lt;/code&gt; has been defined for the &lt;code&gt;script-src&lt;/code&gt;
directive.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Can I embed a &lt;code&gt;data:&lt;/code&gt; image or frame?&lt;/p&gt;

    &lt;p&gt;&lt;code&gt;document.contentSecurityPolicy.isWhitelisted('image-src', 'data:')&lt;/code&gt; and
&lt;code&gt;document.contentSecurityPolicy.isWhitelisted('frame-src', 'data:')&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Can I include Google Analytics?&lt;/p&gt;

    &lt;p&gt;&lt;code&gt;document.contentSecurityPolicy.isWhitelisted('script-src', 'https://ssl.google-analytics.com')&lt;/code&gt;
(Note that &lt;code&gt;isWhitelisted&lt;/code&gt; should do the hard work of dealing with
wildcards. This example should return &lt;code&gt;true&lt;/code&gt; if &lt;code&gt;*.google-analytics.com&lt;/code&gt;
is whitelisted.)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Are reports being sent? If so, where are they going?&lt;/p&gt;

    &lt;p&gt;The &lt;code&gt;document.contentSecurityPolicy.reportUri&lt;/code&gt; property is either
&lt;code&gt;undefined&lt;/code&gt; if no &lt;code&gt;report-uri&lt;/code&gt; directive is set, and a URI if the
directive is set.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This seems like a reasonable first pass at a strawman for discussion. Thanks to
&lt;a href=&quot;http://paulirish.com/&quot;&gt;Paul Irish&lt;/a&gt;, &lt;a href=&quot;http://ericbidelman.com/&quot;&gt;Eric Bidelman&lt;/a&gt;, and &lt;a href=&quot;http://petelepage.com/&quot;&gt;Pete LePage&lt;/a&gt; for
walking through this with me.&lt;/p&gt;

&lt;p&gt;What do you think?&lt;/p&gt;

</content>
    </entry>

    
    <entry>
        <title type='text'>Chrome connects to three random domains at startup.</title>
        <link rel="alternate" href="https://mikewest.org/2012/02/chrome-connects-to-three-random-domains-at-startup" />
        <id>https://mikewest.org/2012/02/chrome-connects-to-three-random-domains-at-startup</id>
        <updated>2012-02-18T00:00:00+01:00</updated>
        <published>2012-02-18T00:00:00+01:00</published>
        <content type='html'>&lt;p&gt;When you start Chrome, it attempts to connect to three random domains like &lt;code&gt;http://aghepodlln/&lt;/code&gt; or &lt;code&gt;http://lkhjasdnpr/&lt;/code&gt;. I&amp;rsquo;ve seen a &lt;a href=&quot;http://stackoverflow.com/questions/7464378/why-is-google-chrome-pinging-mdioussrvd-and-other-random-hosts-that-dont-reso&quot;&gt;few&lt;/a&gt; &lt;a href=&quot;http://www.freesmug.org/forum/t-433541/chromium-chrome-and-mysterious-server-connections&quot;&gt;theories&lt;/a&gt; about why exactly this happens that brush up against the nefarious. The true rationale is incredibly mundane: hopefully this short summary will clear things up.&lt;/p&gt;

&lt;p&gt;The goal of the requests is to determine if you&amp;rsquo;re currently on a network that intercepts and redirects requests for nonexistent hostnames. For example, it&amp;rsquo;s not at all uncommon for ISP to transparently redirect failed DNS lookups in order to convert requests like &lt;code&gt;http://text/&lt;/code&gt; into requests for &lt;code&gt;http://your.helpful.isp/search?q=text&lt;/code&gt;. Leaving aside a discussion of the rightness or wrongness of these &amp;ldquo;helpful&amp;rdquo; activities, this behavior causes problems for Chrome. Specifically, it breaks some heuristics the Omnibox uses to determine whether a user means to &lt;em&gt;search&lt;/em&gt; for a specific term, or to visit a non-standard domain name.&lt;/p&gt;

&lt;p&gt;Google&amp;rsquo;s internal network is a good example of how this can cause problems. Internally, a short-link service named &amp;ldquo;go&amp;rdquo; makes sharing memorable links straightforward. If I type &amp;ldquo;go&amp;rdquo; in Chrome&amp;rsquo;s Omnibox and hit enter, it&amp;rsquo;s not exactly clear whether I mean to visit &lt;code&gt;http://go/&lt;/code&gt; or to search for &amp;ldquo;Go&amp;rdquo; (which is an interesting programming language, by the way). Chrome does its best to do The Right Thing™ in response to this sort of user input by executing a search, and then, in the background, executing a &lt;code&gt;HEAD&lt;/code&gt; request for the potential domain. If the server responds, Chrome will display an infobar, asking if you meant to navigate to &lt;code&gt;http://go/&lt;/code&gt;, and it will remember your response for future reference.&lt;/p&gt;

&lt;p&gt;As you can see, this feature is completely broken if your ISP intercepts all such requests: you&amp;rsquo;d get infobars on every one-word search. So Chrome checks things out at startup, and whenever your IP address changes. And, Chrome is beautifully open-source, so let&amp;rsquo;s take a quick look at the very straightforward implementation:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://code.google.com/codesearch#OAMlx_jo-ck/src/chrome/browser/intranet_redirect_detector.h&amp;amp;exact_package=chromium&amp;amp;ct=rc&amp;amp;cd=1&amp;amp;sq=&quot;&gt;&lt;code&gt;IntranetRedirectDetector&lt;/code&gt;&lt;/a&gt; is the place to start. When Chrome starts up, it creates an &lt;code&gt;IntranetRedirectorDetector&lt;/code&gt; object. This sets up a short delay (currently hard-coded to 7 seconds) in order to ensure that it doesn&amp;rsquo;t get in the way of time-critical startup activities, and then calls &lt;a href=&quot;http://code.google.com/codesearch#OAMlx_jo-ck/src/chrome/browser/intranet_redirect_detector.cc&amp;amp;l=63&quot;&gt;&lt;code&gt;IntranetRedirectDetector::FinishSleep()&lt;/code&gt;&lt;/a&gt; where the real work begins. This method &lt;a href=&quot;http://code.google.com/codesearch#OAMlx_jo-ck/src/chrome/browser/intranet_redirect_detector.cc&amp;amp;l=79&quot;&gt;generates three random domain names&lt;/a&gt;, and kicks off asynchronous &lt;code&gt;HEAD&lt;/code&gt; requests to each in such a way that &lt;a href=&quot;http://code.google.com/codesearch#OAMlx_jo-ck/src/chrome/browser/intranet_redirect_detector.cc&amp;amp;l=87&quot;&gt;they don&amp;rsquo;t generate cache entries, and don&amp;rsquo;t save cookies&lt;/a&gt;. As each of these requests completes, &lt;a href=&quot;http://code.google.com/codesearch#OAMlx_jo-ck/src/chrome/browser/intranet_redirect_detector.cc&amp;amp;l=95&quot;&gt;&lt;code&gt;IntranetRedirectDetector::OnURLFetchComplete()&lt;/code&gt;&lt;/a&gt; is called to record the result. If any two of the three requests resolve to the same host, that host is stored as the network&amp;rsquo;s &amp;ldquo;redirect origin&amp;rdquo;. Easy.&lt;/p&gt;

&lt;p&gt;This information is used in &lt;a href=&quot;http://code.google.com/codesearch#OAMlx_jo-ck/src/chrome/browser/alternate_nav_url_fetcher.cc&amp;amp;l=214&quot;&gt;&lt;code&gt;AlternateNavURLFetcher&lt;/code&gt;&lt;/a&gt; to determine whether or not an infobar should be shown for a specific Omnibox-generated search. If the &lt;code&gt;HEAD&lt;/code&gt; request returns the same site as the redirect origin Chrome saw at startup, then it&amp;rsquo;s ignored. If it&amp;rsquo;s a different origin, then a helpful infobar might be in order.&lt;/p&gt;

&lt;p&gt;So there you have it. Chrome makes three requests to random domains just after startup in order to provide its Omnibox heuristics with enough information to correctly work out a user&amp;rsquo;s intent. These requests are not sending your valuable data anywhere for nefarious purposes, nor are they useful for tracking purposes. The requests happen in order to fix &lt;a href=&quot;http://crbug.com/18942&quot;&gt;crbug.com/18942&lt;/a&gt;, and for no other reason.&lt;/p&gt;

</content>
    </entry>

    
    <entry>
        <title type='text'>Nerdy New Year</title>
        <link rel="alternate" href="https://mikewest.org/2011/12/nerdy-new-year" />
        <id>https://mikewest.org/2011/12/nerdy-new-year</id>
        <updated>2011-12-31T00:00:00+01:00</updated>
        <published>2011-12-31T00:00:00+01:00</published>
        <content type='html'>&lt;p&gt;New Year&amp;rsquo;s resolutions come in all shapes and sizes; if you&amp;rsquo;re a web
developer stuck for good ideas of things you could do to improve the world
(or at least the tiny chunk of it that&amp;rsquo;s concerned with web performance and
security) I&amp;rsquo;d like to propose two: secure user&amp;rsquo;s connections to all your
websites, and use a cookieless domain for static assets.&lt;/p&gt;

&lt;h2 id=&quot;ssl-everywhere&quot;&gt;SSL Everywhere.&lt;/h2&gt;

&lt;p&gt;If you look closely, you&amp;rsquo;ll notice that &lt;code&gt;mikewest.org&lt;/code&gt; is being served via a
secure connection: &lt;code&gt;https&lt;/code&gt; rather than &lt;code&gt;http&lt;/code&gt;. This is a Good Thing™, for
reasons which I explored &lt;a href=&quot;https://mikewest.org/2011/10/http-strict-transport-security-and-you&quot;&gt;earlier this year&lt;/a&gt;. I&amp;rsquo;d like to suggest that each
of you pop open Firefox (yes, Firefox) and head to &lt;a href=&quot;https://www.startssl.com/&quot;&gt;StartSSL&lt;/a&gt; where you can,
&lt;em&gt;for free&lt;/em&gt;, create an account, verify your ownership of a domain, and generate
an SSL certificate.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;ve moved to StartSSL for every domain I own that hosts a website. It&amp;rsquo;s
trivially easy, very well supported (I&amp;rsquo;ve never waited more than 18 hours for a
response to a support request), and works well in every browser I care about.
Moreover, it&amp;rsquo;s run by real people who you can email. I&amp;rsquo;ve gotten responses from
the founder himself at two in the morning; the service is brilliant.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;d suggest, actually, going through the extra step of verifying your identity
with them so that you can generate wildcard certificates, and certificates
with DNS alt names: both will make it easier for you to host SSL websites
without the annoyance of setting up separate IP addresses for each host.
They charge $59.90 for the verification, at which point you can create as many
certificates as you like. It&amp;rsquo;s a heck of a deal.&lt;/p&gt;

&lt;p&gt;And hey, while you&amp;rsquo;re at it, start serving &lt;a href=&quot;https://mikewest.org/2011/10/http-strict-transport-security-and-you&quot;&gt;&lt;code&gt;Strict-Transport-Security&lt;/code&gt;&lt;/a&gt;
headers too!&lt;/p&gt;

&lt;h2 id=&quot;cookieless-domains-for-static-assets&quot;&gt;Cookieless domains for static assets&lt;/h2&gt;

&lt;p&gt;You&amp;rsquo;ve probably heard at some point in the past that it&amp;rsquo;s a &lt;a href=&quot;http://code.google.com/speed/page-speed/docs/request.html#ServeFromCookielessDomain&quot;&gt;good&lt;/a&gt; &lt;a href=&quot;http://developer.yahoo.com/performance/rules.html#cookie_free&quot;&gt;idea&lt;/a&gt;
to serve static assets from a domain that doesn&amp;rsquo;t set cookies. Yesterday, I
finally got around to doing that here. If you hop into devtools or Firebug,
you&amp;rsquo;ll see that this page&amp;rsquo;s CSS, JavaScript, and images are all being served
not from &lt;code&gt;mikewest.org&lt;/code&gt;, but from &lt;code&gt;mikewestdotorg.hasacdn.net&lt;/code&gt;. Setting up an
alias like this is trivial in any server. Here&amp;rsquo;s how I made it work in Nginx:&lt;/p&gt;

&lt;p&gt;My websites all have specific directories in which static assets live,
&lt;code&gt;/home/mkwst/public_html/mikewest.org/public/static&lt;/code&gt; for example. I simply set
up a server listening for requests to &lt;code&gt;mikewestdotorg.hasacdn.net&lt;/code&gt;, and use
the static asset directory as the &lt;code&gt;root&lt;/code&gt;. With that in place, I ensure that all
files are served with &lt;a href=&quot;http://developer.yahoo.com/performance/rules.html#expires&quot;&gt;far-future expiry headers&lt;/a&gt;, and then set up some
trivial versioning magic by ignoring the first chunk of the URL:
&lt;code&gt;https://mikewestdotorg.hasacdn.net/20111231/style.css&lt;/code&gt; serves the same file
as &lt;code&gt;https://mikewestdotorg.hasacdn.net/1/style.css&lt;/code&gt;, but because the 
paths are different, the file can be loaded and cached anew when something
changes.&lt;/p&gt;

&lt;p&gt;That setup looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;server {
  listen 80;
  server_name mikewestdotorg.hasacdn.net;

  # Turn off logging for static assets:
  access_log  off;
  error_log   /dev/null crit;

  # Set the root from which Nginx reads files for this domain:
  root /home/mkwst/public_html/mikewest.org/public/static;

  location / {
    add_header Expires &quot;Thu, 31 Dec 2037 23:55:55 GMT&quot;;
    add_header Cache-Control &quot;public, max-age=315360000&quot;;
    
    if (-f $request_filename) {
      break;
    }

    rewrite ^/\d+/(.*) /$1 break;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Easy! I&amp;rsquo;ve thrown &lt;a href=&quot;https://github.com/mikewest/hasacdn.net/blob/master/private/nginx.conf&quot;&gt;the whole config file up on GitHub&lt;/a&gt; if you&amp;rsquo;re curious. &lt;/p&gt;

&lt;p&gt;So there you have it; enjoy the end of your holidays with these two resolutions
that you can bang out over the weekend. You&amp;rsquo;ll be ahead of the game, and the
envy of all your friends and neighbors when you compare notes at the end of
2012.&lt;/p&gt;
</content>
    </entry>

    
    <entry>
        <title type='text'>Making Your Web Apps Accessible Using HTML5 and ChromeVox</title>
        <link rel="alternate" href="https://mikewest.org/2011/12/transcript-gdd-accessibility-with-chromevox" />
        <id>https://mikewest.org/2011/12/transcript-gdd-accessibility-with-chromevox</id>
        <updated>2011-12-16T00:00:00+01:00</updated>
        <published>2011-12-16T00:00:00+01:00</published>
        <content type='html'>&lt;p&gt;Back in November, I presented twice at the Google Developer Day in Tel-Aviv.
The first of those talks &lt;a href=&quot;http://www.youtube.com/watch?v=pwm73Pe5xb8&quot;&gt;has been uploaded&lt;/a&gt;, and I spent most of the
afternoon transcribing it to post here. I wanted to give the audience (you!) an
introduction to screen readers, and to building accessible websites and
applications. I think it was pretty successful, and I hope you enjoy it if you
watch at home.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;d highly recommend that, if you&amp;rsquo;re at all interested in this stuff (and you
should be), you go out and &lt;a href=&quot;http://goo.gl/pqKpN&quot;&gt;install ChromeVox&lt;/a&gt; to start playing around with
how your sites sound. It&amp;rsquo;s trivial to get up and running, and will start to
give you a sense of what you&amp;rsquo;re doing well, and what needs improvement. The
team has done a brilliant job putting it together, and it&amp;rsquo;s very much worth
your time to experiment with.&lt;/p&gt;

&lt;p&gt;The slides are available at &lt;a href=&quot;http://mkw.st/p/gdd11-berlin-a11y&quot;&gt;mkw.st/p/gdd11-berlin-a11y&lt;/a&gt; if you&amp;rsquo;d like to
follow along at home, and here, without further adou, is the embed, followed
by the transcript:&lt;/p&gt;

&lt;h2 id=&quot;video&quot;&gt;Video&lt;/h2&gt;

&lt;iframe width=&quot;606&quot; height=&quot;370&quot; src=&quot;https://www.youtube.com/embed/pwm73Pe5xb8?rel=0&quot; frameborder=&quot;0&quot; title=&quot;Google Developer Day Tel-Aviv, 2011: Making Your Web Apps Accessible Using HTML5 and ChromeVox&quot; allowfullscreen=&quot;allowfullscreen&quot;&gt;&lt;/iframe&gt;

&lt;h2 id=&quot;transcript&quot;&gt;Transcript&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; What I&amp;rsquo;d like to discuss with you today is a topic that I
think is incredibly important. It&amp;rsquo;s not a topic that I think is very sexy, and
it&amp;rsquo;s something that often gets ignored when building applications. Even Google&amp;rsquo;s
applications. But I think it&amp;rsquo;s really important to talk about accessibility.&lt;/p&gt;

&lt;p&gt;Making applications not only available to a wide variety of people, but usable
by those same people.&lt;/p&gt;

&lt;p&gt;As a way of getting into this, I want you to think about the Google+ page. All
of you have probably seen this. There&amp;rsquo;s a button up in the top corner that says
&amp;ldquo;Add to Circles&amp;rdquo; and the interaction model is the following. I take my mouse, I
hover it over the &amp;ldquo;Add to Circles&amp;rdquo; button, and then something pops up. And at
that point, I&amp;rsquo;m able to select circles into which I can put one of my friends or
one of my contacts. This works really, really well if I can use a mouse.&lt;/p&gt;

&lt;p&gt;All of you close your eyes. Now grab your mouse and hover&amp;hellip; over the&amp;hellip; That&amp;rsquo;s
kinda problematic, right? If I can&amp;rsquo;t see the screen, how do I use my mouse to
hover over anything on the screen? This mode of interaction, while very
interactive and very rich, excludes a wide variety of people that either can&amp;rsquo;t
or don&amp;rsquo;t want to use the mouse for some reason. And in fact, when we first
launched Plus, this was completely inaccessible. It was impossible to use the
circle picker widget with anything other than a mouse. If you didn&amp;rsquo;t have a
mouse, you were simply out of luck.&lt;/p&gt;

&lt;p&gt;What I want to talk about today is how we can avoid that. How we can build
applications that are accessible and universally usable.&lt;/p&gt;

&lt;p&gt;There are a couple of types of accessibility, and the type that I really want to
talk about today is users that use an assistive technology of some sort in order
to access a website. These users could be blind, they might be completely unable
to see the screen, in which case they&amp;rsquo;re going to use something like a screen
reader or braille reader in order to get the information provided to them in a
form that they can access. They could be users with low vision, in this case they
might use a magnifier or a lens of some sort in order to make objects on the
screen bigger so they can actually interact with them well. Or they could be
motor impaired in some way. There are people that use foot pedals. There are
people who can only use individual fingers, or they might have some some sort of
mouth control, be it either with a physical object they control with their
tongue, or with speech control such that they can simulate clicks on specific
items on the page.&lt;/p&gt;

&lt;p&gt;We want to be able to support all of these users, and what I want to talk about
today is how we can do that with HTML5 and with screen readers.&lt;/p&gt;

&lt;p&gt;One such screen reader is called ChromeVox. ChromeVox is a screen reader built
specifically for Chrome by the Chrome Accessibility Team. This uses the
&lt;a href=&quot;http://code.google.com/chrome/extensions/tts.html&quot;&gt;text-to-speech API that Chrome provides&lt;/a&gt; as an extension API. So anyone
can write anything exactly like this, and actually all the code is open source.
So you can take a look at it and see exactly how it works. This is completely
free, you can download it. It&amp;rsquo;s built directly into ChromeOS as the
accessibility mechanism for ChromeOS, and you can download it for Chrome on any
other platform. It&amp;rsquo;ll work quite well, and in fact I&amp;rsquo;ll demo it a little bit
today.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Enter your name. Choose your favorite. Screen Reader Introduction
Heading Three.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; This is what ChromeVox sounds like. If none of you, if one of you
hasn&amp;rsquo;t used a screen reader before, this is what it sounds like: you get a very
mechanical tone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; [Beep] Enter your name. Edit text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; That reads off the thing you&amp;rsquo;re currently focused on on the page,
and generally speaking will give you some meta-information about that. So when
we go back up to the header, we&amp;rsquo;ll hear:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Screen reader introduction. Heading three.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; It tells you that it&amp;rsquo;s a heading, and it tells you that it&amp;rsquo;s a
level three heading. What this tells you is that the semantics of your page are
really critically important. If we jump down into the form:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; [Beep] Enter your name. Edit text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; Here we read not only that you can type something into this field,
but we get a label for it as well. This gives you a really, kind of, a rich
visual, er, mental image of what a visual user would see on this page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; [Beep] Choose your favorite color. Red. List box one of ten.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; It&amp;rsquo;s a list box. There are ten items. It gives you some semantics
along with it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; [Beep] Submit. Button. Having trouble, click here for help. Link.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; So it tells you that there&amp;rsquo;s a link on the page. And there are some
other functions so you can see where that link goes and a variety of other
functionality. But that&amp;rsquo;s the basics.&lt;/p&gt;

&lt;p&gt;What I want to talk about today with that in mind are three things. First, I
want to talk about what you do when you&amp;rsquo;re starting from scratch. When you have
complete control over the HTML, what&amp;rsquo;s the best practice? What should you start
out with?&lt;/p&gt;

&lt;p&gt;Second, I want to talk about the case that most of us find ourselves in, where
we have an application that isn&amp;rsquo;t exactly semantic. It doesn&amp;rsquo;t work quite as
well as we&amp;rsquo;d like it to in terms of the markup or in terms of the CSS, but we
still want to make sure that it&amp;rsquo;s accessible. How do we go about doing that?&lt;/p&gt;

&lt;p&gt;And finally, I&amp;rsquo;ll point you to some tools and resources that you can look at
later on. There&amp;rsquo;s a lot of information here. I&amp;rsquo;m not going to touch even half of
what it takes to make a website accessible, but I am going to give you some
pointers, and I hope that I give you a good basis.&lt;/p&gt;

&lt;p&gt;So let&amp;rsquo;s start out.&lt;/p&gt;

&lt;p&gt;What&amp;rsquo;s really important to understand about Chrome, er, about screen readers in
general is that all they have to work with is the DOM. They have the document
object model. This means that the semantics of your page are incredibly
important, and the visual aspect of your page is incredibly unimportant. For
instance, we can all see that this sentence here is &amp;ldquo;The rain in Spain stays
mainly on the plain.&amp;rdquo; Let&amp;rsquo;s see what ChromeVox thinks about it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Example. Heading.  The plain in rain stays mainly in the Spain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; That&amp;rsquo;s a bit odd. I wonder why that happened. If we look at the DOM
that was used to create this, we see that what&amp;rsquo;s happened is that we&amp;rsquo;ve simply
used absolute positioning in order to move things around on the page so that
they look like they&amp;rsquo;re in a certain order. In the sentence it makes very little
sense to do that, but in our applications we do this all the time. We take
things from disparate parts of the DOM, and we jam them together visually
because that makes sense, that&amp;rsquo;s how they should be. But we didn&amp;rsquo;t code it that
way. In fact, we coded them at separate ends of the spectrum, and in that case,
a screen reader user, or anyone who is only able to work with the DOM, is going
to have a really hard time understanding your web page, and working with your
web page.&lt;/p&gt;

&lt;p&gt;So it&amp;rsquo;s important to understand a couple of things [CROSSTALK] about things when
working with DOM, and when creating a website. What&amp;rsquo;s important, first off, is
to have logical sections of your page, and to order those sections in a way that
makes sense for someone who&amp;rsquo;s trying to use this application. In other words,
the thing that&amp;rsquo;s most important about your page should probably come near the
top of the DOM. The things that are much less important should probably come
near the bottom, even if it&amp;rsquo;s easier for you in some way to put navigation links
all the way at the top of the DOM, those probably aren&amp;rsquo;t the things people are
most interested in, so you want to put them later on the page.&lt;/p&gt;

&lt;p&gt;It&amp;rsquo;s also important to group the things on the page together that have any sort
of semantic relationship with each other. You can use any sort of HTML5 tag to
do that, for example, the &lt;code&gt;section&lt;/code&gt; tag.&lt;/p&gt;

&lt;p&gt;Last thing, yeah, it&amp;rsquo;s important not to use tables. Tables are for layout. Or,
not for layout. They are for data. If you&amp;rsquo;re trying to set up something on your
page with tables, then you&amp;rsquo;re at the wrong conference in general. So, don&amp;rsquo;t do
that.&lt;/p&gt;

&lt;p&gt;Interactive controls. What&amp;rsquo;s interesting about a lot of applications and a lot
of modern web applications that we see on the web today is that people are using
&lt;code&gt;div&lt;/code&gt; and &lt;code&gt;span&lt;/code&gt; to mean absolutely everything. This is a really bad practice
for a wide variety of reasons. There are are elements that actually have
semantics associated with them, and have interaction associated with them. For
instance, if I have an &lt;code&gt;onclick&lt;/code&gt; event on a &lt;code&gt;div&lt;/code&gt;, I have to do a lot of work in
order to make that replicate something like a &lt;code&gt;button&lt;/code&gt;. If I just used the
&lt;code&gt;button&lt;/code&gt; element, I get a lot of that for free. I get some keyboard
interactions. I&amp;rsquo;ve ensured that it has the exact same semantics as a native
button on a native web application, because the browser is doing the work for
me. I don&amp;rsquo;t have to go through and build all of this out myself, I can leverage
the power of the browser, use the correct element, and in that case, get things
like keyboard accessibility almost for free. This is just good practice, there&amp;rsquo;s
no reason not do this at all.&lt;/p&gt;

&lt;p&gt;The last thing here that&amp;rsquo;s really important to note is that &lt;code&gt;div&lt;/code&gt;s and &lt;code&gt;span&lt;/code&gt;s
are by default not focusable. If they&amp;rsquo;re not focusable, they don&amp;rsquo;t show up for a
screen reader. It&amp;rsquo;s just that simple. You need to make sure that anything that a
person is interacting with can obtain focus on the page. I&amp;rsquo;ll give you a quick
example of why that&amp;rsquo;s important. In a little bit.&lt;/p&gt;

&lt;p&gt;So if we turn ChromeVox back on [CROSSTALK].&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Custom button. Live coding example. Heading three.&lt;/p&gt;

&lt;p&gt;Click on this button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; So, there&amp;rsquo;s probably a button coming up. I&amp;rsquo;ve just heard some text
that said &amp;ldquo;button&amp;rdquo;, that&amp;rsquo;s important. So let&amp;rsquo;s jump to the next element on the
page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Send.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; Send. Ok. Let&amp;rsquo;s hit a button. Well, nothing seems to be happening.
I wonder why that is. If I click on &amp;ldquo;send&amp;rdquo;, of course, I get an alert. Hrm.
Something&amp;rsquo;s going wrong here, what could it be?&lt;/p&gt;

&lt;p&gt;The most important thing is to simply change this to a &lt;code&gt;button&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If we change it to a button, and then refresh.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; [Beep] Send. Button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; Send, button. ChromeVox now recognizes this as a semantic element.
If I hit enter again, I get the alert. In other words&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Send. Button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; Enter will simulate a click, if the element is a button. The
browser will do the work for you. If it wasn&amp;rsquo;t a button, you would have to do
things like &lt;code&gt;onkeydown&lt;/code&gt;, and then, have an event handler for &lt;code&gt;onkeydown&lt;/code&gt; in
order to make sure that you replicated all of the functionality that a browser
would.&lt;/p&gt;

&lt;p&gt;This is something that you simply don&amp;rsquo;t want to do on your own. You want
to make sure that you use the right elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Labeling. Label your.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; What&amp;rsquo;s also important, specifically with regard to forms, is to
make sure that every element on the page that users are going to interact with
in some way has a label. This is incredibly important, and it&amp;rsquo;s difficult to
overemphasize how important this is. If you don&amp;rsquo;t have labels, then you simply
have text boxes on the page. A text box is completely meaningless without
context. I know that I&amp;rsquo;m supposed to enter some information into this text box,
but I have no idea what it is, and I have no idea why it might be important for
my interaction with this application. If, on the other hand, I have a label, and
the label syntax is absolutely trivial: You simply say &amp;ldquo;label&amp;rdquo;, and then use an
ID in order to say what this thing is labeling. If I do that, then the screen
reader will understand that there is a semantic relationship between the text
and the element on the page. It will bind those together when it reads them out
to me. In other words, I will get good semantic information about what this
thing on the page is that I&amp;rsquo;m meant to interact with.&lt;/p&gt;

&lt;p&gt;Again, and this should be really really basic, every image on your page should
have an &lt;code&gt;alt&lt;/code&gt; tag. There&amp;rsquo;s no reason at all that an image shouldn&amp;rsquo;t have an alt
tag. There are two types, however, of images on your page. There are images that
replicate information that is already available, in other words they are purely
decorative. And there are images that are, in and of themselves, informative.&lt;/p&gt;

&lt;p&gt;For the former type, you should have a blank &lt;code&gt;alt&lt;/code&gt; tag. If you have a blank
&lt;code&gt;alt&lt;/code&gt; tag, that means &amp;ldquo;I&amp;rsquo;ve thought about this. This image exists on the page,
it&amp;rsquo;s visually important, but it has absolutely no semantic meaning.&amp;rdquo; In that
case the screen reader will simply ignore it. A blank &lt;code&gt;alt&lt;/code&gt; tag means &amp;ldquo;ignore
this image.&amp;rdquo;&lt;/p&gt;

&lt;p&gt;A missing &lt;code&gt;alt&lt;/code&gt; tag is, however, something completely different, and we&amp;rsquo;ll look
at exactly what that does in a moment. For the normal use case, you have an
image on the page that&amp;rsquo;s informative in some way, you should have alt-text
associated with that that says &amp;ldquo;This image has some meaning, here&amp;rsquo;s what it is.&amp;rdquo;
Otherwise, it&amp;rsquo;s completely useless for a person who can&amp;rsquo;t see the page.&lt;/p&gt;

&lt;p&gt;So, again, let&amp;rsquo;s take a quick look at what a form sounds like when you don&amp;rsquo;t do
things correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Edit text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; Edit text.&lt;/p&gt;

&lt;p&gt;There&amp;rsquo;s nothing here. I know that there&amp;rsquo;s a text box. I should probably type
something, but I have no idea what it is.&lt;/p&gt;

&lt;p&gt;Oops.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Password. Edit text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; Password. Edit text. That&amp;rsquo;s interesting. It doesn&amp;rsquo;t really help me.
I know that it&amp;rsquo;s a password, and that&amp;rsquo;s better, but it really doesn&amp;rsquo;t help very
much.&lt;/p&gt;

&lt;p&gt;Now let&amp;rsquo;s look at the image. What&amp;rsquo;s really interesting about this is that I have no
alt text here at all. What this means [CROSSTALK]. This means that the browser is
going try to figure out something for me. And usually it does an absolutely
miserable job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Nine zero one d three n nine four t three. Image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; So it reads the name of the image. Especially when you have these
sorts of big CMS systems that automatically generate images in a variety of
sizes and a variety of contexts, the name of the image is never informative. But
it&amp;rsquo;s just common practice that a screen reader will try to give you any
information that it has. And in this case, the only information it has is the
name of the image. This is really really bad behavior, and it&amp;rsquo;s something that
you should avoid to whatever extent possible when building your own
applications.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s look at how we would solve this problem.&lt;/p&gt;

&lt;p&gt;The first thing we would need to do is change these &lt;code&gt;span&lt;/code&gt;s to &lt;code&gt;label&lt;/code&gt;s.&lt;/p&gt;

&lt;p&gt;By doing so, we give each of the, each of the elements on the page, or each of
the form elements, semantic information. We tell it that the first label is
pointing to the first form element.&lt;/p&gt;

&lt;p&gt;I can&amp;rsquo;t talk and type at the same time, as we&amp;rsquo;re finding out. For user.&lt;/p&gt;

&lt;p&gt;I just can&amp;rsquo;t type at all, I think is the problem.&lt;/p&gt;

&lt;p&gt;So.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; User name. Edit text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; So this time, when I click on it, or if I&amp;rsquo;d given it focus in some
other way it would have behaved the same, when I click on it, it not only reads
out that it&amp;rsquo;s an edit text box, it also tells me the label associated with it so
that I know that here I&amp;rsquo;m supposed to type my user name. That&amp;rsquo;s excellent
behavior.&lt;/p&gt;

&lt;p&gt;Now let&amp;rsquo;s fix the image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; User name. P I N. Password. Edit text. Golden Gate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; Excellent. So now I know that there is information associated with
this image. In that case, I&amp;rsquo;m actually able to use it to understand the page. So
again, big lesson here: use an &lt;code&gt;alt&lt;/code&gt; tag, use &lt;code&gt;label&lt;/code&gt;s. Both of them are
absolutely critically important, and really very basic. If you&amp;rsquo;re not doing this
already, you&amp;rsquo;re doing the wrong thing.&lt;/p&gt;

&lt;p&gt;What we&amp;rsquo;ve talked about and what we&amp;rsquo;ve seen here is that focus is really
important. You see a big outline on the page of what the focused element is. The
focused element is exactly what the user is currently interacting with. If they
have a mouse, they might be hovering over something completely different, or
they might be clicking on things that can&amp;rsquo;t accept focus. That simply isn&amp;rsquo;t the
case when you&amp;rsquo;re dealing with someone who&amp;rsquo;s using a screen reader. In this case,
you need to make sure that you provide focus hooks within your application.&lt;/p&gt;

&lt;p&gt;First of all, so that the important elements the user is supposed to interact
with are focusable. And second, that you not only accept, um, you not only
accept things like hover and, um, onkeydown and a variety of other things along
those lines.&lt;/p&gt;

&lt;p&gt;What will become important later, what we&amp;rsquo;ll see later on is that it&amp;rsquo;s not only
important to ensure that each element can be focused, but also important to
manage focus on the page. If, for instance, I have a dialog box that pops up, I
want to make sure that the focus stays within that dialog box if it&amp;rsquo;s modal.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;ll show a quick example of how that might work.&lt;/p&gt;

&lt;p&gt;So here I have &amp;ldquo;Buy more printer ink&amp;rdquo;. I get a modal dialog box. I see that it&amp;rsquo;s
modal because the screen has been darkened, so I have some sort of visual
feedback that I should click on one of these two buttons before I do anything
else. I&amp;rsquo;ll click on that. Let&amp;rsquo;s see how it sounds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Popup dialog. [Beep] Buy more printer ink. Button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; So it&amp;rsquo;s a button. That&amp;rsquo;s good. I hit a button.&lt;/p&gt;

&lt;p&gt;What happened?&lt;/p&gt;

&lt;p&gt;According to the screen reader, absolutely nothing, because the focus didn&amp;rsquo;t
move. I hit enter, or I clicked on it, but the focus stayed on the button
because nothing told the focus to move. What really needs to happen here,
probably the best case scenario, is to move the focus programmatically to the
first focusable element within the context of this dialog box.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s see what we can do about that.&lt;/p&gt;

&lt;p&gt;Happily, moving focus around is incredibly trivial. You simply have to call
&lt;code&gt;.focus()&lt;/code&gt; on the correct element. Let&amp;rsquo;s look at it again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; O K. Button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; What we see here is that focus was automatically moved inside the
context of this dialog box. That&amp;rsquo;s great. However, there&amp;rsquo;s another aspect that
we need to think about. What happens when I click on one of these two buttons?
What happens in that scenario, if I hit enter, focus is dropped on the floor. In
other words, nothing on this page has focus anymore, which means the screen
reader is going to start back up at the top of the page. That&amp;rsquo;s really bad
experience.&lt;/p&gt;

&lt;p&gt;What we instead want to happen is to bring the user directly back to where they
were when they activated this dialog box. We can do that relatively trivially.
So here we see that the button is called &amp;ldquo;confirm&amp;rdquo;, so I can simply associate
focus with confirm.&lt;/p&gt;

&lt;p&gt;If I refresh this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; O K. Button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; Jumps me in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Buy more printer ink. Button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; Jumps me back out. This is good experience. This means that I move
directly from the dialog, directly back onto the page where I was. I know where
I am, I understand the context, and I&amp;rsquo;m able to deal with that.&lt;/p&gt;

&lt;p&gt;What we&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; O K. Button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; What is problematic, however, is that if I keep hitting Tab, I can
jump outside of this dialog box. Visually, I understand that I&amp;rsquo;m not supposed to
do that, the page is dark. However, that doesn&amp;rsquo;t really work when dealing with a
screen reader. Instead, we need to manage focus for the user in order to show
them that they should stay within this context. They need to make a decision,
yes or no. That&amp;rsquo;s the only time you should use a modal dialog.&lt;/p&gt;

&lt;p&gt;So how can we go about doing that &amp;hellip; [CROSSTALK]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHROMEVOX&amp;nbsp;&amp;raquo;&lt;/strong&gt; Buy more printer ink. Button. [CROSSTALK]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; &amp;hellip; and type, so I will copy.&lt;/p&gt;

&lt;p&gt;I am cheating, and it&amp;rsquo;s awesome.&lt;/p&gt;

&lt;p&gt;There we go.&lt;/p&gt;

&lt;p&gt;So now, I&amp;rsquo;m hitting tab, and trying to get out of the box. Shift-tab would bring
me to the previous focus item. I&amp;rsquo;m not able to. I&amp;rsquo;ve thrown in some code that
makes it possible for me to intercept &lt;code&gt;blur&lt;/code&gt; events and &lt;code&gt;focus&lt;/code&gt; events, and make
sure that I&amp;rsquo;m only focusing on one of the two items that should be focusable
within the context that I currently find myself.&lt;/p&gt;

&lt;p&gt;This isn&amp;rsquo;t that difficult, basically, I&amp;rsquo;m really just adding event listeners and
dealing with it.&lt;/p&gt;

&lt;p&gt;Um.&lt;/p&gt;

&lt;p&gt;And now Chrome is crashing. Ha ha.&lt;/p&gt;

&lt;p&gt;You know what&amp;rsquo;s awesome? &lt;a href=&quot;http://www.chromium.org/getting-involved/dev-channel&quot;&gt;Dev version of Chrome&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I really recommend that you use the dev version of Chrome. I do not recommend
that you demo with the dev version of Chrome because it causes small problems
like this.&lt;/p&gt;

&lt;p&gt;Good times. Let&amp;rsquo;s see if I can get out of this.&lt;/p&gt;

&lt;p&gt;Regardless.&lt;/p&gt;

&lt;p&gt;Um.&lt;/p&gt;

&lt;p&gt;Doo, doo doo, doo doo. Ha ha. Good times.&lt;/p&gt;

&lt;p&gt;Ah, my good friend Force Quit.&lt;/p&gt;

&lt;p&gt;My good friend Force Quit. There we go, hey look at that.&lt;/p&gt;

&lt;p&gt;Now let&amp;rsquo;s open this back up.&lt;/p&gt;

&lt;p&gt;So what you might not know about Chrome is that we have three different
channels. Actually we have four, but three are important.&lt;/p&gt;

&lt;p&gt;We have a stable channel, that&amp;rsquo;s what every user actually gets. And it is, as
the name implies, stable.&lt;/p&gt;

&lt;p&gt;We have a beta channel, the beta channel is a little bit less stable than
stable. Stable gets built about every six weeks, beta gets built probably about
every three weeks. Dev, on the other hand, is built on a weekly basis, sometimes
more than weekly. More than weekly is actually awesome, because it shows you
exactly what&amp;rsquo;s happening on trunk. But. It&amp;rsquo;s slightly problematic in that
sometimes it&amp;rsquo;s broken. Like now. Ha ha.&lt;/p&gt;

&lt;p&gt;Anyway.&lt;/p&gt;

&lt;p&gt;The last thing I&amp;rsquo;d point out when dealing with applications that you have
complete control over are keyboard shortcuts. It&amp;rsquo;s really quite useful to give
users the ability to control the application in a controlled way with a
keyboard. For instance, if you go to GMail, you might not know that you&amp;rsquo;re able
to use Vim keybindings, so J and K, in order to jump between messages. You&amp;rsquo;re
able to use keybindings in order to archive, and jump back to the inbox. It
actually makes you much more efficient.&lt;/p&gt;

&lt;p&gt;For specific types of applications, keyboard shortcuts can be incredibly useful.
There are three types that I list up here. I don&amp;rsquo;t really think it&amp;rsquo;s incredibly
important to talk about them, and I&amp;rsquo;m running out of time, so I&amp;rsquo;ll move on.&lt;/p&gt;

&lt;p&gt;We&amp;rsquo;ve talked about the ideal world. When you have complete control, you want to
use semantic elements, and you want to make sure that you manage focus
correctly, and that you only use those elements that kinda do all the work for
you. That you use &lt;code&gt;button&lt;/code&gt;s instead of &lt;code&gt;div&lt;/code&gt;s and so on.&lt;/p&gt;

&lt;p&gt;What we usually end up with, in the real world, is code that kinda looks like
this. It&amp;rsquo;s just a jumble of random crap thrown onto the page. You need to figure
out first what it is, and then you need to change it to do something useful and
accessible.&lt;/p&gt;

&lt;p&gt;Generally this means that you&amp;rsquo;re trying to build an interactive control that
HTML simply doesn&amp;rsquo;t provide for you. So if we look back to the circle picker
that we looked at before, there&amp;rsquo;s no native HTML widget that says &amp;ldquo;When I hover
over this thing, pop something up and do some sort of checkboxy goodness.&amp;rdquo; That
simply doesn&amp;rsquo;t exist as part of HTML; It&amp;rsquo;s something you need to build on your
own.&lt;/p&gt;

&lt;p&gt;When we find ourselves in these sorts of situations, we need to figure out how
we implement that in a way that is actually accessible. One thing that we can
use is something new called ARIA.&lt;/p&gt;

&lt;p&gt;ARIA is part of the HTML5 specification, kinda, depending on who you ask, and it
gives more semantic information, or it allows you to create semantic
relationships first of all between elements on the page, but also to add
semantics to an element like a &lt;code&gt;div&lt;/code&gt; that, by itself, means absolutely nothing.&lt;/p&gt;

&lt;p&gt;If we look at something like this, this is kinda what the widget looks like, you
have two pieces. You have a button and a popup, and we need to figure out how to
make those accessible. The HTML that we&amp;rsquo;re stuck with for whatever reason looks
like this. We&amp;rsquo;ve got some &lt;code&gt;div&lt;/code&gt;s, we&amp;rsquo;ve got some &lt;code&gt;span&lt;/code&gt;s. There&amp;rsquo;s really nothing
here that a user can actually do anything with, the screen reader.&lt;/p&gt;

&lt;p&gt;So what do we do about it?&lt;/p&gt;

&lt;p&gt;The first thing we need to do is to make sure that the elements that a user
interacts with are focusable. &lt;code&gt;div&lt;/code&gt;s, as I said before, by themselves are not
focusable. They simply get ignored by the screen reader, and instead it jumps to
their content.&lt;/p&gt;

&lt;p&gt;What we can do, however, in order to make it focusable, is to add a &lt;code&gt;tabindex&lt;/code&gt;.
&lt;code&gt;tabindex&lt;/code&gt; means, when you are tabbing through the page, when you&amp;rsquo;re using the
tab key to jump between the focusable elements, first of all this element should
be in the tab, uh, in the tab order, and second of all, perhaps it has a
specific position.&lt;/p&gt;

&lt;p&gt;I have never actually used tab order to say that an element has a specific
position. Instead, I set a tab order of zero, which means
this element is focusable, and this element should appear wherever it appears in
the DOM.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;tabindex&lt;/code&gt; of -1 is also sometimes useful for specific scenarios. This means
that if you&amp;rsquo;re tabbing through the page, this element doesn&amp;rsquo;t get focus, but if
you&amp;rsquo;re using a screen reader or if you&amp;rsquo;re, if you want to programmatically
assign focus in some way, you can.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; &lt;em&gt;[UNINTELLIGIBLE]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Sorry?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; &lt;em&gt;[UNINTELLIGIBLE]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Sure, we can talk about details and stuff later on.&lt;/p&gt;

&lt;p&gt;Um, right.&lt;/p&gt;

&lt;p&gt;So, we talked a little bit earlier about the keyboard, and about the fact that
the keyboard is an incredibly important mechanism for interacting with a web
page. You need to make sure that you support it. This means that your custom
controls should respond to the keyboard in the same way that a native control
does. This means, if for example, I tab over to a link on the page, and I hit
enter, that link is going to be executed. I&amp;rsquo;m going to jump to that link. If I&amp;rsquo;m
on a button and I hit enter, it&amp;rsquo;s going to do something.&lt;/p&gt;

&lt;p&gt;I need to make sure that my custom elements do the exact same thing, and there&amp;rsquo;s
a lot of work associated with this. I first of all need to figure out what the
semantics are, and second I need to replicate those semantics within the context
of my JavaScript.&lt;/p&gt;

&lt;p&gt;This is why it&amp;rsquo;s better to simply use the correct to begin with, because then
you avoid a lot of work. But if you can&amp;rsquo;t avoid that work for whatever reason,
you need to make sure that you deal with the &lt;code&gt;keydown&lt;/code&gt; or the &lt;code&gt;keyup&lt;/code&gt; event, or
a &lt;code&gt;keypress&lt;/code&gt; event, depending on the interaction that you want.&lt;/p&gt;

&lt;p&gt;You need to make sure that you deal with things like enter and escape, in
interesting, and, you know, normal ways, ways that a user would expect.&lt;/p&gt;

&lt;p&gt;The code for that might look something like this: you intercept the &lt;code&gt;keydown&lt;/code&gt; or
a &lt;code&gt;key&lt;/code&gt; event of some sort, you look at the event, and then you look at the
&lt;code&gt;keyCode&lt;/code&gt;, and you need to figure out what the &lt;code&gt;keyCode&lt;/code&gt; actually is. This is
space, this is enter.&lt;/p&gt;

&lt;p&gt;It&amp;rsquo;s generally better practice not to use magic numbers in your code, but
instead to set up some sort of constants so that you actually read &amp;ldquo;space&amp;rdquo; or
&amp;ldquo;enter&amp;rdquo;, but I didn&amp;rsquo;t have space, so I did this.&lt;/p&gt;

&lt;p&gt;Also important to note is that &lt;a href=&quot;http://www.w3.org/TR/wai-aria-practices/#aria_ex&quot;&gt;the W3C has a document that documents a couple
of common keyboard patterns&lt;/a&gt;. Things like &amp;ldquo;Escape should cancel a
dialog box.&amp;rdquo; Things like that are documented relatively well, but the W3C, the
only problem with that is that it&amp;rsquo;s relatively Windows-specific. It&amp;rsquo;s not the
case that all keyboard shortcuts are the same on all platforms. So, keep that
in mind, and make sure that you are tuning your keyboard shortcuts to the
platform that most of your users are actually using.&lt;/p&gt;

&lt;p&gt;If we look at the first part of this widget, I said it was in two parts, look at
the button first. And this actually acts very much like a button, even though
the user has to hover over it. That&amp;rsquo;s not the usual button behavior, but the
conceptual behavior is very similar. I interact in some way with this thing, and
then a modal dialog pops up, and I have to interact with that dialog.&lt;/p&gt;

&lt;p&gt;So here we&amp;rsquo;re going to act as though this &lt;code&gt;div&lt;/code&gt; is a &lt;code&gt;button&lt;/code&gt;. We do that first
of all by giving it &lt;code&gt;tabindex&lt;/code&gt; such that I can tab to it on the page. This means
that enter for instance, I&amp;rsquo;ll be focused on it, I&amp;rsquo;ll press enter, that will
simulate a click, and I&amp;rsquo;ll get some sort of interaction with this button.&lt;/p&gt;

&lt;p&gt;What we don&amp;rsquo;t have, however, is the label semantic. What we instead have to do
is to put text into the &lt;code&gt;div&lt;/code&gt; such that it actually gets read out when the user
focuses on this &lt;code&gt;div&lt;/code&gt;. Again, there&amp;rsquo;s no &lt;code&gt;label&lt;/code&gt; that can be associated with
anything other than an input element or select element or form element of some
sort. That behavior simply doesn&amp;rsquo;t exist. So you have to make sure that there&amp;rsquo;s
textual content in everything that you have on the page. Even if it&amp;rsquo;s like a
gear, because you&amp;rsquo;re doing some sort of settings menu, you can&amp;rsquo;t simply have a
gear as like a background image. It&amp;rsquo;s much much better to have a &lt;code&gt;div&lt;/code&gt;, actually
a &lt;code&gt;button&lt;/code&gt;, but if you have to have a &lt;code&gt;div&lt;/code&gt;, then make sure that &lt;code&gt;div&lt;/code&gt; has
textual content so that a screen reader can actually read it.&lt;/p&gt;

&lt;p&gt;If we look at the dropdown that pops up when I hover over this thing, it acts
much like a modal dialog, so a modal dialog is what we should emulate. We should
make sure that when I&amp;rsquo;m tabbing through, that I can&amp;rsquo;t tab out of the dialog. I
have to make a decision here before I can interact with something else on the
page. We should make sure that it&amp;rsquo;s focusable, and we should make sure that the
elements in particular are focusable. If you look, there are checkboxes up
there, um, it&amp;rsquo;s a little bit light&amp;hellip; but there are checkboxes up there. Those
are implemented as &lt;code&gt;div&lt;/code&gt;s, so we need to make sure that those also are
focusable, and that when I do something with them, they behave exactly like a
checkbox would.&lt;/p&gt;

&lt;p&gt;What we can then layer on top of all of this backend work, so I do all of the
event handling, I do all of the markup, what I can then do to add more semantics
is to layer on ARIA. ARIA is a mechanism by which I can say that this &lt;code&gt;div&lt;/code&gt; is
not only a &lt;code&gt;div&lt;/code&gt;, it actually has a role on the page. In this case it might be a
role of button. This means that when I use a screen reader, or anything that
would extract semantic information from the page, it can look at this &lt;code&gt;div&lt;/code&gt; and
understand that this &lt;code&gt;div&lt;/code&gt; is actually a &lt;code&gt;button&lt;/code&gt;. This means that the screen
reader would read &amp;ldquo;Add to Circle. Button.&amp;rdquo; and then the user would understand
that they could interact in some way with this thing that they&amp;rsquo;ve been presented
with.&lt;/p&gt;

&lt;p&gt;What&amp;rsquo;s important to note is that this isn&amp;rsquo;t a panacea. This doesn&amp;rsquo;t do the work
for you of dealing with the keyboard or of making elements on the page
focusable. It simply adds a semantic layer. You still have to do the work of
intercepting keyboard events, and you still have to do the work of making sure
that these elements are, um, potentially interactable.&lt;/p&gt;

&lt;p&gt;So, these are a couple of examples of ARIA roles that you can have. You can have
a &lt;code&gt;button&lt;/code&gt;, and this means that it is a button on the page. You can click on it
or use the keyboard in order to interact with it. It invites interaction in that
case. A menu item is another example, and search are, kinda, is a landmark on
the page so a screen reader can give you some information about the semantics of
the page itself. Not simply specific elements, but the things that exist on the
page. So there is a search widget somewhere, I can jump to that, potentially.
There are sections of the page that have, are, that bind content together in an
interesting way. I can jump to those.&lt;/p&gt;

&lt;p&gt;Screen readers, by and large, at the moment, don&amp;rsquo;t support ARIA landmarks as
well as they could. What they generally support are headings. This means that if
you have a good heading structure on your page, a screen reader user can easily
jump from one heading to the next, and get a good understanding of what&amp;rsquo;s on the
page. What will be happening in the future is that screen readers will have
better support for ARIA landmarks, and then you&amp;rsquo;ll be able to jump to specific
landmarks on the page as well.&lt;/p&gt;

&lt;p&gt;This is already the case in some screen readers. But it&amp;rsquo;s not really across the
board quite yet. But it&amp;rsquo;s something that we should start thinking about now, and
experimenting with now in things like ChromeVox, so that we can use them in the
future when they become more ubiquitous.&lt;/p&gt;

&lt;p&gt;It&amp;rsquo;s not only the case, however, that ARIA describes roles on the page. So it&amp;rsquo;s
not only the case that I can say &amp;ldquo;It&amp;rsquo;s a button.&amp;rdquo; I can also say that this
button, or that this checkbox, for instance, has been checked. This means that
the &lt;code&gt;div&lt;/code&gt; has a role of checkbox, it acts as through it was a checkbox, but it
has properties associated with that. In this case, &lt;code&gt;aria-checked&lt;/code&gt;. This allows
me to determine programmatically whether or not this item is in a checked state.
So if the box should show a check mark or not. It also enables the screen reader
then to read that out to me, so that when I hover, when I focus on this element
on the page, the screen reader can tell me it is a checkbox, and that the
checkbox is checked.&lt;/p&gt;

&lt;p&gt;Using this sort of state information in order to give the user more semantic
information about how the page is put together, and what state it current finds
itself in, is incredibly useful.&lt;/p&gt;

&lt;p&gt;The last thing I note here is ARIA live region. A live region of the page. If
you&amp;rsquo;ve ever used Twitter, and probably most of you have, you know that when
you&amp;rsquo;re typing in your status message, there&amp;rsquo;s a, there&amp;rsquo;s a number next to it
that counts down from 140. As you&amp;rsquo;re typing, it tells you, you have, you know,
20 characters left. It&amp;rsquo;s really quite useful to mark this region as updating, as
something that screen reader should pay attention to, even if I&amp;rsquo;m not directly
focused on it. This means, if I mark it as a &amp;ldquo;live&amp;rdquo; region, I can type a little
but, and then, in a lull, the screen reader can tell me that this thing on the
page updated itself. So I type a little bit, I wait, the screen reader tells me
I have 20 characters left.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aria-live&lt;/code&gt; is the attribute that allows the screen reader to understand that
this piece of the page is going to update itself, and that it&amp;rsquo;s important to pay
attention to.&lt;/p&gt;

&lt;p&gt;So, if we jump back to the add to circles widget, we could implement it
something like this, where we have the &lt;code&gt;div&lt;/code&gt; for the button, we tell the browser
that it&amp;rsquo;s a button, we tell the browser to make sure it&amp;rsquo;s focusable by giving it
a &lt;code&gt;tabindex&lt;/code&gt; of 0, and we have some text inside of it such that, when I focus on
it, the screen reader tells me something interesting.&lt;/p&gt;

&lt;p&gt;We can set up this thing here as a dialog, and the ARIA, the screen reader will
tell me that this is a dialog that I need to interact with before I move
further. We can make sure that these checkboxes are interactable by giving them
&lt;code&gt;role&lt;/code&gt; of checkbox, I didn&amp;rsquo;t put a &lt;code&gt;tabindex&lt;/code&gt; of 0 here. I should have. I need
to. And I need to make sure that there&amp;rsquo;s an &lt;code&gt;aria-checked&lt;/code&gt; attribute in order to
tell me whether or not this is checked.&lt;/p&gt;

&lt;p&gt;So, at this point, I would just say that there are two tools that I think are
really quite useful when testing your own applications for accessibility.&lt;/p&gt;

&lt;p&gt;The first is &lt;a href=&quot;http://goo.gl/pqKpN&quot;&gt;ChromeVox&lt;/a&gt;. It&amp;rsquo;s a completely free screen reader that&amp;rsquo;s
relatively easy to use for people who have never used a screen reader before.
There&amp;rsquo;s good documentation, it&amp;rsquo;s an extension for Chrome, you can go to the
Chrome Web Store, download it, install it into Chrome on any platform, and it
will read text to you.&lt;/p&gt;

&lt;p&gt;This gives you kind of a quick and dirty mechanism for testing the accessibility
of your page. It&amp;rsquo;s not going to be exactly like a blind user using your page,
because they use screen readers simply differently than I do, for instance. But
it&amp;rsquo;s a good sanity check. You can look at your page, make sure that things more
or less work the way that you would expect them to when you&amp;rsquo;re tabbing through.
That things are in the right order, that things are focusable.&lt;/p&gt;

&lt;p&gt;That is really useful information.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://chrome.google.com/webstore/detail/hlklboladblmgfpkenhlgbhoojdlfoao&quot;&gt;ChromeShades&lt;/a&gt; is an accessibility tool that basically turns off all CSS on your
page, and makes it, makes it very obvious when you have a DOM that makes no
sense. So if you look at your page, you read through it, and you have no idea
what&amp;rsquo;s going on, then you know that the styles that you&amp;rsquo;ve made, that you&amp;rsquo;ve
applied to your page, are more than presentation, they are in fact semantic. And
you need to fix that. You need to make sure that the DOM that you present to a
user is usable and semantic.&lt;/p&gt;

&lt;p&gt;Another screen reader that is quite useful is &lt;a href=&quot;http://www.nvda-project.org/&quot;&gt;NVDA&lt;/a&gt;. NVDA is, I think it&amp;rsquo;s
Windows only, for Firefox. It&amp;rsquo;s a really great screen reader. It&amp;rsquo;s free, so if
you just pop open a VM and start using it, it&amp;rsquo;s really quite good. VoiceOver on
Mac is also quite good, but not quite as good, I think, as NVDA.&lt;/p&gt;

&lt;p&gt;There are a couple of libraries with accessibility support within their UI
components. jQueryUI is doing quite a good job. GWT is getting there, Dojo has
done an excellent job.&lt;/p&gt;

&lt;p&gt;At this point, I think I&amp;rsquo;m running out of time, so I would ask if any of you
have any questions.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;ll pop up some final thoughts that you can read while you&amp;rsquo;re asking.&lt;/p&gt;

&lt;p&gt;Yeah?&lt;/p&gt;

&lt;h2 id=&quot;qa&quot;&gt;Q&amp;amp;A&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; &lt;em&gt;[UNINTELLIGIBLE]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; The question is whether ARIA is part of HTML5 or is a separate
namespace. To be perfectly honest, I don&amp;rsquo;t know. I know that there was a lot of
argument about it. And honestly, I don&amp;rsquo;t care, because it&amp;rsquo;s supported in
browsers, so whether it&amp;rsquo;s part of HTML5 or a separate standard is kinda
irrelevant. Browsers generally support it, screen readers generally support it,
and it is the only mechanism by which you can add this sort of semantic layer to
the page. So, I would suggest that you use it, regardless of what a standards
body tells you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; &lt;em&gt;[UNINTELLIGIBLE]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; The role element, whether&amp;hellip; I think the role element is in fact
part of HTML5, that it validates if you go to &lt;a href=&quot;http://validator.nu/&quot;&gt;validator.nu&lt;/a&gt;. Um, whether it&amp;rsquo;s
part of the spec or not, I don&amp;rsquo;t know.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; What&amp;rsquo;s the state of ARIA support?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; The question was what the state of ARIA support is. Modern browsers
generally support ARIA, and generally make the information available to
accessibility, uh, tools. So, I know Chrome, excuse me, Chrome is working on it.
Chrome has relatively decent accessibility support now. If you look at the dev
version of Chrome, it&amp;rsquo;s relatively good. It exposes the sort of semantic
information, like a role of button. That wasn&amp;rsquo;t the case as of, like, Chrome 12
and 13. We made a lot of effort in 14 and 15, and we&amp;rsquo;ve made even more effort
since then. So Chrome is getting there.&lt;/p&gt;

&lt;p&gt;The support in Firefox has been better over time, they&amp;rsquo;re generally doing quite
a good job of leading in terms of accessibility support within the browser, and
the combination of Firefox and NVDA is quite excellent.&lt;/p&gt;

&lt;p&gt;So, we&amp;rsquo;re getting there with Chrome. ChromeVox, I think, is a really good step
in that direction. As I said, it&amp;rsquo;s embedded into ChromeOS, so we&amp;rsquo;re making sure
that when we roll out new, new iterations of Chrome, that we add accessibility
support.&lt;/p&gt;

&lt;p&gt;IE also has generally quite good accessibility support, or at least, it exposes
all of the right things to the operating system layer. That said, IE6 and IE7
don&amp;rsquo;t understand ARIA at all. IE8 has a little bit of understanding, IE9 is
really starting to get there.&lt;/p&gt;

&lt;p&gt;So, I would say modern browsers have pretty good support for ARIA, and the
support will only get better as time goes on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; Is there any, um, is there any connection between accessibility
&lt;em&gt;[UNINTELLIGIBLE]&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; So the question was, something along the lines of whether things
like alt tags not being there can be validated by tools, or whether that could
be part of HTML validation. Is that a correct&amp;hellip;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; W3C. You want to have HTML5, HTML4, validate &lt;em&gt;[UNINTELLIGIBLE]&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; The question, ok, the question is whether &lt;code&gt;alt&lt;/code&gt; can be associated
in some way with valid HTML5 and valid HTML4. If you don&amp;rsquo;t have an &lt;code&gt;alt&lt;/code&gt; tag
then it would simply be invalid.&lt;/p&gt;

&lt;p&gt;I think that&amp;rsquo;s unlikely to happen for a variety of reasons. What I would suggest
is.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;ll. You can tell me about it in a moment.&lt;/p&gt;

&lt;p&gt;What I would suggest, before we get there, is that there are tools that will
help you determine whether your page is accessible. None are really exceptional,
it really requires some human interaction. But I wouldn&amp;rsquo;t necessarily rely on a
validation tool to tell me whether my site is accessible. That&amp;rsquo;s kind of two
separate questions entirely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; &lt;em&gt;[UNINTELLIGIBLE]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; There are, there are, well, accessible pages will validate. I mean,
that&amp;rsquo;s the case. If you use ARIA, and you use the new, validator.nu, it
understands all the ARIA syntax, and will validate your page for you. It will
also give you warnings for things like &lt;code&gt;alt&lt;/code&gt; tags not existing.&lt;/p&gt;

&lt;p&gt;What I would suggest is that you look at things like &lt;a href=&quot;http://www.w3.org/TR/WCAG/&quot;&gt;WCAG&lt;/a&gt;. There are documents
that declare what it means to be accessible. I don&amp;rsquo;t find them necessarily
convincing, but they work really well for people like government who have to
have a checklist of things that they go through to say &amp;ldquo;this page is
accessible.&amp;rdquo;&lt;/p&gt;

&lt;p&gt;I really think it requires human interaction and human testing, but there are
tools out there that purport to tell you whether your page is accessible.&lt;/p&gt;

&lt;p&gt;Real quick, over here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; &lt;em&gt;[UNINTELLIGIBLE]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; I&amp;rsquo;m told that images will not validate without &lt;code&gt;alt&lt;/code&gt; tags. So, yay
world.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; What about access keys? They seem to be gone?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; About access keys? I don&amp;rsquo;t actually know if access keys are
supported in any browsers. Generally speaking, the support, as I understand it,
wasn&amp;rsquo;t very good, and everybody implemented it themselves anyway. My
understanding is that the best thing for you to do is to build the keyboard
support into your application that actually makes sense for your application.&lt;/p&gt;

&lt;p&gt;GMail doesn&amp;rsquo;t use access keys. GMail does everything via JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; &lt;em&gt;[UNINTELLIGIBLE]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; Yeah. The comment is that nobody uses access keys anymore. I don&amp;rsquo;t
think anyone ever used access keys, or at least they they were never well
supported.&lt;/p&gt;

&lt;p&gt;Ok, well. You did. So that&amp;rsquo;s good.&lt;/p&gt;

&lt;p&gt;I would suggest that you use JavaScript in order to script your page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; &lt;em&gt;[UNINTELLIGIBLE]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; I wouldn&amp;rsquo;t say that it&amp;rsquo;s more accessible to have access keys. To be
perfectly honest, I don&amp;rsquo;t know what the support is for access keys, for that
attribute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; I&amp;rsquo;m a strong advocate for accessibility, but my product manager not
so much. How can I push it to my product manager?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; So, the questions is how can a strong advocate for accessibility
convince business people that accessibility is important.&lt;/p&gt;

&lt;p&gt;This is a problem that everyone faces. Google faces it. You see some of the apps
that we have aren&amp;rsquo;t as accessible as they should be. We&amp;rsquo;re really working to
make them more accessible, but it hasn&amp;rsquo;t always been a priority.&lt;/p&gt;

&lt;p&gt;I think the single most important thing you can do is to look at your current
user base. Generally speaking, the number of people who can&amp;rsquo;t access a webpage
is relatively low. There aren&amp;rsquo;t an amazing number of disabled people in the
world. It is a large number, not probably not large enough in and of itself to
convince a business person that this is a really important group.&lt;/p&gt;

&lt;p&gt;What&amp;rsquo;s more important are the PR benefits, or, not even benefits, but PR harm of
people saying that they simply cannot use your website.&lt;/p&gt;

&lt;p&gt;It&amp;rsquo;s good to look at past legal cases. If we were in the USA, I&amp;rsquo;d say look at
&lt;a href=&quot;http://en.wikipedia.org/wiki/National_Federation_of_the_Blind_v._Target_Corporation&quot;&gt;the Target case&lt;/a&gt;, which was problematic for a variety of reasons. If
you&amp;rsquo;re in Israel, I&amp;rsquo;m told that there is a law coming up that will enforce
accessibility in some way for sites that are used for certain groups of people.
I know nothing about it, and I am not a lawyer, so everything I&amp;rsquo;m saying is
probably wrong.&lt;/p&gt;

&lt;p&gt;I would suggest that you look at the laws in your country. Laws are usually a
good way of convincing people that don&amp;rsquo;t otherwise want to be convinced.&lt;/p&gt;

&lt;p&gt;I think it&amp;rsquo;s probably the worst argument, but it is an effective argument for
that type of person.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUDIENCE&amp;nbsp;&amp;raquo;&lt;/strong&gt; &lt;em&gt;[UNINTELLIGIBLE]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MIKE WEST&amp;nbsp;&amp;raquo;&lt;/strong&gt; That&amp;rsquo;s a bad thing.&lt;/p&gt;

&lt;p&gt;Anything else?&lt;/p&gt;

&lt;p&gt;Great, if there are any other questions, come up. Thanks!&lt;/p&gt;
</content>
    </entry>

    
    <entry>
        <title type='text'>GDD Keynote: The HTML5 Demos</title>
        <link rel="alternate" href="https://mikewest.org/2011/11/gdd-keynote-the-html5-demos" />
        <id>https://mikewest.org/2011/11/gdd-keynote-the-html5-demos</id>
        <updated>2011-11-21T00:00:00+01:00</updated>
        <published>2011-11-21T00:00:00+01:00</published>
        <content type='html'>&lt;p&gt;I had the opportunity to present a few demos during the Chrome section of 
Saturday&amp;rsquo;s Google Developer Day in Berlin (which, incidentally, was a blast).
I expect a video to go up at some point in the vaguely near future, but, since
I got more than a few questions about it, I&amp;rsquo;ll throw the links up here with a
bit of background and credit for each. Incidentally, thanks to &lt;a href=&quot;https://plus.google.com/116059998563577101552/&quot;&gt;Paul
Kinlan&lt;/a&gt; for taking &lt;a href=&quot;https://plus.google.com/116059998563577101552/posts/18W2deUiGkB&quot;&gt;some pictures&lt;/a&gt; during the demos. I&amp;rsquo;m glad I have
something to show here as a stopgap before the video&amp;rsquo;s ready! &lt;em&gt;&lt;strong&gt;Update&lt;/strong&gt;: The
&lt;a href=&quot;https://www.youtube.com/watch?v=xQ92UEDPiZQ&quot;&gt;keynote video&lt;/a&gt; is up on YouTube, and embedded below.&lt;/em&gt;&lt;/p&gt;

&lt;iframe width=&quot;606&quot; height=&quot;370&quot; src=&quot;https://www.youtube.com/embed/xQ92UEDPiZQ?rel=0&amp;amp;start=3540&quot; frameborder=&quot;0&quot; title=&quot;Google Developer Day Berlin, 2011: Keynote&quot; allowfullscreen=&quot;allowfullscreen&quot;&gt;&lt;/iframe&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;The &lt;a href=&quot;http://mbostock.github.com/d3/talk/20111116/transitions.html&quot;&gt;first demo&lt;/a&gt; was pulled from a talk &lt;a href=&quot;http://bost.ocks.org/mike/&quot;&gt;Mike Bostock&lt;/a&gt; gave
just last week, highlighting the power of the impressive &lt;a href=&quot;http://mbostock.github.com/d3/&quot;&gt;D3.js&lt;/a&gt;. D3 is a
free JavaScript library that makes it easy to bind data to a DOM, and then
generate stunning visualizations based on those bindings. His &lt;a href=&quot;http://mbostock.github.com/d3/talk/20111116/#0&quot;&gt;entire
presentation&lt;/a&gt; is well worth checking out, and really highlight what an
often overlooked technology like SVG is capable of.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://mbostock.github.com/d3/&quot;&gt;&lt;img src=&quot;/static_content/20111121-d3.jpg&quot; alt=&quot;Check out D3, it's quite nice.&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Next, I pulled out an oldie-but-goodie: &lt;a href=&quot;http://blog.joelambert.co.uk/&quot;&gt;Joe Lambert&amp;rsquo;s&lt;/a&gt; &lt;a href=&quot;http://www.joelambert.co.uk/flux/transgallery.html&quot;&gt;Flux
Slider&lt;/a&gt;. It&amp;rsquo;s a quick demonstration of the power of CSS-based
transitions, and really well suited to venues like GDD, as it makes the
capabilities of modern browsers immediately visually apparent. If you haven&amp;rsquo;t
seen it yet, take a look. It&amp;rsquo;s another open-source library, so fiddle with
&lt;a href=&quot;https://github.com/joelambert/Flux-Slider/tree/master/js/src&quot;&gt;the code&lt;/a&gt; as well.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://www.joelambert.co.uk/flux/transgallery.html&quot;&gt;&lt;img src=&quot;/static_content/20111121-fluxslider.jpg&quot; alt=&quot;Flux Slider is pretty, play with it!&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Obviously, no HTML5 demo is complete without WebGL, and no WebGL demo is
complete without &lt;a href=&quot;http://mrdoob.com/&quot;&gt;Mr.doob&lt;/a&gt; and &lt;a href=&quot;http://mrdoob.github.com/three.js/&quot;&gt;three.js&lt;/a&gt;. I introduced the topic
by throwing a &lt;a href=&quot;http://mrdoob.com/lab/javascript/webgl/kinect/&quot;&gt;huge, Kinect-driven Mr.doob&lt;/a&gt; onto the wall behind me.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://mrdoob.com/lab/javascript/webgl/kinect/&quot;&gt;&lt;img src=&quot;/static_content/20111121-mrdoob.jpg&quot; alt=&quot;Mr.doob's Kinect-driven demo&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;I followed up the introduction with a &lt;a href=&quot;http://alteredqualia.com/three/examples/webgl_terrain_dynamic.html&quot;&gt;beautiful terrain rendering&lt;/a&gt;
from &lt;a href=&quot;http://alteredqualia.com/&quot;&gt;AlteredQualia&lt;/a&gt;. What I liked most about that demo is the fact
they they&amp;rsquo;ve pulled pieces from the &lt;a href=&quot;http://ro.me/&quot;&gt;ro.me&lt;/a&gt; project to save time and
effort. Open source is brilliant.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://alteredqualia.com/three/examples/webgl_terrain_dynamic.html&quot;&gt;&lt;img src=&quot;/static_content/20111121-terrain.jpg&quot; alt=&quot;AlteredQualia's terrain demo&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Finally, I pulled the &lt;a href=&quot;http://www.htmlfivewow.com/demos/audio-visualizer/index.html&quot;&gt;HTML5 Wow Visualizer&lt;/a&gt; from &lt;a href=&quot;https://plus.sandbox.google.com/118075919496626375791/&quot;&gt;Eric&lt;/a&gt; and
&lt;a href=&quot;http://blog.roomanna.com/&quot;&gt;Arne&lt;/a&gt;&amp;rsquo;s excellent &lt;a href=&quot;http://www.htmlfivewow.com/&quot;&gt;I/O 2011 presentation&lt;/a&gt;. It&amp;rsquo;s still the best
WebAudio API demo out there, clearly demonstrating the power of the analyzer
and showing off things that simply aren&amp;rsquo;t possible with the &lt;code&gt;audio&lt;/code&gt; tag.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://www.htmlfivewow.com/demos/audio-visualizer/index.html&quot;&gt;&lt;img src=&quot;/static_content/20111121-webaudio.jpg&quot; alt=&quot;WebAudio Visualizer demo from HTML5, the how and the wow.&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that&amp;rsquo;s it. Fiveish quick demos in about five minutes. I enjoyed it! What did
you think?&lt;/p&gt;

</content>
    </entry>

    
    <entry>
        <title type='text'>Secure Chrome extensions: Content Security Policy</title>
        <link rel="alternate" href="https://mikewest.org/2011/10/secure-chrome-extensions-content-security-policy" />
        <id>https://mikewest.org/2011/10/secure-chrome-extensions-content-security-policy</id>
        <updated>2011-10-30T00:00:00+02:00</updated>
        <published>2011-10-30T00:00:00+02:00</published>
        <content type='html'>&lt;p&gt;After reading the &lt;a href=&quot;http://mikewest.org/2011/10/content-security-policy-a-primer&quot;&gt;Content Security Policy primer&lt;/a&gt; that I wrote earlier this month, you should have a good idea of the benefits that CSP can offer a website developer. Whitelisting known-good resource origins, refusing to execute potentially dangerous inline JavaScript, and banning the use of &lt;code&gt;eval&lt;/code&gt; are all effective mechanisms for mitigating cross-site scripting attacks. Implementing and enforcing such policies is simply a good idea.&lt;/p&gt;

&lt;p&gt;Recognizing these advantages, Chrome&amp;rsquo;s engineers have extended CSP&amp;rsquo;s reach beyond websites into other areas of the browser where policies can serve as a defense against attacks. Most notably, policies can be applied to &lt;a href=&quot;http://code.google.com/chrome/extensions/apps.html&quot;&gt;packaged applications&lt;/a&gt; and &lt;a href=&quot;http://code.google.com/chrome/extensions/index.html&quot;&gt;extensions&lt;/a&gt;. Both can make use of Chrome&amp;rsquo;s powerful and modular set of &lt;a href=&quot;http://code.google.com/chrome/extensions/api_index.html&quot;&gt;extension APIs&lt;/a&gt;, which give developers capabilities above and beyond what it makes sense for the web platform to offer normal websites. To whatever extent possible, therefore, developers need to ensure that those additional capabilities aren&amp;rsquo;t leaked out to the broader web. Content Security Policies mitigate this risk by helping developers ensure that the only code that runs with elevated privileges is their own.&lt;/p&gt;

&lt;p&gt;Defining policies for an extension is quite straightforward, and we&amp;rsquo;re working to add them to all the sample extensions in the Chromium project. Walking through one of these samples together should give you a good idea of how it all works.&lt;/p&gt;

&lt;h2 id=&quot;implementation&quot;&gt;Implementation&lt;/h2&gt;

&lt;p&gt;The &lt;a href=&quot;http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/extensions/mappy/&quot;&gt;Mappy&lt;/a&gt; sample extension injects a content script into every page a user visits, searches the page for addresses, and passes them back to the extension so that a map can be displayed in the extension&amp;rsquo;s popup. This is exactly the sort of dangerous scenario in which we need to worry about malicious websites exploiting the extension&amp;rsquo;s permissions, perhaps by cleverly embedding JavaScript into the address which might then be executed if we&amp;rsquo;re not careful when it&amp;rsquo;s passed back to the extension&amp;rsquo;s context. A content security policy is absolutely necessary.&lt;/p&gt;

&lt;p&gt;The first step towards securing the extension is to define exactly which resources it needs to load. Mappy&amp;rsquo;s needs are pretty simple: it loads CSS and JavaScript from the local extension package, connects to &lt;code&gt;https://maps.googleapis.com&lt;/code&gt; to geolocate an address, and finally displays a static map image from &lt;code&gt;https://maps.google.com&lt;/code&gt;.&lt;sup id=&quot;fnref:1&quot;&gt;&lt;a href=&quot;#fn:1&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; A sufficiently paranoid policy would use a &lt;code&gt;default-src&lt;/code&gt; policy directive to deny access to &lt;em&gt;everything&lt;/em&gt; by default, and then specifically whitelist only those resources via &lt;code&gt;style-src&lt;/code&gt;, &lt;code&gt;script-src&lt;/code&gt;, &lt;code&gt;connect-src&lt;/code&gt;, and &lt;code&gt;img-src&lt;/code&gt; directives. I&amp;rsquo;ve annotated Mappy&amp;rsquo;s definition (which does exactly that) below:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# Block everything, then whitelist from there.
default-src 'none';

# Accept CSS from the extension's package.
style-src 'self';

# Accept JavaScript from the extension's package.
script-src 'self';

# Allow XHR connections over HTTPS to Google Maps APIs.
connect-src https://maps.googleapis.com; 

# Allow images from Google Maps to load over HTTPS.
img-src https://maps.google.com;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For normal websites, content security policies are delivered via an HTTP header. Chrome extensions use the same policy syntax, but define policies in the package&amp;rsquo;s &lt;a href=&quot;http://code.google.com/chrome/extensions/manifest.html&quot;&gt;manifest JSON&lt;/a&gt; as a simple key-value pair. Simply take the policy you&amp;rsquo;ve defined, and add it to &lt;code&gt;manifest.json&lt;/code&gt;: you can see how Mappy&amp;rsquo;s CSP is defined by visiting &lt;a href=&quot;http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/extensions/mappy/manifest.json?view=markup&quot;&gt;Chromium&amp;rsquo;s source repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With the &lt;a href=&quot;http://codereview.chromium.org/8311007/diff/9001/chrome/common/extensions/docs/examples/extensions/mappy/manifest.json&quot;&gt;manifest changes&lt;/a&gt; in place, the next step is to take a close look at the extension&amp;rsquo;s code to make sure we comply with the new restrictions we&amp;rsquo;re defining. Generally speaking, this means ensuring that CSS and JavaScript is moved out from the extension&amp;rsquo;s background page and popup into separate files. Most of the time, this is a straight copy/paste job, simply moving code wholesale from an inline &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; block into a &lt;code&gt;background.js&lt;/code&gt; file. For Mappy, the &lt;code&gt;background.html&lt;/code&gt; change is &lt;a href=&quot;http://codereview.chromium.org/8311007/diff/9001/chrome/common/extensions/docs/examples/extensions/mappy/background.html&quot;&gt;captured in this diff&lt;/a&gt;, and the &lt;code&gt;popup.html&lt;/code&gt; change is &lt;a href=&quot;http://codereview.chromium.org/8311007/diff/9001/chrome/common/extensions/docs/examples/extensions/mappy/popup.html&quot;&gt;visible in this diff&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That&amp;rsquo;s it! Once you&amp;rsquo;ve defined a policy, and adjusted your extension&amp;rsquo;s code to match it, just test the extension locally, bump the version number, and push the update to your users. They&amp;rsquo;ll be more secure, and the world will be a (slightly) better place.&lt;/p&gt;

&lt;h2 id=&quot;next-steps&quot;&gt;Next Steps&lt;/h2&gt;

&lt;p&gt;Your task is clear: update the extensions you own! It&amp;rsquo;s very straightforward work, and a real win for security. Content Security Policy support was added to Mappy in &lt;a href=&quot;http://crrev.com/106043&quot;&gt;revision 106043&lt;/a&gt;; take a look at &lt;a href=&quot;http://codereview.chromium.org/8311007&quot;&gt;the code review&lt;/a&gt; to get some implementation ideas for your own extensions.&lt;/p&gt;

&lt;p&gt;At the same time you&amp;rsquo;re working on your extensions, the Chromium team is working to set a better example by updating the 70 or so sample extensions and applications that Chromium makes available to include the new &lt;code&gt;content_security_policy&lt;/code&gt; manifest entry. It&amp;rsquo;s easy work &amp;ndash; following the steps listed above takes less than half-hour on average &amp;ndash; but 70 is a big number, so we&amp;rsquo;re a bit behind. You can follow our progress on that effort at &lt;a href=&quot;http://crbug.com/92644&quot;&gt;crbug.com/92644&lt;/a&gt;: star the bug if you&amp;rsquo;re interested in updates, and pitch in if you&amp;rsquo;re interested! &lt;a href=&quot;http://www.chromium.org/developers/contributing-code&quot;&gt;Patches are welcome&lt;/a&gt;: just send any code reviews my way (&lt;code&gt;mkwst@chromium.org&lt;/code&gt;).&lt;/p&gt;

&lt;div class=&quot;footnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot;&gt;
      &lt;p&gt;Whenever possible, load resources over HTTPS rather than unencrypted HTTP. This has a number of benefits for privacy and security, most importantly (for our current context) a guarantee that the code you&amp;rsquo;re loading hasn&amp;rsquo;t been modified since it left the server. Active network attackers need to do a &lt;em&gt;lot&lt;/em&gt; more work to inject code into a HTTPS stream, wheres it&amp;rsquo;s a trivial task via HTTP.&lt;a href=&quot;#fnref:1&quot; rev=&quot;footnote&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</content>
    </entry>

</feed>
