1 00:00:08,550 --> 00:00:10,250 Hi everyone, welcome to our talk. 2 00:00:10,250 --> 00:00:14,650 Today we'll be talking about securing front-ends at scale and how we imagine a post-XSS world. 3 00:00:14,650 --> 00:00:24,530 As you may have heard, XSS or cross-site scripting is a really, really hard problem to solve, but this will be a tale of a journey through tools and runtime mitigations to show how we can get to a post-XSS world. 4 00:00:25,210 --> 00:00:28,110 Before we dive into it, we'll do some introductions. 5 00:00:28,110 --> 00:00:29,290 Hi, I'm Jen. 6 00:00:29,710 --> 00:00:32,650 I've been a software engineer at Google for over three years now. 7 00:00:32,650 --> 00:00:40,410 I work on a team that mainly focuses on deploying web security mitigations across all of Google's web products. 8 00:00:40,410 --> 00:00:48,540 We have a ratio of about 1 to 100 for security to actual product engineer, so we really do care about making things work at scale. 9 00:00:50,750 --> 00:00:57,990 Hi , my name is Aaron, and like Jen, I work on deploying the latest and the greatest security mechanisms to our end users. 10 00:00:57,990 --> 00:01:08,670 Before my stint in security, I worked as a dev in some well-known Google products like Docs and GCP, so I come from the other side of the fence in the security world. 11 00:01:08,670 --> 00:01:21,350 So I approach these problems with a special amount of empathy for a developer on how we can reduce as much friction as possible so that they can focus on shipping the greatest features to the user and not worry too much about security. 12 00:01:24,170 --> 00:01:25,110 Cool. 13 00:01:25,110 --> 00:01:28,170 Now we'll get into our agenda for the day. 14 00:01:28,650 --> 00:01:48,530 We'll start with a quick introduction to cross-site scripting, and we'll talk about what XSS really is, and then we'll introduce some runtime mitigations, mainly within the umbrella of content security policy and its different flavors, and then we'll talk about how we can secure your apps against XSS at scale with some musings and imaginations about the post-XSS world to follow. 15 00:01:48,950 --> 00:01:50,330 So let's get into it. 16 00:01:50,330 --> 00:01:52,430 What is cross-site scripting? 17 00:01:52,490 --> 00:01:56,690 We've said that XSS is common, but we'd like to show you some data to back this up. 18 00:01:57,090 --> 00:02:06,930 Google runs a vulnerability rewards program to pay out security researchers when they report their bugs to us, and this is some data from our VRP program. 19 00:02:06,970 --> 00:02:11,250 As you can see, over 50% of the issues were web issues. 20 00:02:11,250 --> 00:02:11,870 This makes sense. 21 00:02:11,870 --> 00:02:13,270 Google is a web company. 22 00:02:13,330 --> 00:02:17,410 But out of those 50%, 35% are XSS. 23 00:02:17,410 --> 00:02:23,870 So this proves that XSS has been really prevalent, especially within our services, and that's why we've worked so hard to mitigate against it. 24 00:02:24,550 --> 00:02:27,370 So let's talk about what XSS really is. 25 00:02:27,370 --> 00:02:33,430 The root cause is that user input gets mixed up with code and gets interpreted as code. 26 00:02:33,490 --> 00:02:40,450 Because HTML is dynamic and mixes static data with logic that should execute, as you see here, is very prevalent. 27 00:02:40,570 --> 00:02:44,330 And this leads to malicious scripts getting injected into a trusted site. 28 00:02:44,330 --> 00:02:49,390 In this example, there's a description that's supposed to be dynamic. 29 00:02:51,430 --> 00:02:55,750 But if this is user controlled, we can inject the following script and get it to execute. 30 00:02:55,750 --> 00:02:58,230 Then we have code execution on the website. 31 00:02:59,090 --> 00:03:00,990 And what does an XSS let you do? 32 00:03:00,990 --> 00:03:05,490 An XSS, when exploited, can let the attacker take control of the account of a logged in user. 33 00:03:05,490 --> 00:03:10,730 This means the attacker can do anything the victim can, and depending on the account type, this could be very, very dangerous. 34 00:03:10,730 --> 00:03:13,730 And that's why we care a lot about mitigating. 35 00:03:14,450 --> 00:03:20,310 So we also call this the client-side version of a remote code execution, as they share a similar concept. 36 00:03:20,310 --> 00:03:22,670 And here's another format you might be used to seeing. 37 00:03:22,670 --> 00:03:28,690 XSS, we usually pop an alert with a document domain as a proof of concept when we find an XSS vector. 38 00:03:30,290 --> 00:03:36,730 So here's a quick example of a client-side variant of XSS, which is called DOM XSS. 39 00:03:36,730 --> 00:03:42,490 The root cause of this is that JavaScript APIs, specifically DOM APIs, are not secure by default. 40 00:03:42,490 --> 00:03:48,510 They can easily turn strings into code, like innerHTML is an example of this, or script.innerText. 41 00:03:48,510 --> 00:03:52,530 So here's a very simple proof of concept example of how this might happen. 42 00:03:52,530 --> 00:04:00,010 In the code snippet below, you see that we take the location hash, which is a user control string, and we assign it to innerHTML. 43 00:04:00,010 --> 00:04:04,890 We'll see the onError alert statement execute if we use the payload that you see here. 44 00:04:04,890 --> 00:04:06,990 But no one codes like this anymore, right? 45 00:04:06,990 --> 00:04:12,590 Thanks to modern frameworks like React that abstract away DOM manipulations so we don't actually have to use those DOM APIs. 46 00:04:12,590 --> 00:04:14,490 Except not! 47 00:04:14,490 --> 00:04:31,230 In this fresh bit of internet outrage, we see that this enterprising developer has managed to find a way to sneak a .innerHTML assignment call into a React component, a framework that is supposed to take care of the really complex DOM interactions and the repainting for you. 48 00:04:31,270 --> 00:04:33,130 And here's the core concept. 49 00:04:33,130 --> 00:04:41,670 Just because a framework can abstract away the complex DOM operations does not mean that it will prevent you from using these DOM APIs directly. 50 00:04:41,690 --> 00:04:43,670 And these issues are really easy to introduce. 51 00:04:43,670 --> 00:04:50,690 It just takes a developer or a code reviewer having a bad day, and once introduced, it's really hard to remove from your code base. 52 00:04:50,690 --> 00:04:54,090 So do we stand a chance against this class of problems? 53 00:04:54,470 --> 00:04:55,990 And we think we do. 54 00:04:56,130 --> 00:05:04,050 We've all heard of Content Security Policy, or CSP, as a defense against cross-site scripting, but we'll go into more detail about how we can use it. 55 00:05:04,050 --> 00:05:09,990 And CSP is famous for having a lot of directives, and a lot, a lot of directives. 56 00:05:09,990 --> 00:05:14,650 It can really turn off any sort of resource loading that happens in the browser. 57 00:05:14,650 --> 00:05:15,910 So how do we use it? 58 00:05:15,910 --> 00:05:21,890 How do we know that it's delivering the protections and it's not providing a workaround for our attackers? 59 00:05:22,290 --> 00:05:40,150 So before we go there, since you're talking about CSP headers in the context of cross-site scripting protections at scale that we use at Google, we'll start off with a well-known Google app in production, and see what they do in real life, and share a little of the story of how we got there. 60 00:05:40,590 --> 00:05:51,710 So here it is, a well-known Google web app that has a very complex user front end, and has been a champion of shipping the latest and greatest security features. 61 00:05:51,710 --> 00:05:57,910 So let's open up Chrome DevTools in the network tab and see what headers we are sending. 62 00:05:57,910 --> 00:06:05,090 We sort of encourage you to do this because this is a source of truth on what the actual mitigations we are sending to the end user is. 63 00:06:05,110 --> 00:06:10,950 And we see that there are multiple content security policy headers here. 64 00:06:11,110 --> 00:06:20,070 And we'll start out with a caveat that CSP, like we mentioned before, is really a meta feature rather than just a cross-site scripting protection mitigation. 65 00:06:20,290 --> 00:06:26,170 And we really have a lot of different configurations that protect against different potential threats. 66 00:06:26,170 --> 00:06:33,950 Essentially, it was designed to lock down any sort of resource loading on the page, so not all of these headers are specifically for our cross-site scripting defense. 67 00:06:34,170 --> 00:06:40,550 And so we'll look at these two in particular, which are sort of used for cross-site scripting defense. 68 00:06:40,710 --> 00:06:46,110 And we'll focus on these ones, nonce-only CSP and trusted types. 69 00:06:46,110 --> 00:06:55,630 So in the next section, we will go through how these mechanisms work and work in conjunction, and why we believe they are a suitable defense against cross-site scripting. 70 00:06:57,390 --> 00:06:58,070 Cool. 71 00:06:58,070 --> 00:07:01,170 And we'll start with the nonce-only CSP here. 72 00:07:01,590 --> 00:07:05,730 And the example that we saw before, it's kind of pretty self-evident. 73 00:07:05,730 --> 00:07:09,490 It's the one that has the nonce directive, just like you can see here. 74 00:07:09,970 --> 00:07:14,350 And more specifically, a nonce-only policy takes a form that looks like this. 75 00:07:14,450 --> 00:07:23,730 Internally, we recommend a nonce-only or strict CSP for most of our modern apps, and only what is allowed under script source here can run on the page. 76 00:07:23,910 --> 00:07:26,110 In this case, any script with a nonce. 77 00:07:26,110 --> 00:07:37,490 You can think of a nonce as a one-time random value that's sent both by the HTTP headers and in the HTML, and the browser verifies that both of those values match before running any script. 78 00:07:37,490 --> 00:07:45,370 So in this case, we use templating systems to propagate the nonce, and the header and the HTML work together to indicate which scripts are trusted. 79 00:07:46,850 --> 00:07:50,550 Another CSP directive that we want to point out here is strict-dynamic. 80 00:07:50,550 --> 00:07:53,950 This directive enables transitive trust for scripts. 81 00:07:54,230 --> 00:07:59,570 So if you have one script with the right nonce, it's allowed to load other scripts, and the trust is propagated. 82 00:07:59,630 --> 00:08:05,670 When we don't have this directive, only scripts with the right nonce can execute on the page, and they're not allowed to load other scripts. 83 00:08:05,670 --> 00:08:07,970 If they do, it's not allowed to run on the page. 84 00:08:08,210 --> 00:08:14,890 Although this slightly relaxes the policy, in our experience, it's also made adoptions a lot easier for complex web apps. 85 00:08:14,890 --> 00:08:21,890 You can have one loader script that loads all the necessary scripts, and deploying content security policy becomes a lot easier. 86 00:08:23,690 --> 00:08:24,390 Great. 87 00:08:24,390 --> 00:08:24,950 Thanks, Jen. 88 00:08:24,950 --> 00:08:35,650 So as Jen mentioned, a nonce-only policy, a nonce-only content security policy is great if you have the backend or the server-side rendered content working together with the frontend or the client-side code. 89 00:08:35,650 --> 00:08:38,510 But what if we don't have control over the backend? 90 00:08:38,510 --> 00:08:42,990 Then we can use a relative of the nonce-only policy, the hash-based CSP. 91 00:08:44,410 --> 00:08:46,850 And a hash-based CSP looks like this. 92 00:08:46,850 --> 00:08:55,270 So instead of having a nonce under the script source, it has a hash of the scripts that are allowed to load on the page. 93 00:08:55,270 --> 00:09:13,110 This is more useful for scenarios where you really don't have control of the serving infrastructure, so we really need to embed this policy into the HTML response itself, and have a guarantee that it'll run on the HTML, even if we can't modify bits of it to inject the nonce at every page load. 94 00:09:13,590 --> 00:09:22,370 And this is an especially powerful use case for SPAs because they have an initial bundle of JavaScript that they need to load, and it's a fixed value. 95 00:09:22,370 --> 00:09:31,630 We know this at compile time, we can generate a hash knowing that it is a safe bit of JavaScript to run, and we can embed it on the page itself, as we see here. 96 00:09:31,630 --> 00:09:35,510 So following this suggestion, we have this potential transformation of a SPA. 97 00:09:35,510 --> 00:09:43,610 On the left, we have maybe an index.html of an app that will bootstrap some SPA, a single-page application. 98 00:09:43,610 --> 00:09:52,970 So when we turn the script tags with source attributes into an inline loader script tag, we can hash the contents to include this CSP. 99 00:09:53,190 --> 00:09:58,390 And we can combine this approach with a meta tag, so we don't even have to set a header in the response. 100 00:09:58,390 --> 00:10:02,770 The HTML itself contains a CSP that we want to ship. 101 00:10:02,770 --> 00:10:10,930 So no matter what stack you use to serve this HTML blob, you will always have this content security policy associated with it. 102 00:10:10,930 --> 00:10:16,790 And we'll talk a bit more in the next several slides about some of the tooling that can automate this. 103 00:10:18,780 --> 00:10:19,460 Cool. 104 00:10:19,460 --> 00:10:23,340 Now, on to the next flavor of CSP, we have trusted types. 105 00:10:23,340 --> 00:10:29,900 This is, again, another CSP-delivered mitigation that we think is really powerful, specifically against DOM-based XSS. 106 00:10:29,900 --> 00:10:35,260 The example we saw before, it's this one with the require-trusted-types-for directive. 107 00:10:35,720 --> 00:10:40,120 And we want to point out that the attack surface is very large here for DOM XSS. 108 00:10:40,120 --> 00:10:45,000 I mentioned that JavaScript APIs, specifically DOM APIs, are insecure by default. 109 00:10:45,000 --> 00:10:50,040 And there's over 60 of them that can take strings and turn them into code execution. 110 00:10:50,180 --> 00:10:55,640 DOM XSS is usually very, very easy to introduce and hard to detect, as Aaron alluded to before. 111 00:10:55,640 --> 00:11:02,120 And calls to these APIs could be going through multiple levels of indirections, and could exist in libraries that we don't have control over. 112 00:11:02,120 --> 00:11:04,500 So we were thinking, how can we make it better? 113 00:11:04,500 --> 00:11:06,560 And this is where trusted types comes in. 114 00:11:06,560 --> 00:11:12,640 We need a runtime mitigation to provide some sort of type checking on top of JavaScript. 115 00:11:12,640 --> 00:11:14,720 And this is exactly what trusted types does. 116 00:11:14,720 --> 00:11:25,520 The main idea behind it is to make security decisions explicit and auditable as well, because usually when we use these DOM APIs, all of the security decisions seem implicit in the code. 117 00:11:25,520 --> 00:11:35,560 So to do this, trusted types will restrict the access to dangerous DOM APIs that we mentioned before, and it'll require typed objects instead of plain strings to be passed into these DOM APIs. 118 00:11:35,560 --> 00:11:47,300 So as you can see here, whereas before we would have had a string that represented HTML, a string that represented some sort of script, we have explicitly typed objects called trusted HTML, trusted script, or script URL. 119 00:11:47,300 --> 00:11:56,880 We'll talk about how we generate these trusted and typed objects later in the slides, but this is the general idea behind how this protects against DOM XSS. 120 00:11:57,580 --> 00:12:04,580 And just so we have it clear and plain on the slide, this is how the header will look like if you're enforcing trusted types. 121 00:12:04,660 --> 00:12:12,640 This tells the browser to reject string assignments to those injection syncs, and effectively provides a runtime type checking mechanism on top of JavaScript. 122 00:12:13,120 --> 00:12:19,240 So let's go back to the example we saw on our DOM XSS slide and see how trusted types would work in this case. 123 00:12:19,280 --> 00:12:23,460 As you can see here, we're using a plain string and assigning it to inner HTML. 124 00:12:23,620 --> 00:12:27,720 And if trusted types are enforced, the browser will throw an error that looks like this. 125 00:12:27,720 --> 00:12:32,280 And it tells us that we need a trusted HTML object instead of the string that we're trying to use. 126 00:12:33,160 --> 00:12:34,860 And here we are. 127 00:12:34,940 --> 00:12:38,400 This is what a trusted types policy looks like. 128 00:12:38,740 --> 00:12:43,440 This is what I mentioned previously about how we can generate these trusted objects. 129 00:12:43,440 --> 00:12:48,140 We want to highlight that most of the security guarantees of trusted types come from a policy. 130 00:12:48,140 --> 00:12:58,160 You can think of a policy as a wrapper that takes in a string, applies some sort of processing to it, and returns a trusted type, whether it's trusted HTML or script or script URL. 131 00:12:58,180 --> 00:13:02,100 We apply this policy to strings before inserting them into the DOM. 132 00:13:02,120 --> 00:13:07,860 And the processing you do within the policy should make sure that the string won't lead to any unintended code execution. 133 00:13:07,860 --> 00:13:10,180 And that's how we can prevent DOM XSS. 134 00:13:10,180 --> 00:13:14,160 In this example, we're specifically concerned about HTML. 135 00:13:14,520 --> 00:13:17,720 So we use a sanitizer from DOM Purify. 136 00:13:17,720 --> 00:13:27,340 We check for the presence of trusted types in the JavaScript namespace for browser compatibility on the if statement, and then use the correct factory if it exists. 137 00:13:27,340 --> 00:13:36,060 But if you don't want to keep writing this verbose block, and it could be quite long, DOM Purify also works with trusted types off the shelf. 138 00:13:36,060 --> 00:13:42,340 It'll do the browser checking under the hood if you pass in the right config here, and it'll also generate the trusted types policy for you. 139 00:13:42,340 --> 00:13:43,360 So it's quite handy. 140 00:13:45,960 --> 00:13:46,560 Great. 141 00:13:46,560 --> 00:13:47,100 Thanks, Jen. 142 00:13:47,100 --> 00:14:00,000 So now that we've talked about the security features of what we believe to be powerful tools against cross-site scripting today, we'll touch a bit on how we use them in your application and offer a bit of lessons learned from securing our apps at Google scale. 143 00:14:00,400 --> 00:14:07,940 So before we begin, we'd like to make a quick plug for an article that presents many of the ideas that we'll discuss in this next section, but in written form. 144 00:14:07,940 --> 00:14:17,060 This approach is used widely within our team and not just within our web scope, and the article goes into a bit more detail in some of these ideas than we have time for in this talk. 145 00:14:17,060 --> 00:14:18,400 So please check us out. 146 00:14:18,400 --> 00:14:25,000 It's on the Google Security Engineering blog at bughunters.google.com, and along with some other great content. 147 00:14:25,040 --> 00:14:26,960 So yeah, we hope to see you there. 148 00:14:27,640 --> 00:14:31,880 So a quick overview of what we are going to talk about in this section. 149 00:14:32,020 --> 00:14:35,760 Number one, if you use the right frameworks, it'll give you superpowers. 150 00:14:35,760 --> 00:14:45,540 Number two, we need to shift left as much as possible so that we can get feedback to developers on whether the code that they're writing is compatible or incompatible. 151 00:14:45,540 --> 00:14:52,980 Number three, some tools that we found helpful in this process of looking for possible incompatibilities with these features. 152 00:14:52,980 --> 00:14:57,320 And number four, a quick note about third-party dependencies. 153 00:14:58,200 --> 00:15:02,320 So onto our first big idea, frameworks that give you superpowers. 154 00:15:03,060 --> 00:15:08,400 So the idea here is the basis of our at-scale defense against cross-site scripting at Google. 155 00:15:08,660 --> 00:15:27,220 Frameworks with context-aware templating, and that means we assemble the HTML in a way that we don't end up doing inadvertent injections into the HTML, and built-in compatibility with these security features, and also frameworks that are secure by default and secure by design. 156 00:15:30,140 --> 00:15:44,620 So a part of this safe coding philosophy at Google, and this is a term that we'll use for a lot throughout this section, is giving the right tools to developers so that they don't have to worry so much about whether they have the security configurations correct, 157 00:15:44,620 --> 00:15:48,920 and really they can focus on shipping the features to the users. 158 00:15:48,920 --> 00:15:52,640 And we really don't want the security to get in the way of development, right? 159 00:15:52,640 --> 00:15:57,480 Because that is how you get developers to turn against security. 160 00:15:57,480 --> 00:16:09,160 So having frameworks that do not work against you as you try to ship wonderful and secure code is really the basis, and a big part of it is having compatibility with the features that you want to enforce. 161 00:16:09,160 --> 00:16:20,600 And this is possible at Google because we have tight control over our internal frameworks, and also over our advice that we give to our internal developers on how to use these frameworks. 162 00:16:20,600 --> 00:16:24,100 But what if you aren't building web apps inside of the Google ecosystem? 163 00:16:24,100 --> 00:16:26,060 How can we get some of these benefits? 164 00:16:26,480 --> 00:16:34,480 And thankfully, our colleagues have worked hard to ensure compatibility with these powerful security features and some other frameworks as well. 165 00:16:34,480 --> 00:16:45,620 For instance, all the work that we did to harden Angular and Lit, frameworks that we do also use internally as well, contribute back to the open source ecosystem of developers who also use these frameworks. 166 00:16:45,620 --> 00:16:48,980 But our contributions aren't only to Google-sponsored frameworks. 167 00:16:48,980 --> 00:17:02,640 Our friends at also worked hard to make React compliant with their web security strategy, and we've also submitted PRs to other React-based frameworks like Next.js to work well with their suggested security features as well. 168 00:17:03,140 --> 00:17:13,140 The next point is that we really want to get feedback about whether we've potentially written code that is incompatible with these security features as early in the process as possible. 169 00:17:13,140 --> 00:17:23,940 And really, in this approach of shifting left, it's about either adding a header that enforces content security policy and trust types early on, or meta tags that do the same. 170 00:17:24,040 --> 00:17:29,320 So if you have control of their backend server infrastructure, we can just set our headers there, right? 171 00:17:29,320 --> 00:17:35,380 And for instance, we hear that the web bundler and dev server of choice now is Vite. 172 00:17:35,380 --> 00:17:45,040 So here is an example that will work in Vite, a code snippet of middleware written as a Node Express middleware because Vite accepts those. 173 00:17:45,040 --> 00:17:52,160 So you can set these headers and have it enforce the content security policies. 174 00:17:52,360 --> 00:18:04,760 But really, this approach is applicable to any framework-agnostic place where you do have the opportunity to change the response headers in the middleware. 175 00:18:04,760 --> 00:18:20,560 But if you don't, if you're maybe building just a client-rendered single-page application, an SBA, and you don't have necessarily a lot of control over where it will eventually be served, we can also use meta tags like we discussed before. 176 00:18:20,560 --> 00:18:26,120 And this HTML snippet will stay with the rest of your HTML-generated bundles. 177 00:18:26,120 --> 00:18:28,640 So yeah, it really can't become unglued. 178 00:18:28,640 --> 00:18:34,940 So one word of warning about using the meta tag approach, however, is that report-only mode does not work very well. 179 00:18:34,940 --> 00:18:43,340 So it's really useful when used really early in the development process, when you start a new codebase to catch these violations early on. 180 00:18:44,240 --> 00:18:50,880 And for the observant among you, you'll see that this example here uses the hash-based CSV policy that we talked about before. 181 00:18:51,140 --> 00:19:05,540 And as we mentioned earlier, it's possible to take all of your script loading, turn it into a script block that is hashable, but it's sort of tedious to go through all of the script tags in your code and generate the hashes and add them to your CSV. 182 00:19:05,540 --> 00:19:08,220 So is there a way to do this a bit more quickly? 183 00:19:08,300 --> 00:19:13,740 And thankfully, we have a package that will do a lot of this for you available on GitHub and NPM. 184 00:19:14,920 --> 00:19:34,060 And this is shipped as both a webpack plugin and as well as just a string-to-string transformation library that you can put in your bundling and building step to have your HTML automatically extract the script tags, hash them, and then add the meta tag back in. 185 00:19:34,760 --> 00:19:51,060 And this framework agnostic approach to having these plug-and-play parts is really important because if you remember this middleware example from a couple slides ago, you can basically copy-paste the string transformation right into the middleware itself. 186 00:19:51,060 --> 00:19:59,700 And this will add the meta tags or the CSP to any response body of the HTML using that library that we just talked about. 187 00:19:59,700 --> 00:20:07,340 So it's really a plug-and-play approach and a framework agnostic way that we really want to build these tools around. 188 00:20:09,680 --> 00:20:10,360 Cool. 189 00:20:10,360 --> 00:20:11,160 Thanks, Erin. 190 00:20:11,320 --> 00:20:18,920 So in addition to using the headers to spot violations, early we advocate for some other tools to help you with adopting these defenses. 191 00:20:18,920 --> 00:20:27,940 And we'll introduce a bunch of helpful tools, but they can categorically be broken down into, first of all, tools that can help us understand the configurations and violations. 192 00:20:28,140 --> 00:20:31,580 We mentioned that CSP is notoriously hard to configure and understand. 193 00:20:31,580 --> 00:20:34,680 They have so many directives that could be combined in various different ways. 194 00:20:34,680 --> 00:20:36,920 And the CSP evaluator solves that problem. 195 00:20:36,920 --> 00:20:48,600 It's available as either a website or a Chrome extension, which will give you some high-level guidance on the configuration of your CSP or of the CSP of any websites that you visit if you use it as a Chrome extension. 196 00:20:49,320 --> 00:20:54,920 We're also actively working on a tool called the Trusted Types Helper for streamlining the Trusted Types adoption process. 197 00:20:54,920 --> 00:21:02,200 We found that one of the most time-consuming stages of a Trusted Types rollout is finding the source of the violations and fixing them. 198 00:21:02,200 --> 00:21:07,940 This Chrome extension will create a DevTools tab that helps you demystify Trusted Types violations and suggest refactorings. 199 00:21:07,940 --> 00:21:10,080 Stay tuned for this release. 200 00:21:10,360 --> 00:21:17,020 Another category of tools that we advocate for are those that help with refactoring using Static Analysis. 201 00:21:17,560 --> 00:21:30,760 At Google, we have a huge Static Analysis pipeline, and we always believe that Static Analysis goes hand-in-hand with runtime mitigations to complete the cycle and provide comprehensive protections against these attacks. 202 00:21:30,760 --> 00:21:38,440 We took the most effective checks that we run on our internal linter and Static Analysis tooling and built it on top of ESLint, and you have Safety Web. 203 00:21:38,440 --> 00:21:42,880 This is also under active development, but it is available on GitHub. 204 00:21:43,220 --> 00:21:54,120 As you can see in the example here, it'll detect unsafe usages of risky APIs, and once it detects those, you can refactor these unsafe calls with another tool that we provide, which is Safe Values. 205 00:21:54,120 --> 00:21:57,920 This is a library designed to steer developers to make safer choices. 206 00:21:57,920 --> 00:22:04,320 Aaron alluded to this principle we have, which is secure by design, and this embodies all of those principles. 207 00:22:04,320 --> 00:22:14,240 Safe Values will prevent unsafe assignments using type checking unless the value is trusted, either from a trusted source or by a transformation that makes it trusted, such as sanitizing. 208 00:22:14,240 --> 00:22:20,960 It really tries to make doing the right thing really easy and doing the insecure thing really, really hard for developers. 209 00:22:21,940 --> 00:22:27,980 Another big aspect that we want to make a warning about is third-party dependencies. 210 00:22:27,980 --> 00:22:33,840 This is a big aspect of making your application compatible with the features we described before. 211 00:22:35,120 --> 00:22:38,880 So third-party dependencies, quite honestly, is hard. 212 00:22:38,880 --> 00:22:44,400 For both trusted types and CSP, all the code running on your site needs to be free of violations of these policies. 213 00:22:44,400 --> 00:22:51,620 Otherwise, calls to APIs or running the script will be blocked by the browser, and then you might have a feature breakage, which is not what we want. 214 00:22:52,000 --> 00:23:06,380 This is a hard part because we won't always know which dependencies are incompatible until we've introduced them, and it's also hard to fix because the potential refactoring sites don't exist within our code, but in code that others have written, and it could even be in transitive dependencies, 215 00:23:06,380 --> 00:23:07,980 which is multiple levels deep. 216 00:23:08,000 --> 00:23:18,620 So we're currently working on tooling that will make informed decisions about which dependencies might be compatible with which features in the ecosystem, but this is a part where we can use your help as well. 217 00:23:18,640 --> 00:23:27,800 So as CSP and trusted types gain more widespread browser adoption, you can help us by making pull requests if you do end up patching third-party dependencies in your own refactoring journey. 218 00:23:27,800 --> 00:23:29,020 We would really appreciate it. 219 00:23:30,260 --> 00:23:31,620 All right, thanks, Jen. 220 00:23:31,620 --> 00:23:42,900 So we talked a lot about mitigations that we run and the tools that we use today to protect our apps, but let's talk a bit more about where we go from here and the more secure world that we'd like to see in the future. 221 00:23:43,000 --> 00:23:48,660 So to summarize, here are the pillars that we touched on to move towards a post-cross-site scripting world. 222 00:23:48,660 --> 00:23:55,800 The running theme is abstracting security decisions away from the developer in a clear and secure by default way. 223 00:23:56,740 --> 00:24:10,120 So when all of these elements work together, starting from the first stage when code is written all the way to the final point when the code is executed in the client's browser, we have protection at every stage of the development and deployment lifecycle. 224 00:24:10,200 --> 00:24:13,360 And this should make cross-site scripting mostly solvable. 225 00:24:13,360 --> 00:24:18,640 And we see this working at Google at scale on our most recent in-house frameworks. 226 00:24:18,700 --> 00:24:28,800 We see so few cross-site scripting in these frameworks, and none of them are trivial and allow them to involve a logic bug or a legacy system and some really complex attack chain. 227 00:24:28,800 --> 00:24:31,320 So where can we go from here? 228 00:24:31,980 --> 00:24:35,660 So we saw that trusted types is a complex mechanism to adopt. 229 00:24:35,660 --> 00:24:40,900 We can restrict the usages of dangerous DOM APIs, but we haven't gotten rid of them completely. 230 00:24:40,900 --> 00:24:45,780 We still need to create policies to maybe allow list some limited usages of them. 231 00:24:45,780 --> 00:24:49,680 We need to refactor away other code patterns that still use them. 232 00:24:49,680 --> 00:25:01,800 But can you imagine a world where we can build apps to return off all usages of these DOM APIs to give as strong of a guarantee as possible that there are no potential DOM cross-site scripting injection points? 233 00:25:02,900 --> 00:25:05,800 And that's a future vision of where we want to go from here. 234 00:25:05,800 --> 00:25:24,120 If you have new platform-level APIs for operations that people use the DOM APIs for currently, say maybe a browser-included sanitizer implementation for HTML, or maybe a templating solution, then we've come full circle and have our runtime enforcements influence a new suite of secure-by-default, 235 00:25:24,120 --> 00:25:33,740 secure-by-design, web platform APIs and primitives to bring decisions that nudge developers towards safer choices at the very beginning of the pipeline. 236 00:25:34,800 --> 00:25:51,260 And this is a future that we can all hope to get to one day, where we can lock down all access to the DOM APIs, along with a new suite of platform APIs, so that we don't really have to rely on them to build dynamic and amazing web applications for our users. 237 00:25:51,260 --> 00:25:58,520 And this approach, we've sort of nicknamed the perfect types, and we see this as the next evolution of trusted types. 238 00:25:58,520 --> 00:26:13,380 So this approach of turning off access to all DOM APIs, combined with a strict CSP and other framework-based solutions so that we can still build rich user interfaces for our users, we should get us to this new post-cross-site scripting world. 239 00:26:14,440 --> 00:26:27,420 And stepping out for an even bigger picture here, we'd like to make a final plug for this safe coding philosophy and safe-by-design, trying to steer developers in the right direction towards you by using the tools that we offer them. 240 00:26:27,420 --> 00:26:37,020 It's something that extends beyond our work in solving just cross-site scripting or even the web sphere at Google, and is a core priority for all of Google-scale security. 241 00:26:37,020 --> 00:26:52,540 You can read more about our organization's work at these links, and Google is a signer of the CSS Secure by Design pledge, along with a consortium of other industry and government leaders in the space, to commit to sharing our knowledge in how to do this better with everyone. 242 00:26:54,160 --> 00:26:56,720 Cool, and that is sort of the end of our talk. 243 00:26:56,720 --> 00:26:58,660 We want to thank you all for listening. 244 00:26:58,660 --> 00:27:03,200 Hopefully this was a good guide on how to think about solving XSS and how to do it at scale. 245 00:27:03,280 --> 00:27:07,620 Feel free to reach out to us with any questions related to our tools or some of these mitigations. 246 00:27:07,700 --> 00:27:10,300 We'll be happy to have a conversation. 247 00:27:10,760 --> 00:27:16,060 And I want to add a last plug to please help us fix the open source ecosystem. 248 00:27:16,060 --> 00:27:24,060 We try our best to upstream any of the patches that we have internally, but the whole JS ecosystem will be safer and more usable if we all work together. 249 00:27:24,060 --> 00:27:24,560 Thanks!