WEBVTT

00:08.120 --> 00:14.260
We are going to talk about front-end security with some title.

00:14.320 --> 00:20.240
Securing the front lines, protecting front-end applications from overlooked vulnerabilities.

00:21.920 --> 00:25.200
First of all, a little bit about us.

00:25.200 --> 00:31.440
We are a member of Theory, a cyber-secret startup, and the winner of the last DEF CON CTF.

00:31.720 --> 00:38.880
Currently, as far as I know, our team is as good as it was the previous year.

00:38.900 --> 00:42.840
I'm Dohyun, who used to be a hacker and CTF player.

00:44.400 --> 00:53.380
And I started hacking since 10 years ago, and I'm also working as a first-tier web programmer and product manager at Theory.

00:53.660 --> 00:55.840
Here is Woowon.

01:02.220 --> 01:06.640
He's Woowon, who is a bug hunter and also a CTF player.

01:06.640 --> 01:16.240
He is winner of the DEF CON CTF that opened last year, and also he is trying to be winner this year also.

01:16.240 --> 01:20.900
And he is also working with me at Theory as a cyber-security researcher.

01:23.460 --> 01:27.500
There are some risks that you will take away from this talk.

01:27.500 --> 01:32.040
First, we will share vulnerabilities we have found in the real world.

01:32.040 --> 01:36.500
And bugs we found were pretty critical and variable.

01:36.660 --> 01:45.640
But we are here for sharing, and so it might be helpful for hunting and working related to security.

01:45.760 --> 01:51.780
And second, we are going to talk about some common mistakes in front-end work and cause of them.

01:51.960 --> 01:57.340
And finally, we will propose a solution to ensure your front-end is secure.

01:59.720 --> 02:08.120
There are so many important problems on cyber-security, and you are all here because you are interested in this topic.

02:08.120 --> 02:14.060
And then, why we choose and focus on the web front-end security?

02:17.210 --> 02:18.850
The answer is so simple.

02:18.850 --> 02:23.370
Just we found a lot of vulnerabilities in the wild.

02:23.510 --> 02:26.730
We are going to dig deeper into this cause.

02:26.730 --> 02:34.190
Okay, then, let's talk about why we choose and focus on the web front-end security.

02:34.570 --> 02:41.030
So, instead of thinking about reading a textbook and thinking just getting a time machine, then it will be more fun.

02:41.030 --> 02:44.350
And we will take a look about the history of web programming.

02:45.470 --> 02:50.090
So, nowadays, front-end application is already complicated.

02:50.150 --> 02:54.050
And it is the center, there are single-page applications.

02:54.050 --> 03:01.690
With the mobile and smartphone, there are almost clients were just a web browser.

03:01.690 --> 03:06.350
So, it's enough that represent data from web service directly.

03:06.350 --> 03:14.170
Since the emergence of iOS and Android, back-end and client implementation had to be further separation.

03:16.110 --> 03:17.230
Yeah, like that.

03:17.230 --> 03:26.030
As you can see this code, we simply made a database connection, made a query and returned the result rendered by the server.

03:26.350 --> 03:29.970
Fetching the data and rendering it directly.

03:30.330 --> 03:34.110
Just it's got a lot of vulnerabilities, just it looks like.

03:34.110 --> 03:41.010
In the time, in times like this, the importance of the front-end was not emphasized.

03:42.790 --> 03:47.130
But now it's on the era of single-page application.

03:47.230 --> 03:54.770
A single-page application dynamically updates the content on the client page without requiring a full-page reload.

03:54.770 --> 03:59.950
And offering a smoother user experience similar to native applications.

04:00.810 --> 04:08.010
Even if you haven't heard about single-page application, you have probably heard of Vue and React.

04:08.310 --> 04:14.610
And after emerging that, productivity of front-end application was really increased.

04:15.530 --> 04:22.890
As productivity increased, the overall user experience of front-end has improved.

04:22.890 --> 04:29.110
And finally, front-end experience affects business results directly.

04:29.430 --> 04:47.630
There are so many metrics that explain our correlation of user experience and business, but we are tech guy, so leaving aside the boring business tactics or metrics, let's look at it from perspective for improving browser performance.

04:49.930 --> 05:00.770
The web browser has been upgraded more properly and not only functionally, but also performance-wise over a decade.

05:02.470 --> 05:13.510
So far, coming back to the origin point, the biggest reason we focus on front-end security because everyone is focused on back-end security.

05:13.730 --> 05:17.030
Meanwhile, front-end can be an attack surface.

