WEBVTT

00:08.550 --> 00:10.250
Hi everyone, welcome to our talk.

00:10.250 --> 00:14.650
Today we'll be talking about securing front-ends at scale and how we imagine a post-XSS world.

00:14.650 --> 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.

00:25.210 --> 00:28.110
Before we dive into it, we'll do some introductions.

00:28.110 --> 00:29.290
Hi, I'm Jen.

00:29.710 --> 00:32.650
I've been a software engineer at Google for over three years now.

00:32.650 --> 00:40.410
I work on a team that mainly focuses on deploying web security mitigations across all of Google's web products.

00:40.410 --> 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.

00:50.750 --> 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.

00:57.990 --> 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.

01:08.670 --> 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.

01:24.170 --> 01:25.110
Cool.

01:25.110 --> 01:28.170
Now we'll get into our agenda for the day.

01:28.650 --> 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.

01:48.950 --> 01:50.330
So let's get into it.

01:50.330 --> 01:52.430
What is cross-site scripting?

01:52.490 --> 01:56.690
We've said that XSS is common, but we'd like to show you some data to back this up.

01:57.090 --> 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.

02:06.970 --> 02:11.250
As you can see, over 50% of the issues were web issues.

02:11.250 --> 02:11.870
This makes sense.

02:11.870 --> 02:13.270
Google is a web company.

02:13.330 --> 02:17.410
But out of those 50%, 35% are XSS.

02:17.410 --> 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.

02:24.550 --> 02:27.370
So let's talk about what XSS really is.

02:27.370 --> 02:33.430
The root cause is that user input gets mixed up with code and gets interpreted as code.

02:33.490 --> 02:40.450
Because HTML is dynamic and mixes static data with logic that should execute, as you see here, is very prevalent.

02:40.570 --> 02:44.330
And this leads to malicious scripts getting injected into a trusted site.

02:44.330 --> 02:49.390
In this example, there's a description that's supposed to be dynamic.

02:51.430 --> 02:55.750
But if this is user controlled, we can inject the following script and get it to execute.

02:55.750 --> 02:58.230
Then we have code execution on the website.

02:59.090 --> 03:00.990
And what does an XSS let you do?

03:00.990 --> 03:05.490
An XSS, when exploited, can let the attacker take control of the account of a logged in user.

03:05.490 --> 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.

03:10.730 --> 03:13.730
And that's why we care a lot about mitigating.

03:14.450 --> 03:20.310
So we also call this the client-side version of a remote code execution, as they share a similar concept.

03:20.310 --> 03:22.670
And here's another format you might be used to seeing.

03:22.670 --> 03:28.690
XSS, we usually pop an alert with a document domain as a proof of concept when we find an XSS vector.

03:30.290 --> 03:36.730
So here's a quick example of a client-side variant of XSS, which is called DOM XSS.

03:36.730 --> 03:42.490
The root cause of this is that JavaScript APIs, specifically DOM APIs, are not secure by default.

03:42.490 --> 03:48.510
They can easily turn strings into code, like innerHTML is an example of this, or script.innerText.

03:48.510 --> 03:52.530
So here's a very simple proof of concept example of how this might happen.

03:52.530 --> 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.

04:00.010 --> 04:04.890
We'll see the onError alert statement execute if we use the payload that you see here.

04:04.890 --> 04:06.990
But no one codes like this anymore, right?

04:06.990 --> 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.

04:12.590 --> 04:14.490
Except not!

04:14.490 --> 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.

04:31.270 --> 04:33.130
And here's the core concept.

04:33.130 --> 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.

04:41.690 --> 04:43.670
And these issues are really easy to introduce.

04:43.670 --> 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.

04:50.690 --> 04:54.090
So do we stand a chance against this class of problems?

04:54.470 --> 04:55.990
And we think we do.

04:56.130 --> 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.

05:04.050 --> 05:09.990
And CSP is famous for having a lot of directives, and a lot, a lot of directives.

05:09.990 --> 05:14.650
It can really turn off any sort of resource loading that happens in the browser.

05:14.650 --> 05:15.910
So how do we use it?

05:15.910 --> 05:21.890
How do we know that it's delivering the protections and it's not providing a workaround for our attackers?

