start	end	text
8120	14260	We are going to talk about front-end security with some title.
14320	17860	Securing the front lines, protecting front-end applications
17860	20240	from overlooked vulnerabilities.
21920	25200	First of all, a little bit about us.
25200	28520	We are a member of Theory, a cyber-secret startup,
28520	31440	and the winner of the last DEF CON CTF.
31720	34780	Currently, as far as I know,
34780	38880	our team is as good as it was the previous year.
38900	42840	I'm Dohyun, who used to be a hacker and CTF player.
44400	48160	And I started hacking since 10 years ago,
48160	50460	and I'm also working as a first-tier web programmer
50460	53380	and product manager at Theory.
53660	55840	Here is Woowon.
62220	66640	He's Woowon, who is a bug hunter and also a CTF player.
66640	70860	He is winner of the DEF CON CTF that opened last year,
70860	76240	and also he is trying to be winner this year also.
76240	78600	And he is also working with me at Theory
78600	80900	as a cyber-security researcher.
83460	87500	There are some risks that you will take away from this talk.
87500	92040	First, we will share vulnerabilities we have found in the real world.
92040	96500	And bugs we found were pretty critical and variable.
96660	98860	But we are here for sharing,
98860	105640	and so it might be helpful for hunting and working related to security.
105760	108860	And second, we are going to talk about some common mistakes
108860	111780	in front-end work and cause of them.
111960	117340	And finally, we will propose a solution to ensure your front-end is secure.
119720	124160	There are so many important problems on cyber-security,
124160	128120	and you are all here because you are interested in this topic.
128120	134060	And then, why we choose and focus on the web front-end security?
137210	138850	The answer is so simple.
138850	143370	Just we found a lot of vulnerabilities in the wild.
143510	146730	We are going to dig deeper into this cause.
146730	154190	Okay, then, let's talk about why we choose and focus on the web front-end security.
154570	157210	So, instead of thinking about reading a textbook
157210	159590	and thinking just getting a time machine,
159590	161030	then it will be more fun.
161030	164350	And we will take a look about the history of web programming.
165470	170090	So, nowadays, front-end application is already complicated.
170150	174050	And it is the center, there are single-page applications.
174050	177650	With the mobile and smartphone,
177650	181690	there are almost clients were just a web browser.
181690	186350	So, it's enough that represent data from web service directly.
186350	189670	Since the emergence of iOS and Android,
189670	194170	back-end and client implementation had to be further separation.
196110	197230	Yeah, like that.
197230	201830	As you can see this code, we simply made a database connection,
201830	206030	made a query and returned the result rendered by the server.
206350	209970	Fetching the data and rendering it directly.
210330	214110	Just it's got a lot of vulnerabilities, just it looks like.
214110	217150	In the time, in times like this,
217150	221010	the importance of the front-end was not emphasized.
222790	227130	But now it's on the era of single-page application.
227230	230670	A single-page application dynamically updates the content
230670	234770	on the client page without requiring a full-page reload.
234770	239950	And offering a smoother user experience similar to native applications.
240810	244690	Even if you haven't heard about single-page application,
244690	248010	you have probably heard of Vue and React.
248310	249950	And after emerging that,
250290	254610	productivity of front-end application was really increased.
255530	257810	As productivity increased,
257810	262890	the overall user experience of front-end has improved.
262890	269110	And finally, front-end experience affects business results directly.
269430	272070	There are so many metrics that explain
272070	275110	our correlation of user experience and business,
275110	276590	but we are tech guy,
276590	280950	so leaving aside the boring business tactics or metrics,
280950	282890	let's look at it from perspective
284830	287630	for improving browser performance.
289930	293830	The web browser has been upgraded more properly
293830	297750	and not only functionally,
297750	300770	but also performance-wise over a decade.
302470	306150	So far, coming back to the origin point,
306150	309150	the biggest reason we focus on front-end security
309150	313510	because everyone is focused on back-end security.
313730	317030	Meanwhile, front-end can be an attack surface.
317030	319770	There are two reasons.
319770	323250	First one is front-end has more impact on business directly
323250	328230	and require a lot more logic and responsibilities.
329010	332870	And so, remember, with great power comes great responsibility,
332870	340470	so the importance of front-end security are more increased.
341990	346030	From now on, we are going to talk about the real-world case
346030	348050	that we have found.
349450	355330	Now, starting from classic, the XSS, the cross-site script.
355370	360210	To be honest, it gets harder in the modern web stack
360210	365790	because mitigation in framework or library is getting stronger,
365790	369610	and it's harder for developers to make mistakes.
370130	375650	We found to use the function that look dangerous by name,
375650	381810	like dangerously set innerHTML or prefix of unsafe,
381810	386910	but now the safe one is the default way.
387130	390870	And view.js case, there are vHTML.
390870	395730	This can be vulnerable, but this seems less risky,
395730	397090	but they are still risky.
397210	401390	That's the reason why we need content-secret policy
401390	404130	as talked before the presentation,
404130	408410	and we will mention it again in the rest of our presentation.
410650	412990	Next, expose the secret.
413110	417310	This is one of the simplest and most impactful vulnerabilities.
417750	422230	Even if we don't look for zero-day vulnerabilities in complex code,
422710	425010	but we can exploit them.
426150	431910	There are cases where secret information such as API key and password are hard-coded.
431910	433250	Yeah, just like that.
433250	438690	There are some example secret value from using the authorization,
438690	442930	and sometimes they are just hard-coded in the production,
442930	445610	and we can discover it.
447970	454150	And so, you are not reasoning that you didn't hard-code it.
454150	459730	That means not only hard-coded, but also environment variable can be exposed.
459730	460910	Yeah, just like that.
460910	467170	There are sample code to send a message to Slack,
467170	472950	and even if write this way, it can be still exposed via Node EMV.
475030	481970	So, we see a lot of vulnerabilities, especially on the big back office.
482870	491090	We can find some case like this from the back office of the web system.
491090	493250	How did we find this?
495830	502370	We mainly obtained a lot of information that should be kept secret from the manifest.
502890	511010	As you see, the build-manifest.js includes a lot of information of the web application.
511010	522230	And it includes all URLs for application like error or about admin and some develop or staging page.
522450	528470	As you see, there are a lot of interesting things like the back office system
528470	533110	that only developers and administrators can access.
533990	538390	A lot of information is more informative than you might think.
539290	544670	Then, why is the routing information in manifest?
544670	546410	So, why they are here?
546410	551610	Because they are single-page application, and it's built by Next.js.
552010	557110	In production mode, Next.js pre-renders pages that can be routed.
557110	563730	It's for effective client-side navigation and page reloading.
563730	567050	If you are wondering the reason and how to work with it,
567050	572330	you can take a look at build-manifest-plugin.js from Next.js.
572330	577590	That file contains the implementation of those kind of process.
580330	585050	So, now we have determined which URL should be attacked.
585050	589940	The next step is to analyze the code and to find the vulnerabilities.
589940	594080	Yeah, there are source map.
594080	599140	We love to use source map to find our analysis vulnerabilities,
599140	604580	and in general, the modern web stack optimize and minimize code like this.
604580	611700	This is the sample code of front-end application and how to minimize and optimize it.
615010	619350	So, once you can read the source code in the admin page,
619350	625590	you can bypass the admin check and logic that is only implementation on the client.
626330	630410	This is the sample React code that some front-end application,
630410	637250	and they checked the admin stage, and if not admin, then just redirect some other way.
637250	643230	But if we can read the front-end code, then we can access and we can find
643230	650730	what kind of process or what kind of API code in the real application.
651750	657310	You can then call the back-office API and to refund the payment
657310	662450	or creating a deleted user and viewing some user information.
662450	664410	This is very sensitive.
664710	670400	And not only that, it can be another attack surface.
670400	675560	That means, as you know, code of back-end application is not open,
675560	682620	but if you can and find those API list, then you can also try to exploit them,
682620	685420	the API of back-end application.
685420	690660	It is a kind of the door to start exploit the whole application.
693240	699240	However, this makes it difficult for developers to debug.
699240	702520	Even this very simple code is hard to debug.
702520	705880	You don't know exactly where it's happening.
705880	709540	But if developers are annoying, hackers are annoying too.
710900	716960	Annotation in open source map can tell a lot to us.
716960	723660	In some cases, we have recognized account IDs and password information,
723660	730580	and where security patches are already authored and are planned like this.
730580	736160	There are some example of account information in the notation,
736160	740720	and there are some security patch or plan about the security patch.
740720	749820	And sometimes they provide some hosts of web application to be an attack surface.
752200	757060	And there is an interesting case that I'd like to share with you.
757060	761520	Rails webpacker library had a source map enabled as default,
761520	767060	and the pre-request came out saying it should be disabled.
767160	776640	But DHH, the founder of Rails, says he learned a lot of CSS and JS from the view source feature,
776640	779340	so he wants to cap this feature.
780420	783600	As far as I know, it is not applied.
784160	792220	So still enable the source map configuration in webpacker in Rails, the Ruby on Rails.
792880	797200	This is proof the source maps are that useful.
798060	800860	Then, what should we do?
800860	806360	Let me suggest a best practice for it.
807500	812200	Most important thing is do not upload the source map in production.
812420	815980	This can be done with just one line like those.
815980	820100	module.export and devtools just as first.
820380	826660	This can only upload the source map where authentication is required.
826660	833180	That means there are some service to upload the source map and track the error,
833180	840500	and this can be only accessed by some authenticated users.
841520	846940	Or use a tool to map error log with original source code,
846940	852960	and ideally make your code robust, then you don't mind it being exposed.
852960	858420	And the last case is content integrity.
858580	864780	Now, with the growth of Web3, the blockchain, and the influx of large assets,
864780	869080	there have been many attacks targeting users' assets.
869280	875130	Network attacks such as BGP hijacking or attacks that take over a third-party application
875620	880310	and tamper with front-end content have been asserted.
880310	885270	Even if the service is not directly attacked, damage will assert.
885570	890370	But in these days, the user also can be targeted.
891310	896890	This is an example of phishing to get some private key,
896890	901970	but no application received a private key in the first place.
902010	906010	And this attack inserted malicious code into front-end content
906010	913290	to perform malicious behavior such as stealing user info data or leaking the information.
914990	921350	In other words, the contents are inserted from attacks domains and used for attacks.
922730	927370	Here is an example of the following SRI.
927510	935030	When the SRI is applied, external content is validated and not loaded if the content has been malformed with.
935030	940430	This can be helped detect and block malformed external content.
941410	946290	And second one is for contents integrity, is the CSP.
946310	953390	And let's assume that we allow things to second data to example.com like this.
953390	960490	If someone hacked the website and tried to send other domain, that will be blocked.
960490	968150	This means checking or preventing integrity when malicious content is requested or loaded.
968150	973750	One or more steps are required for hackers to succeed in an attack.
973750	979510	In conclusion, CSP and SRIs validate the resource used in webpage.
979650	985660	This increase the number of steps an attacker need to succeed, making attack more difficult.
988720	996320	CSP and SRI are great feature, but there are reasons why they are challenging to implementation.
996400	1001440	First thing is hard to keep track of all resources.
1001440	1008700	Second one is it can be cause usability issue when applying some new CSP rules.
1010420	1017240	So we are looking on solving both of these problems.
1017240	1025900	A simple idea is to track and verify all requests, apply a new CSP to the browser, and simulate the page.
1026600	1031460	So we have prepared the demo video for you.
1031460	1043860	And that visualizing resource graph view and result of scanning secrets to set up CSP well and find the attack vector better.
1044000	1054940	And this right bottom one is the guide who developed by our demo and our team software engineer.
1054940	1057060	So let's watch together.
1068180	1072240	Alright, I want to showcase this tool that we wrote for the presentation.
1072240	1078740	It's called Asynt Frontend Scanner, and it can extract valuable insights about your frontend application.
1079020	1084480	To get started, just type in the location of your app, in this case, Siri.io.
1087250	1092230	It might take up to 2 minutes to finish the scan, so please be patient.
1092690	1095490	It's not actually 2 minutes, so don't worry about it.
1103260	1106680	Alright, let's start with the Resource Insights tab.
1106680	1113100	In this tab, you can see the summary and the details about the resources that were loaded by the browser during the page load.
1113560	1119220	On the left pane of this tab, you can see a list of all the resources loaded by the page.
1122740	1127440	You can also group them by type, such as images, scripts, and so on.
1127440	1134460	This can help you quickly identify any unusual or suspicious resources that might be loaded by the page.
1135760	1140240	Moving on to the bottom half of the left pane, you can see the Domain Overview.
1140420	1144280	This section shows a list of domains for each resource type.
1144620	1149060	This can help you identify which third-party domain resources are being loaded.
1149060	1155180	Furthermore, you can use this information to construct an initial version of your content security policy,
1155180	1162160	which, as we said in the presentation, can help protect against cross-site scripting outtakes and other security vulnerabilities.
1162700	1169780	Now, please be aware of the fact that this overview shows only resources that were loaded during the initial page load.
1169780	1176920	This means that there might be resources which were not captured during the scan, even if those resources are recovered by your application.
1176920	1185140	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.
1187220	1192920	Now, let's move on to the Resource Graph View, which is on the right pane of the Resource Insights tab.
1192920	1198100	Here, you can see a visual representation of the resources that were loaded by the page.
1199060	1208200	The leftmost resource is the one that was loaded first, and the arrow indicates a direct dependence between the resources.
1209120	1216160	This graph can help you identify any dependencies between resources and find out why the specific resource was loaded.
1217800	1225320	If you want to inspect a resource in more detail, you can click on it to reveal additional information about the request and response.
1226940	1233740	It also focuses the resource on the graph view, letting you easily discover its dependencies and dependence.
1234100	1243380	In the Details section, you can see additional details such as SRI hash, request headers, and response headers, and the initiator of the request.
1243780	1248440	If the resource is loaded through a POST request, you can also see the POST data.
1250200	1257700	Now, I want to share with you how the Resource Insights view can help the security team track down potential defacement attacks.
1257820	1265060	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.
1270620	1277840	This is a simple Next.js app hosting blog post. Let's analyze this application using our tool.
1277840	1279780	That's a sample page.
1280780	1288070	As you can see, this application is loading external resources from static.synth.io domain.
1288400	1293240	This could be a potential attack vector if the site hosting the script gets compromised.
1295580	1303080	Let's simulate a hypothetical supply chain attack by uploading a raw copy of the script to the static.synth.io site.
1311180	1314320	Now, let's visit the site again to see what happened.
1319690	1323950	You can see that the cover image for the hero post has been hijacked.
1324430	1328810	We can use the Resource Insights to find out who loaded the rogue image.
1328910	1331730	Firstly, let's analyze the application again.
1344420	1348840	In the Images tab, we can go through the images loaded by the page.
1355620	1361640	It looks like we have found a culprit. Now, let's find out who loaded this image.
1365320	1371220	You can see that the analytic script we compromised indeed loaded the defacement image.
1371400	1378300	To prevent this kind of attacks, make sure you have specified SRI hashes to the external scripts loaded.
1378500	1384660	Also, establishing content security policies for your website makes these kind of attacks much harder to pull off.
1386960	1391620	This demo page we just showed also contains publicly exposed secret information.
1391640	1397500	However, manually finding these kind of secrets are time-consuming and labor-intensive.
1397540	1401660	That's why we also created a secret scanner for front-end applications.
1402220	1407980	However, it's important to note that secret scanners may have false positives and false negatives.
1407980	1417580	Despite this, the secret scanner remains a valuable tool because secrets are often located together, making it easier to detect potential security risks efficiently.
1421020	1426460	As you can see, the demo page contains quite a lot of high-severity credentials.
1426660	1431440	However, the scripts containing these scripts were not directly loaded.
1431440	1439260	One advantage of our secret scanner is that it can discover so-called hidden pages through enumerating build manifests of the front-end application.
1440940	1445740	Here, you can see that this secret is discovered through build manifests.
1445740	1454780	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.
1456640	1462960	Front-end security lacks the attention it deserves, and easily exploitable vulnerabilities are often overlooked.
1463200	1473700	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.
1475740	1481720	That's all of our demo. Back to the presentation.
1481780	1490640	As you see from the demo, it can assist in the creation of CSP or SRI rules.
1490640	1494680	However, there are other things we need to think about.
1494680	1505280	First, there are cases where the attack surface is exposed to internal or staging state domains other than the target domain within the CSP.
1505740	1518960	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.
1520040	1526900	So far, we talked about those five topics and demos.
1526900	1537130	For recap, everything exists for a reason, manifest or source map, like those things, and there are also shared responsibilities.
1537660	1545880	A user needs to take care of their own security, and programmers need to take care of their own code or infrastructure.
1546300	1552110	And finally, security engineers, like us, need to be prepared for all of the threats.
1552110	1561190	That means no matter how good the security perks are, if the programmers aren't aware, the problem won't be solved.
1561190	1566030	They have different concerns, so we need to maintain a healthy conflict.
1566130	1572290	Similarly, programmers can only mitigate so much if a user lacks security awareness.
1572290	1582050	No matter how robust the backend security is, it is worthless if keys and APIs are just exposed on the frontend and production.
1582110	1589910	As you move to the endpoint, security becomes more of a management issue than a technical one.
1589950	1597470	So, for example, writing or sharing passwords through plain text or notepad is one example of those.
1598510	1609450	So, long story short, we just want to tell, check whether your sensitive data is publicly exposed, and everything is not text-surfaced.
1609450	1617790	So, thank you for your attention, and if you want to try our demo, please fill out this form.
1617830	1635250	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.
1635250	1641850	The form is pretty simple, so please fill out this, and I will send the link of the demo.
1644190	1648270	Thank you for your attention, and the presentation is at the end.