05:17.030 --> 05:19.770
There are two reasons.

05:19.770 --> 05:28.230
First one is front-end has more impact on business directly and require a lot more logic and responsibilities.

05:29.010 --> 05:40.470
And so, remember, with great power comes great responsibility, so the importance of front-end security are more increased.

05:41.990 --> 05:48.050
From now on, we are going to talk about the real-world case that we have found.

05:49.450 --> 05:55.330
Now, starting from classic, the XSS, the cross-site script.

05:55.370 --> 06:09.610
To be honest, it gets harder in the modern web stack because mitigation in framework or library is getting stronger, and it's harder for developers to make mistakes.

06:10.130 --> 06:26.910
We found to use the function that look dangerous by name, like dangerously set innerHTML or prefix of unsafe, but now the safe one is the default way.

06:27.130 --> 06:30.870
And view.js case, there are vHTML.

06:30.870 --> 06:37.090
This can be vulnerable, but this seems less risky, but they are still risky.

06:37.210 --> 06:48.410
That's the reason why we need content-secret policy as talked before the presentation, and we will mention it again in the rest of our presentation.

06:50.650 --> 06:52.990
Next, expose the secret.

06:53.110 --> 06:57.310
This is one of the simplest and most impactful vulnerabilities.

06:57.750 --> 07:05.010
Even if we don't look for zero-day vulnerabilities in complex code, but we can exploit them.

07:06.150 --> 07:11.910
There are cases where secret information such as API key and password are hard-coded.

07:11.910 --> 07:13.250
Yeah , just like that.

07:13.250 --> 07:25.610
There are some example secret value from using the authorization, and sometimes they are just hard-coded in the production, and we can discover it.

07:27.970 --> 07:34.150
And so, you are not reasoning that you didn't hard-code it.

07:34.150 --> 07:39.730
That means not only hard-coded, but also environment variable can be exposed.

07:39.730 --> 07:40.910
Yeah, just like that.

07:40.910 --> 07:52.950
There are sample code to send a message to Slack, and even if write this way, it can be still exposed via Node EMV.

07:55.030 --> 08:01.970
So, we see a lot of vulnerabilities, especially on the big back office.

08:02.870 --> 08:11.090
We can find some case like this from the back office of the web system.

08:11.090 --> 08:13.250
How did we find this?

08:15.830 --> 08:22.370
We mainly obtained a lot of information that should be kept secret from the manifest.

08:22.890 --> 08:31.010
As you see, the build-manifest.js includes a lot of information of the web application.

08:31.010 --> 08:42.230
And it includes all URLs for application like error or about admin and some develop or staging page.

08:42.450 --> 08:53.110
As you see, there are a lot of interesting things like the back office system that only developers and administrators can access.

08:53.990 --> 08:58.390
A lot of information is more informative than you might think.

08:59.290 --> 09:04.670
Then, why is the routing information in manifest?

09:04.670 --> 09:06.410
So, why they are here?

09:06.410 --> 09:11.610
Because they are single-page application, and it's built by Next.js.

09:12.010 --> 09:17.110
In production mode, Next.js pre-renders pages that can be routed.

09:17.110 --> 09:23.730
It's for effective client-side navigation and page reloading.

09:23.730 --> 09:32.330
If you are wondering the reason and how to work with it, you can take a look at build-manifest-plugin.js from Next.js.

09:32.330 --> 09:37.590
That file contains the implementation of those kind of process.

09:40.330 --> 09:45.050
So, now we have determined which URL should be attacked.

09:45.050 --> 09:49.940
The next step is to analyze the code and to find the vulnerabilities.

09:49.940 --> 09:54.080
Yeah, there are source map.

09:54.080 --> 10:04.580
We love to use source map to find our analysis vulnerabilities, and in general, the modern web stack optimize and minimize code like this.

10:04.580 --> 10:11.700
This is the sample code of front-end application and how to minimize and optimize it.

10:15.010 --> 10:25.590
So, once you can read the source code in the admin page, you can bypass the admin check and logic that is only implementation on the client.

10:26.330 --> 10:37.250
This is the sample React code that some front-end application, and they checked the admin stage, and if not admin, then just redirect some other way.

10:37.250 --> 10:50.730
But if we can read the front-end code, then we can access and we can find what kind of process or what kind of API code in the real application.

10:51.750 --> 11:02.450
You can then call the back-office API and to refund the payment or creating a deleted user and viewing some user information.