05:22.290 --> 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.

05:40.590 --> 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.

05:51.710 --> 05:57.910
So let's open up Chrome DevTools in the network tab and see what headers we are sending.

05:57.910 --> 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.

06:05.110 --> 06:10.950
And we see that there are multiple content security policy headers here.

06:11.110 --> 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.

06:20.290 --> 06:26.170
And we really have a lot of different configurations that protect against different potential threats.

06:26.170 --> 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.

06:34.170 --> 06:40.550
And so we'll look at these two in particular, which are sort of used for cross-site scripting defense.

06:40.710 --> 06:46.110
And we'll focus on these ones, nonce-only CSP and trusted types.

06:46.110 --> 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.

06:57.390 --> 06:58.070
Cool.

06:58.070 --> 07:01.170
And we'll start with the nonce-only CSP here.

07:01.590 --> 07:05.730
And the example that we saw before, it's kind of pretty self-evident.

07:05.730 --> 07:09.490
It's the one that has the nonce directive, just like you can see here.

07:09.970 --> 07:14.350
And more specifically, a nonce-only policy takes a form that looks like this.

07:14.450 --> 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.

07:23.910 --> 07:26.110
In this case, any script with a nonce.

07:26.110 --> 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.

07:37.490 --> 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.

07:46.850 --> 07:50.550
Another CSP directive that we want to point out here is strict-dynamic.

07:50.550 --> 07:53.950
This directive enables transitive trust for scripts.

07:54.230 --> 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.

07:59.630 --> 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.

08:05.670 --> 08:07.970
If they do, it's not allowed to run on the page.

08:08.210 --> 08:14.890
Although this slightly relaxes the policy, in our experience, it's also made adoptions a lot easier for complex web apps.

08:14.890 --> 08:21.890
You can have one loader script that loads all the necessary scripts, and deploying content security policy becomes a lot easier.

08:23.690 --> 08:24.390
Great.

08:24.390 --> 08:24.950
Thanks, Jen.

08:24.950 --> 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.

08:35.650 --> 08:38.510
But what if we don't have control over the backend?

08:38.510 --> 08:42.990
Then we can use a relative of the nonce-only policy, the hash-based CSP.

08:44.410 --> 08:46.850
And a hash-based CSP looks like this.

08:46.850 --> 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.

08:55.270 --> 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.

09:13.590 --> 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.

09:22.370 --> 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.

09:31.630 --> 09:35.510
So following this suggestion, we have this potential transformation of a SPA.

09:35.510 --> 09:43.610
On the left, we have maybe an index.html of an app that will bootstrap some SPA, a single-page application.

09:43.610 --> 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.

09:53.190 --> 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.

09:58.390 --> 10:02.770
The HTML itself contains a CSP that we want to ship.

10:02.770 --> 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.

10:10.930 --> 10:16.790
And we'll talk a bit more in the next several slides about some of the tooling that can automate this.

10:18.780 --> 10:19.460
Cool.

10:19.460 --> 10:23.340
Now, on to the next flavor of CSP, we have trusted types.

10:23.340 --> 10:29.900
This is, again, another CSP-delivered mitigation that we think is really powerful, specifically against DOM-based XSS.

10:29.900 --> 10:35.260
The example we saw before, it's this one with the require-trusted-types-for directive.

10:35.720 --> 10:40.120
And we want to point out that the attack surface is very large here for DOM XSS.

10:40.120 --> 10:45.000
I mentioned that JavaScript APIs, specifically DOM APIs, are insecure by default.

10:45.000 --> 10:50.040
And there's over 60 of them that can take strings and turn them into code execution.

10:50.180 --> 10:55.640
DOM XSS is usually very, very easy to introduce and hard to detect, as Aaron alluded to before.

10:55.640 --> 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.

11:02.120 --> 11:04.500
So we were thinking, how can we make it better?

11:04.500 --> 11:06.560
And this is where trusted types comes in.

11:06.560 --> 11:12.640
We need a runtime mitigation to provide some sort of type checking on top of JavaScript.

11:12.640 --> 11:14.720
And this is exactly what trusted types does.

11:14.720 --> 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.

11:25.520 --> 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.

11:35.560 --> 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.

