Eval all the strings! - Hardened JavaScript

Rate this content
Bookmark
GithubProject website

This talk is about SecureEcmaScript and Compartments which are TC39 proposals, and I'm working on tooling to make these concepts usable with people championing those proposals.
This is a first-hand account of the future of JavaScript security.
SES + tooling (LavaMoat or Endo) is making limiting access to network, fs, core modules or globals possible on a per-package basis.
I want to show how they work, what possibilities they open and how to make that future happen today with some effort.
To me this is the final step in securing npm supply chain - even if a package gets taken over by bad actors, it won't be able to hurt me.

This talk has been presented at Node Congress 2023, check out the latest edition of this JavaScript Conference.

FAQ

Lava Mode is a tool that allows you to be proactive instead of reactive by generating policies to control what packages in your application can access. It helps prevent malicious packages from causing harm.

Lava Mode works by generating a policy for your application that restricts what each package can access. It uses a technology called LockDown to lock down the JavaScript environment, making it impossible to tamper with.

Prototype pollution is a type of attack where an attacker changes the prototype of a base object, leading to unintended behavior. Lava Mode prevents this by making objects non-extensible, thereby blocking such changes.

Lava Mode uses several technologies including LockDown and hardened JavaScript. These technologies help isolate each dependency within the same process, preventing tampering with the JavaScript environment.

Lava Mode can help by generating a policy that restricts what a package can do, effectively limiting the damage a malicious package can cause. It can also reveal the behavior of obfuscated malware without needing to deobfuscate it.

Yes, Lava Mode can be integrated into existing projects. The speaker offers to help set up Lava Mode in your project if you get in touch early enough.

NPM audit works by informing you of malicious packages weeks after you have shipped your app to production, whereas Lava Mode provides a much tighter and proactive feedback loop.

Hardened JavaScript is a technology that allows for the isolation of each dependency within the same process. It prevents tampering with the JavaScript environment and is part of the technology behind Lava Mode.

Yes, Lava Mode can detect and reveal the behavior of obfuscated malware. It does this by prompting synchronously for everything the malware reaches for, making it unnecessary to deobfuscate the file.

Yes, the technologies behind Lava Mode, such as hardened JavaScript, are part of early-stage proposals that may eventually become part of the JavaScript language.

Zbyszek Tenerowicz
Zbyszek Tenerowicz
8 min
14 Apr, 2023

Comments

Sign in or register to post your comment.
Video Summary and Transcription
NPM packages can be potentially dangerous, so it's important to be proactive in managing them. Lava Mode allows you to detect and investigate suspicious packages before deploying your app. Lavamote prevents unauthorized access to sensitive resources by isolating dependencies and using hardened JavaScript. Lava Mode makes it easier to analyze obfuscated files and understand their actions.

1. The Importance of Proactive Package Management

Short description:

NPM packages are unsanitized inputs from the Internet that you run in your application. What if some of them are malicious and dangerous? Waiting for someone to find out is not ideal. With Lava Mode, you can be proactive instead of reactive. It allows you to detect suspicious packages and investigate them before shipping your app to production. Let me show you a demo.

♪♪ ♪♪ OK, I'm Zb. Now, Gector, it's in the corner and in the middle. OK, would you take a string I gave you and run it in your application? Like, that's code. Raise your hands if you would. No, really? OK, would it help if I put it in the tar.gz file? AUDIENCE LAUGHS Because that's what NPM packages are, and they're glorious, don't get me wrong, but they're also unsanitized inputs from the Internet that you run in your application.