11:02.450 --> 11:04.410
This is very sensitive.

11:04.710 --> 11:10.400
And not only that, it can be another attack surface.

11:10.400 --> 11:25.420
That means, as you know, code of back-end application is not open, but if you can and find those API list, then you can also try to exploit them, the API of back-end application.

11:25.420 --> 11:30.660
It is a kind of the door to start exploit the whole application.

11:33.240 --> 11:39.240
However, this makes it difficult for developers to debug.

11:39.240 --> 11:42.520
Even this very simple code is hard to debug.

11:42.520 --> 11:45.880
You don't know exactly where it's happening.

11:45.880 --> 11:49.540
But if developers are annoying, hackers are annoying too.

11:50.900 --> 11:56.960
Annotation in open source map can tell a lot to us.

11:56.960 --> 12:10.580
In some cases, we have recognized account IDs and password information, and where security patches are already authored and are planned like this.

12:10.580 --> 12:20.720
There are some example of account information in the notation, and there are some security patch or plan about the security patch.

12:20.720 --> 12:29.820
And sometimes they provide some hosts of web application to be an attack surface.

12:32.200 --> 12:37.060
And there is an interesting case that I'd like to share with you.

12:37.060 --> 12:47.060
Rails webpacker library had a source map enabled as default, and the pre-request came out saying it should be disabled.

12:47.160 --> 12:59.340
But DHH, the founder of Rails, says he learned a lot of CSS and JS from the view source feature, so he wants to cap this feature.

13:00.420 --> 13:03.600
As far as I know, it is not applied.

13:04.160 --> 13:12.220
So still enable the source map configuration in webpacker in Rails, the Ruby on Rails.

13:12.880 --> 13:17.200
This is proof the source maps are that useful.

13:18.060 --> 13:20.860
Then, what should we do?

13:20.860 --> 13:26.360
Let me suggest a best practice for it.

13:27.500 --> 13:32.200
Most important thing is do not upload the source map in production.

13:32.420 --> 13:35.980
This can be done with just one line like those.

13:35.980 --> 13:40.100
module.export and devtools just as first.

13:40.380 --> 13:46.660
This can only upload the source map where authentication is required.

13:46.660 --> 14:00.500
That means there are some service to upload the source map and track the error, and this can be only accessed by some authenticated users.

14:01.520 --> 14:12.960
Or use a tool to map error log with original source code, and ideally make your code robust, then you don't mind it being exposed.

14:12.960 --> 14:18.420
And the last case is content integrity.

14:18.580 --> 14:29.080
Now, with the growth of Web3, the blockchain, and the influx of large assets, there have been many attacks targeting users' assets.

14:29.280 --> 14:40.310
Network attacks such as BGP hijacking or attacks that take over a third-party application and tamper with front-end content have been asserted.

14:40.310 --> 14:45.270
Even if the service is not directly attacked, damage will assert.

14:45.570 --> 14:50.370
But in these days, the user also can be targeted.

14:51.310 --> 15:01.970
This is an example of phishing to get some private key, but no application received a private key in the first place.

15:02.010 --> 15:13.290
And this attack inserted malicious code into front-end content to perform malicious behavior such as stealing user info data or leaking the information.

15:14.990 --> 15:21.350
In other words, the contents are inserted from attacks domains and used for attacks.

15:22.730 --> 15:27.370
Here is an example of the following SRI.

15:27.510 --> 15:35.030
When the SRI is applied, external content is validated and not loaded if the content has been malformed with.

15:35.030 --> 15:40.430
This can be helped detect and block malformed external content.

15:41.410 --> 15:46.290
And second one is for contents integrity, is the CSP.

15:46.310 --> 15:53.390
And let's assume that we allow things to second data to example.com like this.

15:53.390 --> 16:00.490
If someone hacked the website and tried to send other domain, that will be blocked.

16:00.490 --> 16:08.150
This means checking or preventing integrity when malicious content is requested or loaded.

16:08.150 --> 16:13.750
One or more steps are required for hackers to succeed in an attack.

16:13.750 --> 16:19.510
In conclusion, CSP and SRIs validate the resource used in webpage.

16:19.650 --> 16:25.660
This increase the number of steps an attacker need to succeed, making attack more difficult.

16:28.720 --> 16:36.320
CSP and SRI are great feature, but there are reasons why they are challenging to implementation.

16:36.400 --> 16:41.440
First thing is hard to keep track of all resources.

16:41.440 --> 16:48.700
Second one is it can be cause usability issue when applying some new CSP rules.

