1 00:00:02,040 --> 00:00:04,220 Hello, my name is Aaron. 2 00:00:04,220 --> 00:00:06,080 And I guess I have to apologize. 3 00:00:06,080 --> 00:00:12,340 The resemblance is a little hard to see in that picture, because my hair is not nearly as luscious as it is in that photo. 4 00:00:12,380 --> 00:00:17,800 But I'm sorry, your mineral content in the water, as you've all found out, really awful here. 5 00:00:18,700 --> 00:00:21,780 But yeah, like Jen, I work at Google. 6 00:00:21,780 --> 00:00:25,560 We do web security on hundreds and thousands of different web apps. 7 00:00:25,560 --> 00:00:28,140 I've been at Google for a little under seven years. 8 00:00:28,140 --> 00:00:31,360 And before my stint in security, I came from the developer side. 9 00:00:31,360 --> 00:00:35,760 I've worked on products like Google Docs and GCP on customer facing stuff. 10 00:00:35,760 --> 00:00:51,080 So when we approach this work of trying to make our web apps as secure as possible, we approach it with a special empathy for the developer, where we want to ship the most secure products, but also we don't want to get in the way of delivering really dynamic and new user features. 11 00:00:51,840 --> 00:00:52,460 Cool. 12 00:00:52,460 --> 00:00:53,360 Thanks, Aaron. 13 00:00:53,540 --> 00:00:55,840 Here's a quick look at our agenda for today. 14 00:00:55,840 --> 00:00:58,940 So we'll start with a quick intro to XSS. 15 00:00:58,940 --> 00:01:02,320 I assume most of you are familiar with it, but we'll still go over some examples. 16 00:01:02,600 --> 00:01:08,140 And then we'll talk about runtime mitigation, specifically those that come with content security policy and its different flavors. 17 00:01:08,260 --> 00:01:12,100 Then we'll talk about how we use those to secure applications at scale. 18 00:01:12,460 --> 00:01:16,980 And we'll move on to how we imagine the post-XSS world and end with a call to action. 19 00:01:17,720 --> 00:01:18,460 Cool. 20 00:01:18,560 --> 00:01:20,060 So cross-site scripting. 21 00:01:20,900 --> 00:01:23,900 It's just some data to motivate that this is a big problem. 22 00:01:24,000 --> 00:01:30,240 Google runs a vulnerability reward program where we pay out security researchers when they report their bugs to us. 23 00:01:30,720 --> 00:01:34,980 As you can see here, over 50% of the bugs reported are web-related. 24 00:01:34,980 --> 00:01:35,540 That makes sense. 25 00:01:35,540 --> 00:01:37,100 Google is a web company. 26 00:01:37,200 --> 00:01:43,080 And then the rest, out of those 50%, almost 35% are XSS. 27 00:01:43,080 --> 00:01:48,200 So this was a really big problem, and that's why we've developed techniques to remediate the stats at scale. 28 00:01:48,540 --> 00:01:51,200 So let's talk about what XSS really is. 29 00:01:51,200 --> 00:01:56,060 The root cause is user input gets mixed up with code and then gets interpreted as code. 30 00:01:56,080 --> 00:02:02,840 Because HTML is dynamic and mixes static data with logic that should execute, as you see here, this is very prevalent. 31 00:02:02,840 --> 00:02:06,800 And this leads to malicious scripts getting injected into a trusted site. 32 00:02:06,880 --> 00:02:16,700 In this example, you see a very simple example, there's a description that's supposed to be dynamic, but if this is user-controlled, we can inject the following script and get it to execute. 33 00:02:16,700 --> 00:02:18,160 And there you have an XSS. 34 00:02:18,940 --> 00:02:24,140 An XSS, when exploited, lets the attacker take control of the account of a logged-in user. 35 00:02:24,140 --> 00:02:29,520 This means the attacker can do anything the victim can, so it's pretty powerful, and that's why we try really hard to avoid it. 36 00:02:29,640 --> 00:02:37,060 We also call this the client-side version of remote code execution, as they share a similar concept of arbitrary code execution. 37 00:02:37,260 --> 00:02:41,160 And here's another format you might be used to seeing XSS. 38 00:02:41,160 --> 00:02:46,320 We usually pop an alert with the document domain as a proof of concept when we find an XSS record. 39 00:02:47,200 --> 00:02:53,240 So a quick example of DOM XSS, the client-side variant of cross-site scripting. 40 00:02:53,240 --> 00:02:57,220 The root cause here is DOM APIs are not secure by default. 41 00:02:57,220 --> 00:03:05,060 We all love JavaScript, and JavaScript loves turning strings into code through APIs like innerHTML or script.innerText. 42 00:03:05,140 --> 00:03:07,940 Here's a very simple example of how this might happen. 43 00:03:07,940 --> 00:03:11,060 In this code snippet, locationHash is a user-controlled string. 44 00:03:11,060 --> 00:03:13,860 We take that and happily insert it into innerHTML. 45 00:03:13,940 --> 00:03:20,620 In this case, with the example here, the onError alert statement will execute, and then we have XSS. 46 00:03:20,620 --> 00:03:22,380 But no one codes like this anymore, right? 47 00:03:22,380 --> 00:03:27,200 Thanks to modern frameworks like React that abstract away file manipulations, nobody has to do this. 48 00:03:29,580 --> 00:03:30,980 Except... not. 49 00:03:30,980 --> 00:03:41,620 As you can see in this fresh bit of internet outrage, an enterprising developer has managed to work in a innerHTML assignment inside a very functional React component. 50 00:03:41,620 --> 00:03:52,140 It's supposed to be a really advanced system that takes care of the virtual DOM dipping, all of the different re-rendering things, so that you don't have to do this yourself, but this developer didn't really want to take it into their own hands. 51 00:03:52,140 --> 00:03:54,140 And this is the crux of the problem. 52 00:03:54,140 --> 00:04:01,480 Just because a framework can abstract away the complex DOM operations doesn't mean that it can prevent a developer from using them. 53 00:04:01,480 --> 00:04:04,540 And these issues are really easy to introduce in your codebase. 54 00:04:04,540 --> 00:04:12,540 It really takes a developer, a code reviewer, having a bad day and once it sneaks into your product then it's really hard to eradicate. 55 00:04:12,540 --> 00:04:15,740 So do we stand a chance against this class of problems? 56 00:04:16,060 --> 00:04:17,160 And we think we do. 57 00:04:17,160 --> 00:04:22,240 We've all heard of content security policy and how it can solve all your process scripting, right? 58 00:04:22,240 --> 00:04:28,580 Well, we do admit that content security policy is a little bit difficult to understand and configure. 59 00:04:28,660 --> 00:04:32,040 It really is more like a meta feature than a feature. 60 00:04:32,040 --> 00:04:36,780 It has a lot of bells and whistles and knobs that you can change, a lot of directives. 61 00:04:36,780 --> 00:04:38,420 What do you have to set on these directives? 62 00:04:38,420 --> 00:04:44,640 And it is a little confusing because it tries to cover everything, any sort of resource that loads on your page. 63 00:04:44,640 --> 00:04:58,020 But hopefully when we go on this journey together, we can talk about some of the configurations that we found to work at scale and cover many classes of cross-site scripting and we'll see why they work together. 64 00:04:58,540 --> 00:05:10,740 And before we begin, since we are talking about cross-site scripting and CSP and protections that Google uses, maybe we'll take a look at what is actually working in the wild. 65 00:05:10,740 --> 00:05:15,220 So here we have an example of a particular Google web app that some of you may have used. 66 00:05:15,220 --> 00:05:21,980 You know it has a really complicated UI with a lot of interactive user features and a small call out to this team. 67 00:05:21,980 --> 00:05:31,640 They've been great partners in really shipping the best and greatest and the latest web protection mitigations and working really hard to keep their end users safe. 68 00:05:31,660 --> 00:05:36,620 So let's open up Chrome DevTools and see what we are actually shipping on a real life product. 69 00:05:36,900 --> 00:05:43,180 And as you can see here, we see a couple different content security policies, a lot of them as a matter of fact. 70 00:05:43,180 --> 00:05:54,120 But like we said before, not all of them are specifically for cross-site scripting defenses because it's a meta feature that can also turn off other potential dangerous vectors as well. 71 00:05:54,120 --> 00:06:01,860 We don't have time to get into the other protections, but if you have questions, we will be sticking around for a little bit after we can go into more detail after the talk. 72 00:06:01,860 --> 00:06:13,460 But for now, we'll focus on these two, the ones that we find to be really powerful protections against cross-site scripting, namely the nonce-only CSP and the trusted types header. 73 00:06:14,700 --> 00:06:17,140 Cool, and we'll go into some details. 74 00:06:17,140 --> 00:06:22,580 So nonce-only CSP, in the example we saw before, it's pretty self-explanatory. 75 00:06:22,580 --> 00:06:24,600 It's the one with the nonce directive. 76 00:06:25,360 --> 00:06:30,000 More specifically, a nonce-only policy takes a form that looks a bit like this. 77 00:06:30,000 --> 00:06:34,820 Internally, we recommend a nonce-only or a strict CSP for most of our modern web apps. 78 00:06:34,820 --> 00:06:39,960 What this does is only what's allow-listed under the script source directive can run on the page. 79 00:06:39,960 --> 00:06:41,480 Other scripts will be blocked. 80 00:06:41,480 --> 00:06:48,740 So in this case, any script with the right nonce, which is a random value that's generated per request, can run on the page. 81 00:06:48,740 --> 00:06:56,800 So the templating systems usually propagate the nonce for each script tag on the HTML, and the header has to send the right value for the nonce. 82 00:06:56,800 --> 00:07:01,840 So the header and the HTML work together to indicate which scripts are trusted, and the browser can act accordingly. 83 00:07:02,480 --> 00:07:07,680 Another CSP directive that's useful for a nonce-only policy is the strict dynamic directive. 84 00:07:07,680 --> 00:07:11,040 This directive enables a transitive trust for scripts. 85 00:07:11,040 --> 00:07:16,740 So if you have one script with the right nonce, it's allowed to load other scripts, and the trust is propagated. 86 00:07:16,920 --> 00:07:20,560 When we don't have this directive, only scripts with the right nonce can execute. 87 00:07:20,560 --> 00:07:22,640 If they load other scripts, they'll be blocked. 88 00:07:23,320 --> 00:07:30,100 So although this slightly relaxes the policy, we found that it's also made adoptions a lot easier for complex web apps. 89 00:07:30,100 --> 00:07:32,540 So that's the trade-off that we're working on. 90 00:07:33,820 --> 00:07:34,980 So thanks, Jen. 91 00:07:34,980 --> 00:07:47,740 So as Jen mentioned, a nonce-only CSP is great if you have the back-end or the server-side render content working in close conjunction with the front-end or client-side code, because you have to generate these nonces that are new for every single response. 92 00:07:47,940 --> 00:07:50,360 But what if you don't have control over the back-end? 93 00:07:50,360 --> 00:07:55,040 Then we have to use a close relative of the nonce-only CSP called the hash-based CSP. 94 00:07:55,060 --> 00:08:02,740 And the way it works is, it's very similar to a nonce-based policy, but as you've noticed, instead of the nonce value, we provide a hash value. 95 00:08:02,740 --> 00:08:09,040 And this is really powerful because we don't have to regenerate this CSP for every response load. 96 00:08:09,040 --> 00:08:15,980 The hash is fixed, presumably because on every response, your script is mostly the same. 97 00:08:15,980 --> 00:08:25,340 And this is really powerful when you don't have control over that back-end, so you can put in the logic to do this nonce generation. 98 00:08:25,560 --> 00:08:41,360 And this is also super useful for the SBA, single-page applications, because when you are doing the final bundling process for your final HTML, you know what script has are going to be there in your SBA bundle, and use that to generate your hash, and there you go, 99 00:08:41,480 --> 00:08:49,300 a fixed CSP policy that offers this protection that you can even drop into a meta tag at the top of the HTML file. 100 00:08:49,300 --> 00:08:56,240 And in more detail, so what you have on the left is sort of like what your bundle might look like for a particular single-page application. 101 00:08:56,240 --> 00:09:00,700 You've got a couple scripts loading to actually get the user interaction going. 102 00:09:00,700 --> 00:09:10,740 And we would actually rewrite this in this case into a dynamic loader inside an inline script block, because that is one of the characteristics of a hash-based CSP for now. 103 00:09:10,740 --> 00:09:15,060 You need to know exactly what's in the script content in order to make the hash. 104 00:09:15,060 --> 00:09:27,780 So usually you do this by actually inlining the block, and if you have resources that would load over the network, then you turn it into JavaScript that would dynamically add it to the page. 105 00:09:27,780 --> 00:09:35,880 And once we have that, we also added some preload tags so that we actually get the parallelization going for fetching these resources. 106 00:09:35,880 --> 00:09:42,680 You can take the script block, create the hash, and stick it in as a meta tag that carries a CSP, and there you go. 107 00:09:42,680 --> 00:09:47,680 The HTML is self-contained and offers this protection with a CSP baked in. 108 00:09:51,680 --> 00:09:56,200 The next CSP-delivered mitigation that we want to talk about is trusted types. 109 00:09:56,200 --> 00:10:00,280 Specifically, trusted types is geared towards protecting DOM-based XSS. 110 00:10:00,300 --> 00:10:07,660 So in the example that we saw before, it's the one that says require trusted types for, and that's the directive that you need to send. 111 00:10:08,940 --> 00:10:13,080 So we want to point out that the attack surface is large here for DOM XSS. 112 00:10:13,080 --> 00:10:22,100 There's over 60 JavaScript APIs that can turn strings into code and lead to arbitrary code execution, and DOM XSS is usually very easy to introduce and hard to detect. 113 00:10:22,100 --> 00:10:30,200 Calls to these APIs could be going through multiple levels of indirections, it could be in a transitive dependency, or it could exist in libraries that we don't have control over. 114 00:10:30,200 --> 00:10:31,800 So how can we make this better? 115 00:10:32,260 --> 00:10:36,280 And we need a run-time mitigation for this, and this is where trusted types comes in. 116 00:10:36,280 --> 00:10:40,680 The main idea behind trusted types is to make security decisions explicit and auditable. 117 00:10:40,680 --> 00:10:52,520 To do this, trusted types will restrict the access to the dangerous DOM APIs we mentioned previously, and it will require typed objects instead of plain strings to be passed into the over 60 APIs. 118 00:10:52,580 --> 00:10:59,920 So in this case, instead of strings that represent script URLs, HTML, or scripts, will require typed objects such as trusted script URL. 119 00:10:59,920 --> 00:11:03,700 And we'll discuss how to generate these typed objects, but this is the main idea. 120 00:11:04,720 --> 00:11:07,040 This is what the header looks like, again. 121 00:11:07,100 --> 00:11:14,500 This tells the browser to reject string assignments to injection syncs, and effectively it provides a run-time type checking mechanism on top of JavaScript. 122 00:11:14,880 --> 00:11:25,100 If you remember the example from our DOM XSS slide before, we're using a plain string here with innerHTML, and if trusted types were enforced, we would throw an error that looks like this. 123 00:11:25,100 --> 00:11:29,180 So the browser will tell you you need a trusted HTML, and it won't use a string. 124 00:11:30,120 --> 00:11:39,600 We want to highlight that most security guarantees of trusted types come from a policy, and the policy is what I mentioned of how we could generate a trusted object. 125 00:11:39,720 --> 00:11:44,680 So you can think of it as a wrapper that takes in a string and returns a trusted type. 126 00:11:44,680 --> 00:11:56,200 And we apply this policy to strings before inserting them into the DOM sync, and the processing you do within the policy should make sure the string won't lead to any unintended code execution, therefore preventing DOM XSS. 127 00:11:56,380 --> 00:11:59,740 So in this example, we use a sanitizer from DOM Purify. 128 00:11:59,740 --> 00:12:06,800 We check for the presence of trusted types in the JavaScript namespace for browser compatibility, and then use the correct factory if it exists. 129 00:12:06,800 --> 00:12:21,840 But if you don't want to keep writing this verbose if block, because it is a bit clunky, DOM Purify also works with trusted types off the shelf, so it will do the policy creation and the browser compatibility checking under the hood for you if you pass in the right config for trusted types. 130 00:12:25,280 --> 00:12:26,020 Thanks, Jen. 131 00:12:26,020 --> 00:12:38,060 So now that we've talked about our security features that we believe are powerful against cross-site scripting today, we'll touch a little bit on how to use them in your application and offer a bit of the lessons that we've learned from securing our apps at scale at Google. 132 00:12:38,060 --> 00:12:45,040 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 the next section, but in written form. 133 00:12:45,040 --> 00:12:53,340 This approach is used widely in our team and our org, and this article goes into a little bit more detail than what we have time for in some of the ideas that we'll elaborate on next. 134 00:12:53,340 --> 00:13:02,780 It's on the Google Security Engineering blog at bughunters.google.com, along with other great content like this, and also similar to, I think, the theme of this village. 135 00:13:02,780 --> 00:13:04,480 So please check us out. 136 00:13:04,720 --> 00:13:06,280 So back to the main show. 137 00:13:06,280 --> 00:13:12,540 What are some of the tactics that we use to adopt these security features at scale on hundreds of different web apps? 138 00:13:12,540 --> 00:13:18,800 So some of the lessons that we've learned that we find most useful are, number one, use the frameworks that will help you in this journey. 139 00:13:18,900 --> 00:13:28,280 Number two, try to shift left to get developers an indication whether this feature is incompatible with code that they're writing as early as possible in the process. 140 00:13:28,280 --> 00:13:34,380 Number three, some tools that we've built and we also rely on throughout this process that we found useful. 141 00:13:34,380 --> 00:13:40,320 And number four, a quick note about third-party dependencies and how they might complicate your adoption process. 142 00:13:40,460 --> 00:13:49,160 So the first big idea is if you're starting a new code base from scratch, let's think about which frameworks we can use that will give us security superpowers. 143 00:13:49,160 --> 00:14:04,700 And the big idea behind that is that at our scale, at at-scale defense against cross-site scripting at Google, we rely on frameworks with, number one, context-aware templating, and number two, built-in compatibility with these security features that are secure by default. 144 00:14:04,860 --> 00:14:11,020 And as a quick aside, we haven't talked too much about context-aware templating right now, but we don't have too much time to get into that. 145 00:14:11,020 --> 00:14:20,320 But the gist of it is you want to have a templating system that does reasonable enough things to prevent a lot of server-side rendered cross-site scripting from happening. 146 00:14:20,320 --> 00:14:24,920 Catch us after the talk, and we are happy to chat about templating too, which is beyond the scope of this talk. 147 00:14:26,820 --> 00:14:33,100 So what we want to cover on this slide and for the rest of the talk is what we call the safe calling philosophy at Google. 148 00:14:33,100 --> 00:14:47,220 And this is the idea that we want to give tools to developers that take away a lot of the uncertainty from the developer on how to use and configure these security features correctly, because they are really easy to misconfigure in really subtle ways. 149 00:14:47,260 --> 00:14:58,240 And we want the security to not really get in the way of feature development and shipping great things to our users, so we want to abstract away some of these decisions in a clear and understandable manner. 150 00:14:58,240 --> 00:15:02,480 And the key to do this is through our frameworks and our APIs. 151 00:15:02,540 --> 00:15:14,460 And we'll say that this is possible at Google because you do have tight control over the internal frameworks that you use in-house, and also tight control over the guidance that we give to our developers on how to use these frameworks. 152 00:15:14,460 --> 00:15:21,540 But I imagine many of the web developers here aren't building internal web apps for Google, so how can you get some of these benefits? 153 00:15:21,780 --> 00:15:32,520 And thankfully, our, yeah, colleagues have worked hard to ensure compatibility with some of these security features and frameworks that are available outside of our internal ecosystem as well. 154 00:15:32,520 --> 00:15:44,080 For instance, some of the frameworks that are also available externally, like Angular and Lit, all the hurdling work that we do there translates to benefits for the ecosystem and for everyone in the world to use. 155 00:15:44,080 --> 00:15:59,740 But if you're also using frameworks that are not entirely within the Google ecosystem or very Google-inspired, we also have our colleagues at Meta who did a lot of work to make React compatible with CSV and Trusted Types, and some of the frameworks that are based on React, 156 00:15:59,740 --> 00:16:04,940 like Next.js, thanks to volunteers and other colleagues, have compatibility as well. 157 00:16:04,940 --> 00:16:09,420 Great, so on to the second idea, how to shift left and enforce early. 158 00:16:09,420 --> 00:16:25,440 And this is just the idea that you want to add these headers and protections as early as possible, maybe in your dev server, so that when things go wrong, your developers can see the error and act on it as soon as they've written the code, so that they can fix it while the context of what they're trying to do is fresh in their minds. 159 00:16:25,640 --> 00:16:33,700 And a quick, and more technically, a way to do this is, well, here in this example, we have a configuration for a Vite dev server. 160 00:16:33,700 --> 00:16:36,560 I hear that's what all the web developers are using nowadays. 161 00:16:36,560 --> 00:16:38,320 We are all on to Vite now. 162 00:16:38,840 --> 00:16:46,960 And here we see a Node.js express-style middleware inside this configuration for the dev server that just dumps in these headers. 163 00:16:48,220 --> 00:16:58,240 But if you don't have control over your dev server or your serving stack, as you mentioned before, meta tags at the top of an HTML file also can deliver these headers. 164 00:16:58,240 --> 00:17:13,880 And for the observant among you, you will see that here we have our hash-based CSP again, because if you are baking a CSP into a static HTML page, you really want it to be a hash-based CSP so that the nonce value isn't blown the first time you use it. 165 00:17:14,040 --> 00:17:22,420 And we saw an example of how to do the refactoring to make a hash-based CSP before, and it was a little cumbersome, so how can you do that more easily? 166 00:17:22,420 --> 00:17:30,860 And the answer is, we have an experimental tool available in GitHub and NPM that does a lot of this transformation for you. 167 00:17:30,860 --> 00:17:40,400 This is available as a Webpack plugin, but also as a utility library that takes in a string of the HTML and does a refactoring like this. 168 00:17:40,460 --> 00:17:49,300 I mean, I know there's a lot of code on the screen, but it just takes in a string and outputs a string and will shuffle around the notes, do the hashing, add the meta tags for you. 169 00:17:49,300 --> 00:18:00,240 And this is really powerful because this is a very framework-agnostic way that now has proven to have outlasted the popularity of Webpack plugins because they just keep changing the configurations. 170 00:18:00,240 --> 00:18:09,340 But this is really powerful because if we remember the example from before with the Vite middleware, it composes almost perfectly. 171 00:18:09,340 --> 00:18:12,420 This is just a copy-paste job of the last two slides. 172 00:18:12,700 --> 00:18:27,060 And I think one of the lessons we learned in building some of this tooling is if you keep it as agnostic as possible in terms of frameworks and just separate the logic from the framework, then you can just, yeah, snap the pieces together when a new framework comes along. 173 00:18:28,120 --> 00:18:30,340 So on to the next section. 174 00:18:31,560 --> 00:18:32,740 Thanks, Aaron. 175 00:18:32,740 --> 00:18:40,540 In addition to using the header to spot violations early, we really advocate for using some other tools to help you with adopting these defenses. 176 00:18:40,540 --> 00:18:49,080 We'll introduce a bunch of helpful tools, but they can be categorically be broken down into, first of all, tools for understanding features and violations. 177 00:18:49,100 --> 00:18:55,180 We mentioned that CSV is notoriously hard to configure and understand, and the CSV evaluator solves that problem. 178 00:18:55,180 --> 00:19:01,700 It's available as either a website or a Chrome extension, which will give you some high-level guidance on the configuration of your CSV. 179 00:19:01,700 --> 00:19:05,880 It can detect directives and then kind of explain them. 180 00:19:06,340 --> 00:19:09,780 We're also actively working on a tool called Trusted Types Helper. 181 00:19:09,780 --> 00:19:15,440 This isn't released yet, but it will be soon, for streamlining the Trusted Types adoption process. 182 00:19:15,440 --> 00:19:21,860 One of the most time-consuming and painful stages of Trusted Types enforcement is finding the source of violations and trying to fix them. 183 00:19:21,860 --> 00:19:28,100 So this Chrome extension will create a DevTools tab that helps you demystify Trusted Types violations and suggest some refactoring. 184 00:19:28,100 --> 00:19:29,320 So stay tuned. 185 00:19:29,920 --> 00:19:34,820 Another category of tools are those that help with refactoring using Static Analysis. 186 00:19:35,280 --> 00:19:47,000 We have a huge Static Analysis pipeline at Google, and we took the most effective checks that we run on our internal Static Analysis tooling and Linter and built it on top of ESLint, and that is Safety Web. 187 00:19:47,000 --> 00:19:51,660 This project is also in active development, but it is available on GitHub. 188 00:19:51,740 --> 00:20:00,720 As you can see in the example here, it will detect unsafe usages of risky APIs, and you can refactor these unsafe calls with another tool we provide called Safe Values. 189 00:20:00,720 --> 00:20:05,880 So Safe Values is a library designed to steer developers to make safer choices. 190 00:20:05,980 --> 00:20:14,800 It will prevent unsafe assignments using TypeScript type checking unless the value is trusted, either from a trusted source or by transformation that makes it trusted. 191 00:20:14,800 --> 00:20:17,980 For example, sanitizing an HTML makes it trusted. 192 00:20:19,000 --> 00:20:23,380 We mentioned we were going to add a quick note about third-party dependencies. 193 00:20:23,380 --> 00:20:29,560 This is the complicated part, and it's a big aspect of making your application compatible with these features. 194 00:20:29,820 --> 00:20:37,780 For both Trusted Types and CSP, all code running on your site needs to be free of violations of these policies, otherwise they will be blocked by the browser. 195 00:20:38,040 --> 00:20:50,580 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 in our code, but code that others have written and others control. 196 00:20:50,720 --> 00:21:00,380 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 could use some help as well. 197 00:21:00,380 --> 00:21:10,920 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 that you find along your journey of adopting these features. 198 00:21:12,900 --> 00:21:13,680 Thanks, Jen. 199 00:21:13,680 --> 00:21:24,440 So, I know we talked a lot about the mitigations and the tools that are used today to protect our apps, but let's talk a bit about where we want to go from here and the more secure world that we'd like to see in the future. 200 00:21:25,020 --> 00:21:32,820 And here are the key ideas we talked about today that form the basis of this protection, this pipeline of protection, if you will. 201 00:21:34,220 --> 00:21:40,840 So, the running theme is abstracting security decisions away from developers in a clear and secure by default way. 202 00:21:41,180 --> 00:21:52,660 When all of these elements work together, starting from the first stage when the 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 lifecycle. 203 00:21:52,780 --> 00:21:57,680 And this should make most cross-site scripting solvable, and we see this working at Google scale. 204 00:21:57,680 --> 00:22:13,020 On our most recent in-house frameworks that follow a lot of these guidelines from these pillars, we see so few cross-site scripting, and none of them are trivial attack chains, and all of them really have some weird logic bug or some legacy system involved. 205 00:22:13,020 --> 00:22:19,140 So, we are seeing the effects of this working at scale across billions of users and hundreds of different web apps. 206 00:22:19,140 --> 00:22:20,520 But how can we make this safer? 207 00:22:20,520 --> 00:22:21,480 Where do we go from here? 208 00:22:21,480 --> 00:22:23,340 What's the next logical step? 209 00:22:23,340 --> 00:22:34,140 And we believe that, remember how we talked about trusted types, and it blocks a lot of these inherently unsafe DOM APIs in the web platform, or at least makes it harder to use? 210 00:22:34,140 --> 00:22:47,440 What if we take that to the conclusion of the idea and actually like ban all of those usages at runtime of these legacy DOM APIs that are a little bit inherently unsafe as they've been designed? 211 00:22:47,440 --> 00:22:50,580 Can we build apps where we don't use any of those APIs? 212 00:22:51,060 --> 00:22:53,680 And that's our future vision of where we go from here. 213 00:22:53,680 --> 00:23:15,760 If we have new platform-level APIs for operations that we currently use DOM APIs for, such as maybe a browser-included sanitizer implementation for HTML, maybe a templating solution, then we've really come full circle and have our runtime enforcements influence a new suite of secure-by-default web platform APIs to bring decisions that nudge developers towards safer choices, 214 00:23:15,760 --> 00:23:27,960 maybe at the framework level, from the very beginning when the first line of code is written in a new code base all the way to the moment when it is executed on the client's browser. 215 00:23:28,520 --> 00:23:39,020 And this is the future we hope to get to, one where we can safely lock down all the accesses to many DOM APIs along with a new suite of platform APIs to replace those operations in a safe-by-default manner. 216 00:23:39,020 --> 00:23:49,140 And we call this approach, we've nicknamed it Perfect Types, it is the logical evolution of Trusted Types, and we see this as the next evolution of Trusted Types and a post-cross-site scripting world. 217 00:23:49,140 --> 00:23:58,660 This combined with the strict CSP configurations we talked about and our framework-based approaches, secure-by-design, safe-by-design, should guide us to a new post-cross-site scripting world. 218 00:23:58,660 --> 00:24:12,120 And taking a step back for a second, for an even bigger picture, and as a final plug, this safe coding philosophy and safe-by-design, trying to steer developers in the right direction is something that extends beyond just JavaScript, cross-site scripting, 219 00:24:12,120 --> 00:24:16,060 and is a core priority for all Google-scale security efforts. 220 00:24:16,060 --> 00:24:28,980 You can read more about our organization's work at these links, and Google is a signer of CISA's secure-by-design pledge along with other industry and government leaders in the space, and we've committed to sharing our knowledge on how to build a safer future together. 221 00:24:29,820 --> 00:24:34,260 All right, well, that is the end of our talk, so thank you everyone for listening. 222 00:24:34,260 --> 00:24:37,380 Hopefully this was a good guide on how to think about solving XSS. 223 00:24:37,380 --> 00:24:38,160 I'll leave you here.