11:47.300 --> 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.

11:57.580 --> 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.

12:04.660 --> 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.

12:13.120 --> 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.

12:19.280 --> 12:23.460
As you can see here, we're using a plain string and assigning it to inner HTML.

12:23.620 --> 12:27.720
And if trusted types are enforced, the browser will throw an error that looks like this.

12:27.720 --> 12:32.280
And it tells us that we need a trusted HTML object instead of the string that we're trying to use.

12:33.160 --> 12:34.860
And here we are.

12:34.940 --> 12:38.400
This is what a trusted types policy looks like.

12:38.740 --> 12:43.440
This is what I mentioned previously about how we can generate these trusted objects.

12:43.440 --> 12:48.140
We want to highlight that most of the security guarantees of trusted types come from a policy.

12:48.140 --> 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.

12:58.180 --> 13:02.100
We apply this policy to strings before inserting them into the DOM.

13:02.120 --> 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.

13:07.860 --> 13:10.180
And that's how we can prevent DOM XSS.

13:10.180 --> 13:14.160
In this example, we're specifically concerned about HTML.

13:14.520 --> 13:17.720
So we use a sanitizer from DOM Purify.

13:17.720 --> 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.

13:27.340 --> 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.

13:36.060 --> 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.

13:42.340 --> 13:43.360
So it's quite handy.

13:45.960 --> 13:46.560
Great.

13:46.560 --> 13:47.100
Thanks, Jen.

13:47.100 --> 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.

14:00.400 --> 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.

14:07.940 --> 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.

14:17.060 --> 14:18.400
So please check us out.

14:18.400 --> 14:25.000
It's on the Google Security Engineering blog at bughunters.google.com, and along with some other great content.

14:25.040 --> 14:26.960
So yeah, we hope to see you there.

14:27.640 --> 14:31.880
So a quick overview of what we are going to talk about in this section.

14:32.020 --> 14:35.760
Number one, if you use the right frameworks, it'll give you superpowers.

14:35.760 --> 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.

14:45.540 --> 14:52.980
Number three, some tools that we found helpful in this process of looking for possible incompatibilities with these features.

14:52.980 --> 14:57.320
And number four, a quick note about third-party dependencies.

14:58.200 --> 15:02.320
So onto our first big idea, frameworks that give you superpowers.

15:03.060 --> 15:08.400
So the idea here is the basis of our at-scale defense against cross-site scripting at Google.

15:08.660 --> 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.

15:30.140 --> 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,

15:44.620 --> 15:48.920
and really they can focus on shipping the features to the users.

15:48.920 --> 15:52.640
And we really don't want the security to get in the way of development, right?

15:52.640 --> 15:57.480
Because that is how you get developers to turn against security.

15:57.480 --> 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.

16:09.160 --> 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.

16:20.600 --> 16:24.100
But what if you aren't building web apps inside of the Google ecosystem?

16:24.100 --> 16:26.060
How can we get some of these benefits?

16:26.480 --> 16:34.480
And thankfully, our colleagues have worked hard to ensure compatibility with these powerful security features and some other frameworks as well.

16:34.480 --> 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.

16:45.620 --> 16:48.980
But our contributions aren't only to Google-sponsored frameworks.

16:48.980 --> 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.

17:03.140 --> 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.

17:13.140 --> 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.

17:24.040 --> 17:29.320
So if you have control of their backend server infrastructure, we can just set our headers there, right?

17:29.320 --> 17:35.380
And for instance, we hear that the web bundler and dev server of choice now is Vite.

17:35.380 --> 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.

17:45.040 --> 17:52.160
So you can set these headers and have it enforce the content security policies.

17:52.360 --> 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.

18:04.760 --> 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.

18:20.560 --> 18:26.120
And this HTML snippet will stay with the rest of your HTML-generated bundles.

18:26.120 --> 18:28.640
So yeah, it really can't become unglued.

18:28.640 --> 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.

18:34.940 --> 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.

18:44.240 --> 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.

18:51.140 --> 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.

19:05.540 --> 19:08.220
So is there a way to do this a bit more quickly?

19:08.300 --> 19:13.740
And thankfully, we have a package that will do a lot of this for you available on GitHub and NPM.