16:50.420 --> 16:57.240
So we are looking on solving both of these problems.

16:57.240 --> 17:05.900
A simple idea is to track and verify all requests, apply a new CSP to the browser, and simulate the page.

17:06.600 --> 17:11.460
So we have prepared the demo video for you.

17:11.460 --> 17:23.860
And that visualizing resource graph view and result of scanning secrets to set up CSP well and find the attack vector better.

17:24.000 --> 17:34.940
And this right bottom one is the guide who developed by our demo and our team software engineer.

17:34.940 --> 17:37.060
So let's watch together.

17:48.180 --> 17:52.240
Alright, I want to showcase this tool that we wrote for the presentation.

17:52.240 --> 17:58.740
It's called Asynt Frontend Scanner, and it can extract valuable insights about your frontend application.

17:59.020 --> 18:04.480
To get started, just type in the location of your app, in this case, Siri.io.

18:07.250 --> 18:12.230
It might take up to 2 minutes to finish the scan, so please be patient.

18:12.690 --> 18:15.490
It's not actually 2 minutes, so don't worry about it.

18:23.260 --> 18:26.680
Alright, let's start with the Resource Insights tab.

18:26.680 --> 18:33.100
In this tab, you can see the summary and the details about the resources that were loaded by the browser during the page load.

18:33.560 --> 18:39.220
On the left pane of this tab, you can see a list of all the resources loaded by the page.

18:42.740 --> 18:47.440
You can also group them by type, such as images, scripts, and so on.

18:47.440 --> 18:54.460
This can help you quickly identify any unusual or suspicious resources that might be loaded by the page.

18:55.760 --> 19:00.240
Moving on to the bottom half of the left pane, you can see the Domain Overview.

19:00.420 --> 19:04.280
This section shows a list of domains for each resource type.

19:04.620 --> 19:09.060
This can help you identify which third-party domain resources are being loaded.

19:09.060 --> 19:22.160
Furthermore, you can use this information to construct an initial version of your content security policy, which, as we said in the presentation, can help protect against cross-site scripting outtakes and other security vulnerabilities.

19:22.700 --> 19:29.780
Now, please be aware of the fact that this overview shows only resources that were loaded during the initial page load.

19:29.780 --> 19:36.920
This means that there might be resources which were not captured during the scan, even if those resources are recovered by your application.

19:36.920 --> 19:45.140
We recommend you use the Content Security Policy Report Only header first to find out if there are any resources not covered by your policy.

19:47.220 --> 19:52.920
Now, let's move on to the Resource Graph View, which is on the right pane of the Resource Insights tab.

19:52.920 --> 19:58.100
Here, you can see a visual representation of the resources that were loaded by the page.

19:59.060 --> 20:08.200
The leftmost resource is the one that was loaded first, and the arrow indicates a direct dependence between the resources.

20:09.120 --> 20:16.160
This graph can help you identify any dependencies between resources and find out why the specific resource was loaded.

20:17.800 --> 20:25.320
If you want to inspect a resource in more detail, you can click on it to reveal additional information about the request and response.

20:26.940 --> 20:33.740
It also focuses the resource on the graph view, letting you easily discover its dependencies and dependence.

20:34.100 --> 20:43.380
In the Details section, you can see additional details such as SRI hash, request headers, and response headers, and the initiator of the request.

20:43.780 --> 20:48.440
If the resource is loaded through a POST request, you can also see the POST data.

20:50.200 --> 20:57.700
Now, I want to share with you how the Resource Insights view can help the security team track down potential defacement attacks.

20:57.820 --> 21:05.060
The example I'm going to show you might look a bit contrived, but it's actually based on a real-world case that our team was involved in.

21:10.620 --> 21:14.660
This is a simple Next.js app hosting blog post.

21:14.660 --> 21:17.840
Let's analyze this application using our tool.

21:17.840 --> 21:19.780
That's a sample page.

21:20.780 --> 21:28.070
As you can see, this application is loading external resources from static.synth.io domain.

21:28.400 --> 21:33.240
This could be a potential attack vector if the site hosting the script gets compromised.

21:35.580 --> 21:43.080
Let's simulate a hypothetical supply chain attack by uploading a raw copy of the script to the static.synth.io site.

21:51.180 --> 21:54.320
Now, let's visit the site again to see what happened.

21:59.690 --> 22:03.950
You can see that the cover image for the hero post has been hijacked.

22:04.430 --> 22:08.810
We can use the Resource Insights to find out who loaded the rogue image.