Yeah, and we love them. I'm installing NPM packages all the time. Like, that's the main thing I do at work. But what if some of them are not great? And I don't mean lousy packages. I published a bunch of lousy packages, nothing bad happened, but actually malicious, dangerous packages, what then? Well, you can wait for someone to find out that the package is malicious, submit it somewhere and then NPM audit is gonna tell you a few weeks after you shipped your app to production with this package in your dependencies. That works already. You can go with socket dev, which has a much tighter feedback loop, but it just tells you that stuff is suspicious and you have to investigate. So do you have time to read your dependencies? I don't know. Ooh, I don't have a network connection. That's funny. Yeah, there was a logo here. Okay, but with Lava Mode, you can be proactive instead of reactive. And that's a great thing, being proactive instead of reactive. Let me see if I can refresh this now. Okay, I have a demo. I can show you what it does. This is a very brief version of the demo. Sorry, there's much more steps, but I have an app here that's using a package to get very valuable data and then it's sending it to a different server with some authorization that's coming from environment variables. Okay, if I run it, I have this localhost server running and it's gonna pop up the result. Okay, that's what it does. It gets stuff. So, what's the package doing? The package is getting this valuable information from somewhere and sending it over. Okay, now what if the maintainer got bored and handed over the package to someone else who had some bad intentions. Okay, so see, live coding, barely any typing. So, if they grab your precious secret and send elsewhere, what would happen? Well, they would get it.

2. Preventing Unauthorized Access with Lavamote

Short description:

Lavamote generates a policy to prevent unauthorized access to sensitive resources. By using hardened JavaScript and LockDown technology, Lavamote isolates each dependency within the same process, preventing tampering with the JavaScript environment. If you want to know more, I'm offering to help you set up a Lava MultiView project.

Okay, so the other server just got the secret, right? And the stuff still works. Okay, so what if we want to prevent it? That's where Lavamote comes in and Lavamote generates a policy for you which contains information like this package can access fetch and buffer for other versions of that package that I wanted to demo.

Okay, so with Lavamote, if I do, I have Lavamote wire as npm test. I'm gonna run it and it's gonna say this. It's slightly garbled but it says process did not exist. Process was undefined actually for this package only. So you can use process in the main app or other packages but this package doesn't have access to it.

Okay, so let's do some more hacking. Have you heard of prototype pollution? There was a chance to hear about it today. So if I take object prototype and I define a setter as authorization field on that and I pass authorization header to fetch, fetch is going to call my setter that I set on the global prototype. How funny. Okay, so this is still gonna work under regular node. Okay, and then with, yeah, I got the bearer and the secret. Okay, but if I run under Lava mode, I'm gonna get an error that says cannot define property authorization, object is not extensible. Lava mode is also using a technology behind the scenes called LockDown that locks down everything and it's impossible to tamper with the JavaScript environment itself.