19:14.920 --> 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.

19:34.760 --> 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.

19:51.060 --> 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.

19:59.700 --> 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.

20:09.680 --> 20:10.360
Cool.

20:10.360 --> 20:11.160
Thanks, Erin.

20:11.320 --> 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.

20:18.920 --> 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.

20:28.140 --> 20:31.580
We mentioned that CSP is notoriously hard to configure and understand.

20:31.580 --> 20:34.680
They have so many directives that could be combined in various different ways.

20:34.680 --> 20:36.920
And the CSP evaluator solves that problem.

20:36.920 --> 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.

20:49.320 --> 20:54.920
We're also actively working on a tool called the Trusted Types Helper for streamlining the Trusted Types adoption process.

20:54.920 --> 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.

21:02.200 --> 21:07.940
This Chrome extension will create a DevTools tab that helps you demystify Trusted Types violations and suggest refactorings.

21:07.940 --> 21:10.080
Stay tuned for this release.

21:10.360 --> 21:17.020
Another category of tools that we advocate for are those that help with refactoring using Static Analysis.

21:17.560 --> 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.

21:30.760 --> 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.

21:38.440 --> 21:42.880
This is also under active development, but it is available on GitHub.

21:43.220 --> 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.

21:54.120 --> 21:57.920
This is a library designed to steer developers to make safer choices.

21:57.920 --> 22:04.320
Aaron alluded to this principle we have, which is secure by design, and this embodies all of those principles.

22:04.320 --> 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.

22:14.240 --> 22:20.960
It really tries to make doing the right thing really easy and doing the insecure thing really, really hard for developers.

22:21.940 --> 22:27.980
Another big aspect that we want to make a warning about is third-party dependencies.

22:27.980 --> 22:33.840
This is a big aspect of making your application compatible with the features we described before.

22:35.120 --> 22:38.880
So third-party dependencies, quite honestly, is hard.

22:38.880 --> 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.

22:44.400 --> 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.

22:52.000 --> 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,

23:06.380 --> 23:07.980
which is multiple levels deep.

23:08.000 --> 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.

23:18.640 --> 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.

23:27.800 --> 23:29.020
We would really appreciate it.

23:30.260 --> 23:31.620
All right, thanks, Jen.

23:31.620 --> 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.

23:43.000 --> 23:48.660
So to summarize, here are the pillars that we touched on to move towards a post-cross-site scripting world.

23:48.660 --> 23:55.800
The running theme is abstracting security decisions away from the developer in a clear and secure by default way.

23:56.740 --> 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.

24:10.200 --> 24:13.360
And this should make cross-site scripting mostly solvable.

24:13.360 --> 24:18.640
And we see this working at Google at scale on our most recent in-house frameworks.

24:18.700 --> 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.

24:28.800 --> 24:31.320
So where can we go from here?

24:31.980 --> 24:35.660
So we saw that trusted types is a complex mechanism to adopt.

24:35.660 --> 24:40.900
We can restrict the usages of dangerous DOM APIs, but we haven't gotten rid of them completely.

24:40.900 --> 24:45.780
We still need to create policies to maybe allow list some limited usages of them.

24:45.780 --> 24:49.680
We need to refactor away other code patterns that still use them.

24:49.680 --> 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?

25:02.900 --> 25:05.800
And that's a future vision of where we want to go from here.

25:05.800 --> 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,

25:24.120 --> 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.

25:34.800 --> 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.

25:51.260 --> 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.

25:58.520 --> 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.

26:14.440 --> 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.

26:27.420 --> 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.

26:37.020 --> 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.

26:54.160 --> 26:56.720
Cool, and that is sort of the end of our talk.

26:56.720 --> 26:58.660
We want to thank you all for listening.

26:58.660 --> 27:03.200
Hopefully this was a good guide on how to think about solving XSS and how to do it at scale.

27:03.280 --> 27:07.620
Feel free to reach out to us with any questions related to our tools or some of these mitigations.

27:07.700 --> 27:10.300
We'll be happy to have a conversation.

27:10.760 --> 27:16.060
And I want to add a last plug to please help us fix the open source ecosystem.

27:16.060 --> 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.

27:24.060 --> 27:24.560
Thanks!