22:08.910 --> 22:11.730
Firstly, let's analyze the application again.

22:24.420 --> 22:28.840
In the Images tab, we can go through the images loaded by the page.

22:35.620 --> 22:38.200
It looks like we have found a culprit.

22:38.520 --> 22:41.640
Now, let's find out who loaded this image.

22:45.320 --> 22:51.220
You can see that the analytic script we compromised indeed loaded the defacement image.

22:51.400 --> 22:58.300
To prevent this kind of attacks, make sure you have specified SRI hashes to the external scripts loaded.

22:58.500 --> 23:04.660
Also, establishing content security policies for your website makes these kind of attacks much harder to pull off.

23:06.960 --> 23:11.620
This demo page we just showed also contains publicly exposed secret information.

23:11.640 --> 23:17.500
However, manually finding these kind of secrets are time-consuming and labor-intensive.

23:17.540 --> 23:21.660
That's why we also created a secret scanner for front-end applications.

23:22.220 --> 23:27.980
However, it's important to note that secret scanners may have false positives and false negatives.

23:27.980 --> 23:37.580
Despite this, the secret scanner remains a valuable tool because secrets are often located together, making it easier to detect potential security risks efficiently.

23:41.020 --> 23:46.460
As you can see, the demo page contains quite a lot of high-severity credentials.

23:46.660 --> 23:51.440
However, the scripts containing these scripts were not directly loaded.

23:51.440 --> 23:59.260
One advantage of our secret scanner is that it can discover so-called hidden pages through enumerating build manifests of the front-end application.

24:00.940 --> 24:05.740
Here, you can see that this secret is discovered through build manifests.

24:05.740 --> 24:14.780
You might think this kind of vulnerability is rare, but there are surprising amount of production applications that are currently being served with secrets embedded in them.

24:16.640 --> 24:22.960
Front-end security lacks the attention it deserves, and easily exploitable vulnerabilities are often overlooked.

24:23.200 --> 24:33.700
It is hard for any security team to keep their front-end applications secure without a system that continuously monitors and ensures that there are no vulnerabilities or potential threats slipping through the cracks.

24:35.740 --> 24:38.280
That's all of our demo.

24:38.780 --> 24:41.720
Back to the presentation.

24:41.780 --> 24:50.640
As you see from the demo, it can assist in the creation of CSP or SRI rules.

24:50.640 --> 24:54.680
However, there are other things we need to think about.

24:54.680 --> 25:05.280
First, there are cases where the attack surface is exposed to internal or staging state domains other than the target domain within the CSP.

25:05.740 --> 25:18.960
Next, if you set up a repository link like the GitHub as a CSP rule that allows anyone to upload or enclose files, you can upload arbitrary files and use them in an attack.

25:20.040 --> 25:26.900
So far, we talked about those five topics and demos.

25:26.900 --> 25:37.130
For recap, everything exists for a reason, manifest or source map, like those things, and there are also shared responsibilities.

25:37.660 --> 25:45.880
A user needs to take care of their own security, and programmers need to take care of their own code or infrastructure.

25:46.300 --> 25:52.110
And finally, security engineers, like us, need to be prepared for all of the threats.

25:52.110 --> 26:01.190
That means no matter how good the security perks are, if the programmers aren't aware, the problem won't be solved.

26:01.190 --> 26:06.030
They have different concerns, so we need to maintain a healthy conflict.

26:06.130 --> 26:12.290
Similarly, programmers can only mitigate so much if a user lacks security awareness.

26:12.290 --> 26:22.050
No matter how robust the backend security is, it is worthless if keys and APIs are just exposed on the frontend and production.

26:22.110 --> 26:29.910
As you move to the endpoint, security becomes more of a management issue than a technical one.

26:29.950 --> 26:37.470
So, for example, writing or sharing passwords through plain text or notepad is one example of those.

26:38.510 --> 26:49.450
So, long story short, we just want to tell, check whether your sensitive data is publicly exposed, and everything is not text-surfaced.

26:49.450 --> 26:57.790
So, thank you for your attention, and if you want to try our demo, please fill out this form.

26:57.830 --> 27:15.250
Originally, we were going to open this up to the public, but as we tested, it's too powerful for that, so we are only going to open it up to people with a letter of guaranteed identities.

27:15.250 --> 27:21.850
The form is pretty simple, so please fill out this, and I will send the link of the demo.

27:24.190 --> 27:28.270
Thank you for your attention, and the presentation is at the end.