Okay, going back here. So what's the magic? It's called hardened JavaScript. It lets you isolate, in our case, we're using it to isolate each dependency within the same process. There's no other context or realms involved in all of this. It has compartment, LockDown, hardened, yeah let's skip over that. It's becoming part of the language eventually. It's an early stage proposal right now, but coming from people who are responsible for stuff like Command JS, promise in the language, et cetera. If you want to know more, these links are available. And I'm offering to help you set up Lava MultiView project if you get in touch early enough. But I promised I'll evo all the strings, right? So I have one more demo that's, oh, I'm not over time yet. Cool. I made this thing, I used this technology to make this thing where I can run any code and get prompted synchronously for everything it reaches for. So I took actual malware from NPM. It's already removed but it was there. Yeah, let's run it.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Scaling Up with Remix and Micro Frontends
Remix Conf Europe 2022Remix Conf Europe 2022
23 min
Scaling Up with Remix and Micro Frontends
Top Content
This talk discusses the usage of Microfrontends in Remix and introduces the Tiny Frontend library. Kazoo, a used car buying platform, follows a domain-driven design approach and encountered issues with granular slicing. Tiny Frontend aims to solve the slicing problem and promotes type safety and compatibility of shared dependencies. The speaker demonstrates how Tiny Frontend works with server-side rendering and how Remix can consume and update components without redeploying the app. The talk also explores the usage of micro frontends and the future support for Webpack Module Federation in Remix.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
RemixConf EU discussed full stack components and their benefits, such as marrying the backend and UI in the same file. The talk demonstrated the implementation of a combo box with search functionality using Remix and the Downshift library. It also highlighted the ease of creating resource routes in Remix and the importance of code organization and maintainability in full stack components. The speaker expressed gratitude towards the audience and discussed the future of Remix, including its acquisition by Shopify and the potential for collaboration with Hydrogen.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
Watch video: Debugging JS
Debugging JavaScript is a crucial skill that is often overlooked in the industry. It is important to understand the problem, reproduce the issue, and identify the root cause. Having a variety of debugging tools and techniques, such as console methods and graphical debuggers, is beneficial. Replay is a time-traveling debugger for JavaScript that allows users to record and inspect bugs. It works with Redux, plain React, and even minified code with the help of source maps.
Making JavaScript on WebAssembly Fast
JSNation Live 2021JSNation Live 2021
29 min
Making JavaScript on WebAssembly Fast
Top Content
WebAssembly enables optimizing JavaScript performance for different environments by deploying the JavaScript engine as a portable WebAssembly module. By making JavaScript on WebAssembly fast, instances can be created for each request, reducing latency and security risks. Initialization and runtime phases can be improved with tools like Wiser and snapshotting, resulting in faster startup times. Optimizing JavaScript performance in WebAssembly can be achieved through techniques like ahead-of-time compilation and inline caching. WebAssembly usage is growing outside the web, offering benefits like isolation and portability. Build sizes and snapshotting in WebAssembly depend on the application, and more information can be found on the Mozilla Hacks website and Bike Reliance site.
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Node Congress 2022Node Congress 2022
26 min
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Top Content
The talk discusses the importance of supply chain security in the open source ecosystem, highlighting the risks of relying on open source code without proper code review. It explores the trend of supply chain attacks and the need for a new approach to detect and block malicious dependencies. The talk also introduces Socket, a tool that assesses the security of packages and provides automation and analysis to protect against malware and supply chain attacks. It emphasizes the need to prioritize security in software development and offers insights into potential solutions such as realms and Deno's command line flags.
Webpack in 5 Years?
JSNation 2022JSNation 2022
26 min
Webpack in 5 Years?
Top Content
In the last 10 years, Webpack has shaped the way we develop web applications by introducing code splitting, co-locating style sheets and assets with JavaScript modules, and enabling bundling for server-side processing. Webpack's flexibility and large plugin system have also contributed to innovation in the ecosystem. The initial configuration for Webpack can be overwhelming, but it is necessary due to the complexity of modern web applications. In larger scale applications, there are performance problems in Webpack due to issues with garbage collection, leveraging multiple CPUs, and architectural limitations. Fixing problems in Webpack has trade-offs, but a rewrite could optimize architecture and fix performance issues.

Workshops on related topic

