1 00:00:08,120 --> 00:00:14,260 We are going to talk about front-end security with some title. 2 00:00:14,320 --> 00:00:20,240 Securing the front lines, protecting front-end applications from overlooked vulnerabilities. 3 00:00:21,920 --> 00:00:25,200 First of all, a little bit about us. 4 00:00:25,200 --> 00:00:31,440 We are a member of Theory, a cyber-secret startup, and the winner of the last DEF CON CTF. 5 00:00:31,720 --> 00:00:38,880 Currently, as far as I know, our team is as good as it was the previous year. 6 00:00:38,900 --> 00:00:42,840 I'm Dohyun, who used to be a hacker and CTF player. 7 00:00:44,400 --> 00: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. 8 00:00:53,660 --> 00:00:55,840 Here is Woowon. 9 00:01:02,220 --> 00:01:06,640 He's Woowon, who is a bug hunter and also a CTF player. 10 00:01:06,640 --> 00: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. 11 00:01:16,240 --> 00:01:20,900 And he is also working with me at Theory as a cyber-security researcher. 12 00:01:23,460 --> 00:01:27,500 There are some risks that you will take away from this talk. 13 00:01:27,500 --> 00:01:32,040 First, we will share vulnerabilities we have found in the real world. 14 00:01:32,040 --> 00:01:36,500 And bugs we found were pretty critical and variable. 15 00:01:36,660 --> 00:01:45,640 But we are here for sharing, and so it might be helpful for hunting and working related to security. 16 00:01:45,760 --> 00:01:51,780 And second, we are going to talk about some common mistakes in front-end work and cause of them. 17 00:01:51,960 --> 00:01:57,340 And finally, we will propose a solution to ensure your front-end is secure. 18 00:01:59,720 --> 00:02:08,120 There are so many important problems on cyber-security, and you are all here because you are interested in this topic. 19 00:02:08,120 --> 00:02:14,060 And then, why we choose and focus on the web front-end security? 20 00:02:17,210 --> 00:02:18,850 The answer is so simple. 21 00:02:18,850 --> 00:02:23,370 Just we found a lot of vulnerabilities in the wild. 22 00:02:23,510 --> 00:02:26,730 We are going to dig deeper into this cause. 23 00:02:26,730 --> 00:02:34,190 Okay, then, let's talk about why we choose and focus on the web front-end security. 24 00:02:34,570 --> 00:02:41,030 So, instead of thinking about reading a textbook and thinking just getting a time machine, then it will be more fun. 25 00:02:41,030 --> 00:02:44,350 And we will take a look about the history of web programming. 26 00:02:45,470 --> 00:02:50,090 So, nowadays, front-end application is already complicated. 27 00:02:50,150 --> 00:02:54,050 And it is the center, there are single-page applications. 28 00:02:54,050 --> 00:03:01,690 With the mobile and smartphone, there are almost clients were just a web browser. 29 00:03:01,690 --> 00:03:06,350 So, it's enough that represent data from web service directly. 30 00:03:06,350 --> 00:03:14,170 Since the emergence of iOS and Android, back-end and client implementation had to be further separation. 31 00:03:16,110 --> 00:03:17,230 Yeah, like that. 32 00:03:17,230 --> 00: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. 33 00:03:26,350 --> 00:03:29,970 Fetching the data and rendering it directly. 34 00:03:30,330 --> 00:03:34,110 Just it's got a lot of vulnerabilities, just it looks like. 35 00:03:34,110 --> 00:03:41,010 In the time, in times like this, the importance of the front-end was not emphasized. 36 00:03:42,790 --> 00:03:47,130 But now it's on the era of single-page application. 37 00:03:47,230 --> 00:03:54,770 A single-page application dynamically updates the content on the client page without requiring a full-page reload. 38 00:03:54,770 --> 00:03:59,950 And offering a smoother user experience similar to native applications. 39 00:04:00,810 --> 00:04:08,010 Even if you haven't heard about single-page application, you have probably heard of Vue and React. 40 00:04:08,310 --> 00:04:14,610 And after emerging that, productivity of front-end application was really increased. 41 00:04:15,530 --> 00:04:22,890 As productivity increased, the overall user experience of front-end has improved. 42 00:04:22,890 --> 00:04:29,110 And finally, front-end experience affects business results directly. 43 00:04:29,430 --> 00: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. 44 00:04:49,930 --> 00:05:00,770 The web browser has been upgraded more properly and not only functionally, but also performance-wise over a decade. 45 00:05:02,470 --> 00: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. 46 00:05:13,730 --> 00:05:17,030 Meanwhile, front-end can be an attack surface. 47 00:05:17,030 --> 00:05:19,770 There are two reasons. 48 00:05:19,770 --> 00:05:28,230 First one is front-end has more impact on business directly and require a lot more logic and responsibilities. 49 00:05:29,010 --> 00:05:40,470 And so, remember, with great power comes great responsibility, so the importance of front-end security are more increased. 50 00:05:41,990 --> 00:05:48,050 From now on, we are going to talk about the real-world case that we have found. 51 00:05:49,450 --> 00:05:55,330 Now, starting from classic, the XSS, the cross-site script. 52 00:05:55,370 --> 00: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. 53 00:06:10,130 --> 00: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. 54 00:06:27,130 --> 00:06:30,870 And view.js case, there are vHTML. 55 00:06:30,870 --> 00:06:37,090 This can be vulnerable, but this seems less risky, but they are still risky. 56 00:06:37,210 --> 00: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. 57 00:06:50,650 --> 00:06:52,990 Next, expose the secret. 58 00:06:53,110 --> 00:06:57,310 This is one of the simplest and most impactful vulnerabilities. 59 00:06:57,750 --> 00:07:05,010 Even if we don't look for zero-day vulnerabilities in complex code, but we can exploit them. 60 00:07:06,150 --> 00:07:11,910 There are cases where secret information such as API key and password are hard-coded. 61 00:07:11,910 --> 00:07:13,250 Yeah , just like that. 62 00:07:13,250 --> 00: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. 63 00:07:27,970 --> 00:07:34,150 And so, you are not reasoning that you didn't hard-code it. 64 00:07:34,150 --> 00:07:39,730 That means not only hard-coded, but also environment variable can be exposed. 65 00:07:39,730 --> 00:07:40,910 Yeah, just like that. 66 00:07:40,910 --> 00: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. 67 00:07:55,030 --> 00:08:01,970 So, we see a lot of vulnerabilities, especially on the big back office. 68 00:08:02,870 --> 00:08:11,090 We can find some case like this from the back office of the web system. 69 00:08:11,090 --> 00:08:13,250 How did we find this? 70 00:08:15,830 --> 00:08:22,370 We mainly obtained a lot of information that should be kept secret from the manifest. 71 00:08:22,890 --> 00:08:31,010 As you see, the build-manifest.js includes a lot of information of the web application. 72 00:08:31,010 --> 00:08:42,230 And it includes all URLs for application like error or about admin and some develop or staging page. 73 00:08:42,450 --> 00: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. 74 00:08:53,990 --> 00:08:58,390 A lot of information is more informative than you might think. 75 00:08:59,290 --> 00:09:04,670 Then, why is the routing information in manifest? 76 00:09:04,670 --> 00:09:06,410 So, why they are here? 77 00:09:06,410 --> 00:09:11,610 Because they are single-page application, and it's built by Next.js. 78 00:09:12,010 --> 00:09:17,110 In production mode, Next.js pre-renders pages that can be routed. 79 00:09:17,110 --> 00:09:23,730 It's for effective client-side navigation and page reloading. 80 00:09:23,730 --> 00: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. 81 00:09:32,330 --> 00:09:37,590 That file contains the implementation of those kind of process. 82 00:09:40,330 --> 00:09:45,050 So, now we have determined which URL should be attacked. 83 00:09:45,050 --> 00:09:49,940 The next step is to analyze the code and to find the vulnerabilities. 84 00:09:49,940 --> 00:09:54,080 Yeah, there are source map. 85 00:09:54,080 --> 00: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. 86 00:10:04,580 --> 00:10:11,700 This is the sample code of front-end application and how to minimize and optimize it. 87 00:10:15,010 --> 00: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. 88 00:10:26,330 --> 00: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. 89 00:10:37,250 --> 00: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. 90 00:10:51,750 --> 00: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. 91 00:11:02,450 --> 00:11:04,410 This is very sensitive. 92 00:11:04,710 --> 00:11:10,400 And not only that, it can be another attack surface. 93 00:11:10,400 --> 00: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. 94 00:11:25,420 --> 00:11:30,660 It is a kind of the door to start exploit the whole application. 95 00:11:33,240 --> 00:11:39,240 However, this makes it difficult for developers to debug. 96 00:11:39,240 --> 00:11:42,520 Even this very simple code is hard to debug. 97 00:11:42,520 --> 00:11:45,880 You don't know exactly where it's happening. 98 00:11:45,880 --> 00:11:49,540 But if developers are annoying, hackers are annoying too. 99 00:11:50,900 --> 00:11:56,960 Annotation in open source map can tell a lot to us. 100 00:11:56,960 --> 00: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. 101 00:12:10,580 --> 00: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. 102 00:12:20,720 --> 00:12:29,820 And sometimes they provide some hosts of web application to be an attack surface. 103 00:12:32,200 --> 00:12:37,060 And there is an interesting case that I'd like to share with you. 104 00:12:37,060 --> 00:12:47,060 Rails webpacker library had a source map enabled as default, and the pre-request came out saying it should be disabled. 105 00:12:47,160 --> 00: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. 106 00:13:00,420 --> 00:13:03,600 As far as I know, it is not applied. 107 00:13:04,160 --> 00:13:12,220 So still enable the source map configuration in webpacker in Rails, the Ruby on Rails. 108 00:13:12,880 --> 00:13:17,200 This is proof the source maps are that useful. 109 00:13:18,060 --> 00:13:20,860 Then, what should we do? 110 00:13:20,860 --> 00:13:26,360 Let me suggest a best practice for it. 111 00:13:27,500 --> 00:13:32,200 Most important thing is do not upload the source map in production. 112 00:13:32,420 --> 00:13:35,980 This can be done with just one line like those. 113 00:13:35,980 --> 00:13:40,100 module.export and devtools just as first. 114 00:13:40,380 --> 00:13:46,660 This can only upload the source map where authentication is required. 115 00:13:46,660 --> 00: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. 116 00:14:01,520 --> 00: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. 117 00:14:12,960 --> 00:14:18,420 And the last case is content integrity. 118 00:14:18,580 --> 00: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. 119 00:14:29,280 --> 00: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. 120 00:14:40,310 --> 00:14:45,270 Even if the service is not directly attacked, damage will assert. 121 00:14:45,570 --> 00:14:50,370 But in these days, the user also can be targeted. 122 00:14:51,310 --> 00: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. 123 00:15:02,010 --> 00: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. 124 00:15:14,990 --> 00:15:21,350 In other words, the contents are inserted from attacks domains and used for attacks. 125 00:15:22,730 --> 00:15:27,370 Here is an example of the following SRI. 126 00:15:27,510 --> 00:15:35,030 When the SRI is applied, external content is validated and not loaded if the content has been malformed with. 127 00:15:35,030 --> 00:15:40,430 This can be helped detect and block malformed external content. 128 00:15:41,410 --> 00:15:46,290 And second one is for contents integrity, is the CSP. 129 00:15:46,310 --> 00:15:53,390 And let's assume that we allow things to second data to example.com like this. 130 00:15:53,390 --> 00:16:00,490 If someone hacked the website and tried to send other domain, that will be blocked. 131 00:16:00,490 --> 00:16:08,150 This means checking or preventing integrity when malicious content is requested or loaded. 132 00:16:08,150 --> 00:16:13,750 One or more steps are required for hackers to succeed in an attack. 133 00:16:13,750 --> 00:16:19,510 In conclusion, CSP and SRIs validate the resource used in webpage. 134 00:16:19,650 --> 00:16:25,660 This increase the number of steps an attacker need to succeed, making attack more difficult. 135 00:16:28,720 --> 00:16:36,320 CSP and SRI are great feature, but there are reasons why they are challenging to implementation. 136 00:16:36,400 --> 00:16:41,440 First thing is hard to keep track of all resources. 137 00:16:41,440 --> 00:16:48,700 Second one is it can be cause usability issue when applying some new CSP rules. 138 00:16:50,420 --> 00:16:57,240 So we are looking on solving both of these problems. 139 00:16:57,240 --> 00:17:05,900 A simple idea is to track and verify all requests, apply a new CSP to the browser, and simulate the page. 140 00:17:06,600 --> 00:17:11,460 So we have prepared the demo video for you. 141 00:17:11,460 --> 00: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. 142 00:17:24,000 --> 00:17:34,940 And this right bottom one is the guide who developed by our demo and our team software engineer. 143 00:17:34,940 --> 00:17:37,060 So let's watch together. 144 00:17:48,180 --> 00:17:52,240 Alright, I want to showcase this tool that we wrote for the presentation. 145 00:17:52,240 --> 00:17:58,740 It's called Asynt Frontend Scanner, and it can extract valuable insights about your frontend application. 146 00:17:59,020 --> 00:18:04,480 To get started, just type in the location of your app, in this case, Siri.io. 147 00:18:07,250 --> 00:18:12,230 It might take up to 2 minutes to finish the scan, so please be patient. 148 00:18:12,690 --> 00:18:15,490 It's not actually 2 minutes, so don't worry about it. 149 00:18:23,260 --> 00:18:26,680 Alright, let's start with the Resource Insights tab. 150 00:18:26,680 --> 00: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. 151 00:18:33,560 --> 00:18:39,220 On the left pane of this tab, you can see a list of all the resources loaded by the page. 152 00:18:42,740 --> 00:18:47,440 You can also group them by type, such as images, scripts, and so on. 153 00:18:47,440 --> 00:18:54,460 This can help you quickly identify any unusual or suspicious resources that might be loaded by the page. 154 00:18:55,760 --> 00:19:00,240 Moving on to the bottom half of the left pane, you can see the Domain Overview. 155 00:19:00,420 --> 00:19:04,280 This section shows a list of domains for each resource type. 156 00:19:04,620 --> 00:19:09,060 This can help you identify which third-party domain resources are being loaded. 157 00:19:09,060 --> 00: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. 158 00:19:22,700 --> 00:19:29,780 Now, please be aware of the fact that this overview shows only resources that were loaded during the initial page load. 159 00:19:29,780 --> 00: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. 160 00:19:36,920 --> 00: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. 161 00:19:47,220 --> 00:19:52,920 Now, let's move on to the Resource Graph View, which is on the right pane of the Resource Insights tab. 162 00:19:52,920 --> 00:19:58,100 Here, you can see a visual representation of the resources that were loaded by the page. 163 00:19:59,060 --> 00:20:08,200 The leftmost resource is the one that was loaded first, and the arrow indicates a direct dependence between the resources. 164 00:20:09,120 --> 00:20:16,160 This graph can help you identify any dependencies between resources and find out why the specific resource was loaded. 165 00:20:17,800 --> 00: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. 166 00:20:26,940 --> 00:20:33,740 It also focuses the resource on the graph view, letting you easily discover its dependencies and dependence. 167 00:20:34,100 --> 00: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. 168 00:20:43,780 --> 00:20:48,440 If the resource is loaded through a POST request, you can also see the POST data. 169 00:20:50,200 --> 00: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. 170 00:20:57,820 --> 00: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. 171 00:21:10,620 --> 00:21:14,660 This is a simple Next.js app hosting blog post. 172 00:21:14,660 --> 00:21:17,840 Let's analyze this application using our tool. 173 00:21:17,840 --> 00:21:19,780 That's a sample page. 174 00:21:20,780 --> 00:21:28,070 As you can see, this application is loading external resources from static.synth.io domain. 175 00:21:28,400 --> 00:21:33,240 This could be a potential attack vector if the site hosting the script gets compromised. 176 00:21:35,580 --> 00: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. 177 00:21:51,180 --> 00:21:54,320 Now, let's visit the site again to see what happened. 178 00:21:59,690 --> 00:22:03,950 You can see that the cover image for the hero post has been hijacked. 179 00:22:04,430 --> 00:22:08,810 We can use the Resource Insights to find out who loaded the rogue image. 180 00:22:08,910 --> 00:22:11,730 Firstly, let's analyze the application again. 181 00:22:24,420 --> 00:22:28,840 In the Images tab, we can go through the images loaded by the page. 182 00:22:35,620 --> 00:22:38,200 It looks like we have found a culprit. 183 00:22:38,520 --> 00:22:41,640 Now, let's find out who loaded this image. 184 00:22:45,320 --> 00:22:51,220 You can see that the analytic script we compromised indeed loaded the defacement image. 185 00:22:51,400 --> 00:22:58,300 To prevent this kind of attacks, make sure you have specified SRI hashes to the external scripts loaded. 186 00:22:58,500 --> 00:23:04,660 Also, establishing content security policies for your website makes these kind of attacks much harder to pull off. 187 00:23:06,960 --> 00:23:11,620 This demo page we just showed also contains publicly exposed secret information. 188 00:23:11,640 --> 00:23:17,500 However, manually finding these kind of secrets are time-consuming and labor-intensive. 189 00:23:17,540 --> 00:23:21,660 That's why we also created a secret scanner for front-end applications. 190 00:23:22,220 --> 00:23:27,980 However, it's important to note that secret scanners may have false positives and false negatives. 191 00:23:27,980 --> 00: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. 192 00:23:41,020 --> 00:23:46,460 As you can see, the demo page contains quite a lot of high-severity credentials. 193 00:23:46,660 --> 00:23:51,440 However, the scripts containing these scripts were not directly loaded. 194 00:23:51,440 --> 00: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. 195 00:24:00,940 --> 00:24:05,740 Here, you can see that this secret is discovered through build manifests. 196 00:24:05,740 --> 00: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. 197 00:24:16,640 --> 00:24:22,960 Front-end security lacks the attention it deserves, and easily exploitable vulnerabilities are often overlooked. 198 00:24:23,200 --> 00: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. 199 00:24:35,740 --> 00:24:38,280 That's all of our demo. 200 00:24:38,780 --> 00:24:41,720 Back to the presentation. 201 00:24:41,780 --> 00:24:50,640 As you see from the demo, it can assist in the creation of CSP or SRI rules. 202 00:24:50,640 --> 00:24:54,680 However, there are other things we need to think about. 203 00:24:54,680 --> 00: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. 204 00:25:05,740 --> 00: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. 205 00:25:20,040 --> 00:25:26,900 So far, we talked about those five topics and demos. 206 00:25:26,900 --> 00:25:37,130 For recap, everything exists for a reason, manifest or source map, like those things, and there are also shared responsibilities. 207 00:25:37,660 --> 00: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. 208 00:25:46,300 --> 00:25:52,110 And finally, security engineers, like us, need to be prepared for all of the threats. 209 00:25:52,110 --> 00: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. 210 00:26:01,190 --> 00:26:06,030 They have different concerns, so we need to maintain a healthy conflict. 211 00:26:06,130 --> 00:26:12,290 Similarly, programmers can only mitigate so much if a user lacks security awareness. 212 00:26:12,290 --> 00: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. 213 00:26:22,110 --> 00:26:29,910 As you move to the endpoint, security becomes more of a management issue than a technical one. 214 00:26:29,950 --> 00:26:37,470 So, for example, writing or sharing passwords through plain text or notepad is one example of those. 215 00:26:38,510 --> 00: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. 216 00:26:49,450 --> 00:26:57,790 So, thank you for your attention, and if you want to try our demo, please fill out this form. 217 00:26:57,830 --> 00: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. 218 00:27:15,250 --> 00:27:21,850 The form is pretty simple, so please fill out this, and I will send the link of the demo. 219 00:27:24,190 --> 00:27:28,270 Thank you for your attention, and the presentation is at the end.