We are going to talk about front-end security with some title. Securing the front lines, protecting front-end applications from overlooked vulnerabilities. First of all, a little bit about us. We are a member of Theory, a cyber-secret startup, and the winner of the last DEF CON CTF. Currently, as far as I know, our team is as good as it was the previous year. I'm Dohyun, who used to be a hacker and CTF player. And I started hacking since 10 years ago, and I'm also working as a first-tier web programmer and product manager at Theory. Here is Woowon. He's Woowon, who is a bug hunter and also a CTF player. He is winner of the DEF CON CTF that opened last year, and also he is trying to be winner this year also. And he is also working with me at Theory as a cyber-security researcher. There are some risks that you will take away from this talk. First, we will share vulnerabilities we have found in the real world. And bugs we found were pretty critical and variable. But we are here for sharing, and so it might be helpful for hunting and working related to security. And second, we are going to talk about some common mistakes in front-end work and cause of them. And finally, we will propose a solution to ensure your front-end is secure. There are so many important problems on cyber-security, and you are all here because you are interested in this topic. And then, why we choose and focus on the web front-end security? The answer is so simple. Just we found a lot of vulnerabilities in the wild. We are going to dig deeper into this cause. Okay, then, let's talk about why we choose and focus on the web front-end security. So, instead of thinking about reading a textbook and thinking just getting a time machine, then it will be more fun. And we will take a look about the history of web programming. So, nowadays, front-end application is already complicated. And it is the center, there are single-page applications. With the mobile and smartphone, there are almost clients were just a web browser. So, it's enough that represent data from web service directly. Since the emergence of iOS and Android, back-end and client implementation had to be further separation. Yeah, like that. As you can see this code, we simply made a database connection, made a query and returned the result rendered by the server. Fetching the data and rendering it directly. Just it's got a lot of vulnerabilities, just it looks like. In the time, in times like this, the importance of the front-end was not emphasized. But now it's on the era of single-page application. A single-page application dynamically updates the content on the client page without requiring a full-page reload. And offering a smoother user experience similar to native applications. Even if you haven't heard about single-page application, you have probably heard of Vue and React. And after emerging that, productivity of front-end application was really increased. As productivity increased, the overall user experience of front-end has improved. And finally, front-end experience affects business results directly. 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. The web browser has been upgraded more properly and not only functionally, but also performance-wise over a decade. 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. Meanwhile, front-end can be an attack surface. There are two reasons. First one is front-end has more impact on business directly and require a lot more logic and responsibilities. And so, remember, with great power comes great responsibility, so the importance of front-end security are more increased. From now on, we are going to talk about the real-world case that we have found. Now, starting from classic, the XSS, the cross-site script. 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. 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. And view.js case, there are vHTML. This can be vulnerable, but this seems less risky, but they are still risky. 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. Next, expose the secret. This is one of the simplest and most impactful vulnerabilities. Even if we don't look for zero-day vulnerabilities in complex code, but we can exploit them. There are cases where secret information such as API key and password are hard-coded. Yeah, just like that. 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. And so, you are not reasoning that you didn't hard-code it. That means not only hard-coded, but also environment variable can be exposed. Yeah, just like that. There are sample code to send a message to Slack, and even if write this way, it can be still exposed via Node EMV. So, we see a lot of vulnerabilities, especially on the big back office. We can find some case like this from the back office of the web system. How did we find this? We mainly obtained a lot of information that should be kept secret from the manifest. As you see, the build-manifest.js includes a lot of information of the web application. And it includes all URLs for application like error or about admin and some develop or staging page. As you see, there are a lot of interesting things like the back office system that only developers and administrators can access. A lot of information is more informative than you might think. Then, why is the routing information in manifest? So, why they are here? Because they are single-page application, and it's built by Next.js. In production mode, Next.js pre-renders pages that can be routed. It's for effective client-side navigation and page reloading. 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. That file contains the implementation of those kind of process. So, now we have determined which URL should be attacked. The next step is to analyze the code and to find the vulnerabilities. Yeah, there are source map. We love to use source map to find our analysis vulnerabilities, and in general, the modern web stack optimize and minimize code like this. This is the sample code of front-end application and how to minimize and optimize it. 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. 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. 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. You can then call the back-office API and to refund the payment or creating a deleted user and viewing some user information. This is very sensitive. And not only that, it can be another attack surface. 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. It is a kind of the door to start exploit the whole application. However, this makes it difficult for developers to debug. Even this very simple code is hard to debug. You don't know exactly where it's happening. But if developers are annoying, hackers are annoying too. Annotation in open source map can tell a lot to us. In some cases, we have recognized account IDs and password information, and where security patches are already authored and are planned like this. There are some example of account information in the notation, and there are some security patch or plan about the security patch. And sometimes they provide some hosts of web application to be an attack surface. And there is an interesting case that I'd like to share with you. Rails webpacker library had a source map enabled as default, and the pre-request came out saying it should be disabled. 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. As far as I know, it is not applied. So still enable the source map configuration in webpacker in Rails, the Ruby on Rails. This is proof the source maps are that useful. Then, what should we do? Let me suggest a best practice for it. Most important thing is do not upload the source map in production. This can be done with just one line like those. module.export and devtools just as first. This can only upload the source map where authentication is required. 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. 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. And the last case is content integrity. Now, with the growth of Web3, the blockchain, and the influx of large assets, there have been many attacks targeting users' assets. Network attacks such as BGP hijacking or attacks that take over a third-party application and tamper with front-end content have been asserted. Even if the service is not directly attacked, damage will assert. But in these days, the user also can be targeted. This is an example of phishing to get some private key, but no application received a private key in the first place. And this attack inserted malicious code into front-end content to perform malicious behavior such as stealing user info data or leaking the information. In other words, the contents are inserted from attacks domains and used for attacks. Here is an example of the following SRI. When the SRI is applied, external content is validated and not loaded if the content has been malformed with. This can be helped detect and block malformed external content. And second one is for contents integrity, is the CSP. And let's assume that we allow things to second data to example.com like this. If someone hacked the website and tried to send other domain, that will be blocked. This means checking or preventing integrity when malicious content is requested or loaded. One or more steps are required for hackers to succeed in an attack. In conclusion, CSP and SRIs validate the resource used in webpage. This increase the number of steps an attacker need to succeed, making attack more difficult. CSP and SRI are great feature, but there are reasons why they are challenging to implementation. First thing is hard to keep track of all resources. Second one is it can be cause usability issue when applying some new CSP rules. So we are looking on solving both of these problems. A simple idea is to track and verify all requests, apply a new CSP to the browser, and simulate the page. So we have prepared the demo video for you. And that visualizing resource graph view and result of scanning secrets to set up CSP well and find the attack vector better. And this right bottom one is the guide who developed by our demo and our team software engineer. So let's watch together. Alright, I want to showcase this tool that we wrote for the presentation. It's called Asynt Frontend Scanner, and it can extract valuable insights about your frontend application. To get started, just type in the location of your app, in this case, Siri.io. It might take up to 2 minutes to finish the scan, so please be patient. It's not actually 2 minutes, so don't worry about it. Alright, let's start with the Resource Insights tab. In this tab, you can see the summary and the details about the resources that were loaded by the browser during the page load. On the left pane of this tab, you can see a list of all the resources loaded by the page. You can also group them by type, such as images, scripts, and so on. This can help you quickly identify any unusual or suspicious resources that might be loaded by the page. Moving on to the bottom half of the left pane, you can see the Domain Overview. This section shows a list of domains for each resource type. This can help you identify which third-party domain resources are being loaded. 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. Now, please be aware of the fact that this overview shows only resources that were loaded during the initial page load. This means that there might be resources which were not captured during the scan, even if those resources are recovered by your application. 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. Now, let's move on to the Resource Graph View, which is on the right pane of the Resource Insights tab. Here, you can see a visual representation of the resources that were loaded by the page. The leftmost resource is the one that was loaded first, and the arrow indicates a direct dependence between the resources. This graph can help you identify any dependencies between resources and find out why the specific resource was loaded. If you want to inspect a resource in more detail, you can click on it to reveal additional information about the request and response. It also focuses the resource on the graph view, letting you easily discover its dependencies and dependence. In the Details section, you can see additional details such as SRI hash, request headers, and response headers, and the initiator of the request. If the resource is loaded through a POST request, you can also see the POST data. Now, I want to share with you how the Resource Insights view can help the security team track down potential defacement attacks. 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. This is a simple Next.js app hosting blog post. Let's analyze this application using our tool. That's a sample page. As you can see, this application is loading external resources from static.synth.io domain. This could be a potential attack vector if the site hosting the script gets compromised. Let's simulate a hypothetical supply chain attack by uploading a raw copy of the script to the static.synth.io site. Now, let's visit the site again to see what happened. You can see that the cover image for the hero post has been hijacked. We can use the Resource Insights to find out who loaded the rogue image. Firstly, let's analyze the application again. In the Images tab, we can go through the images loaded by the page. It looks like we have found a culprit. Now, let's find out who loaded this image. You can see that the analytic script we compromised indeed loaded the defacement image. To prevent this kind of attacks, make sure you have specified SRI hashes to the external scripts loaded. Also, establishing content security policies for your website makes these kind of attacks much harder to pull off. This demo page we just showed also contains publicly exposed secret information. However, manually finding these kind of secrets are time-consuming and labor-intensive. That's why we also created a secret scanner for front-end applications. However, it's important to note that secret scanners may have false positives and false negatives. Despite this, the secret scanner remains a valuable tool because secrets are often located together, making it easier to detect potential security risks efficiently. As you can see, the demo page contains quite a lot of high-severity credentials. However, the scripts containing these scripts were not directly loaded. One advantage of our secret scanner is that it can discover so-called hidden pages through enumerating build manifests of the front-end application. Here, you can see that this secret is discovered through build manifests. 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. Front-end security lacks the attention it deserves, and easily exploitable vulnerabilities are often overlooked. 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. That's all of our demo. Back to the presentation. As you see from the demo, it can assist in the creation of CSP or SRI rules. However, there are other things we need to think about. First, there are cases where the attack surface is exposed to internal or staging state domains other than the target domain within the CSP. 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. So far, we talked about those five topics and demos. For recap, everything exists for a reason, manifest or source map, like those things, and there are also shared responsibilities. A user needs to take care of their own security, and programmers need to take care of their own code or infrastructure. And finally, security engineers, like us, need to be prepared for all of the threats. That means no matter how good the security perks are, if the programmers aren't aware, the problem won't be solved. They have different concerns, so we need to maintain a healthy conflict. Similarly, programmers can only mitigate so much if a user lacks security awareness. No matter how robust the backend security is, it is worthless if keys and APIs are just exposed on the frontend and production. As you move to the endpoint, security becomes more of a management issue than a technical one. So, for example, writing or sharing passwords through plain text or notepad is one example of those. So, long story short, we just want to tell, check whether your sensitive data is publicly exposed, and everything is not text-surfaced. So, thank you for your attention, and if you want to try our demo, please fill out this form. 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. The form is pretty simple, so please fill out this, and I will send the link of the demo. Thank you for your attention, and the presentation is at the end.