Master JavaScript Patterns
JSNation 2024JSNation 2024
145 min
Master JavaScript Patterns
Top Content
Featured Workshop
Adrian Hajdin
Adrian Hajdin
During this workshop, participants will review the essential JavaScript patterns that every developer should know. Through hands-on exercises, real-world examples, and interactive discussions, attendees will deepen their understanding of best practices for organizing code, solving common challenges, and designing scalable architectures. By the end of the workshop, participants will gain newfound confidence in their ability to write high-quality JavaScript code that stands the test of time.
Points Covered:
1. Introduction to JavaScript Patterns2. Foundational Patterns3. Object Creation Patterns4. Behavioral Patterns5. Architectural Patterns6. Hands-On Exercises and Case Studies
How It Will Help Developers:
- Gain a deep understanding of JavaScript patterns and their applications in real-world scenarios- Learn best practices for organizing code, solving common challenges, and designing scalable architectures- Enhance problem-solving skills and code readability- Improve collaboration and communication within development teams- Accelerate career growth and opportunities for advancement in the software industry
Integrating LangChain with JavaScript for Web Developers
React Summit 2024React Summit 2024
92 min
Integrating LangChain with JavaScript for Web Developers
Featured Workshop
Vivek Nayyar
Vivek Nayyar
Dive into the world of AI with our interactive workshop designed specifically for web developers. "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" offers a unique opportunity to bridge the gap between AI and web development. Despite the prominence of Python in AI development, the vast potential of JavaScript remains largely untapped. This workshop aims to change that.Throughout this hands-on session, participants will learn how to leverage LangChain—a tool designed to make large language models more accessible and useful—to build dynamic AI agents directly within JavaScript environments. This approach opens up new possibilities for enhancing web applications with intelligent features, from automated customer support to content generation and beyond.We'll start with the basics of LangChain and AI models, ensuring a solid foundation even for those new to AI. From there, we'll dive into practical exercises that demonstrate how to integrate these technologies into real-world JavaScript projects. Participants will work through examples, facing and overcoming the challenges of making AI work seamlessly on the web.This workshop is more than just a learning experience; it's a chance to be at the forefront of an emerging field. By the end, attendees will not only have gained valuable skills but also created AI-enhanced features they can take back to their projects or workplaces.Whether you're a seasoned web developer curious about AI or looking to expand your skillset into new and exciting areas, "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" is your gateway to the future of web development. Join us to unlock the potential of AI in your web projects, making them smarter, more interactive, and more engaging for users.
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
React Day Berlin 2022React Day Berlin 2022
86 min
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
Top Content
WorkshopFree
Hussien Khayoon
Kahvi Patel
2 authors
Using a library might seem easy at first glance, but how do you choose the right library? How do you upgrade an existing one? And how do you wade through the documentation to find what you want?
In this workshop, we’ll discuss all these finer points while going through a general example of building a code editor using CodeMirror in React. All while sharing some of the nuances our team learned about using this library and some problems we encountered.
Testing Web Applications Using Cypress
TestJS Summit - January, 2021TestJS Summit - January, 2021
173 min
Testing Web Applications Using Cypress
WorkshopFree
Gleb Bahmutov
Gleb Bahmutov
This workshop will teach you the basics of writing useful end-to-end tests using Cypress Test Runner.
We will cover writing tests, covering every application feature, structuring tests, intercepting network requests, and setting up the backend data.
Anyone who knows JavaScript programming language and has NPM installed would be able to follow along.
React Server Components Unleashed: A Deep Dive into Next-Gen Web Development
React Day Berlin 2023React Day Berlin 2023
149 min
React Server Components Unleashed: A Deep Dive into Next-Gen Web Development
Workshop
Maurice de Beijer
Maurice de Beijer
Get ready to supercharge your web development skills with React Server Components! In this immersive, 3-hour workshop, we'll unlock the full potential of this revolutionary technology and explore how it's transforming the way developers build lightning-fast, efficient web applications.
Join us as we delve into the exciting world of React Server Components, which seamlessly blend server-side rendering with client-side interactivity for unparalleled performance and user experience. You'll gain hands-on experience through practical exercises, real-world examples, and expert guidance on how to harness the power of Server Components in your own projects.
Throughout the workshop, we'll cover essential topics, including:- Understanding the differences between Server and Client Components- Implementing Server Components to optimize data fetching and reduce JavaScript bundle size- Integrating Server and Client Components for a seamless user experience- Strategies for effectively passing data between components and managing state- Tips and best practices for maximizing the performance benefits of React Server Components
0 to Auth in an hour with ReactJS
React Summit 2023React Summit 2023
56 min
0 to Auth in an hour with ReactJS
WorkshopFree
Kevin Gao
Kevin Gao
Passwordless authentication may seem complex, but it is simple to add it to any app using the right tool. There are multiple alternatives that are much better than passwords to identify and authenticate your users - including SSO, SAML, OAuth, Magic Links, One-Time Passwords, and Authenticator Apps.
While addressing security aspects and avoiding common pitfalls, we will enhance a full-stack JS application (Node.js backend + React frontend) to authenticate users with OAuth (social login) and One Time Passwords (email), including:- User authentication - Managing user interactions, returning session / refresh JWTs- Session management and validation - Storing the session securely for subsequent client requests, validating / refreshing sessions- Basic Authorization - extracting and validating claims from the session token JWT and handling authorization in backend flows
At the end of the workshop, we will also touch other approaches of authentication implementation with Descope - using frontend or backend SDKs.