Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Thrive Market’s Amina Pasha believes brands that focus on trust will win in an AI-first world

    WTF are tokens?

    Pacific Drive developer Ironwood Studios raises $4m in seed funding round

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      Read the extended transcript: President Donald Trump interviewed by ‘NBC Nightly News’ anchor Tom Llamas

      February 6, 2026

      Stocks and bitcoin sink as investors dump software company shares

      February 4, 2026

      AI, crypto and Trump super PACs stash millions to spend on the midterms

      February 2, 2026

      To avoid accusations of AI cheating, college students are turning to AI

      January 29, 2026

      ChatGPT can embrace authoritarian ideas after just one prompt, researchers say

      January 24, 2026
    • Business

      The HDD brand that brought you the 1.8-inch, 2.5-inch, and 3.5-inch hard drives is now back with a $19 pocket-sized personal cloud for your smartphones

      February 12, 2026

      New VoidLink malware framework targets Linux cloud servers

      January 14, 2026

      Nvidia Rubin’s rack-scale encryption signals a turning point for enterprise AI security

      January 13, 2026

      How KPMG is redefining the future of SAP consulting on a global scale

      January 10, 2026

      Top 10 cloud computing stories of 2025

      December 22, 2025
    • Crypto

      Pi Network Tops Daily Charts with a 25% Rally, Here’s Why

      February 15, 2026

      Solana New Holders Drop by 2.3 Million, Will It Impact Price Recovery?

      February 15, 2026

      CLARITY Act’s Stablecoin Yield Restrictions Could Benefit Foreign Currencies, Not USD

      February 15, 2026

      Bitcoin Shorts Reach Most Extreme Level Since 2024 Bottom

      February 15, 2026

      Coinbase Urges Fed to Modernize US Payments to Match European Standards

      February 15, 2026
    • Technology

      Thrive Market’s Amina Pasha believes brands that focus on trust will win in an AI-first world

      February 15, 2026

      WTF are tokens?

      February 15, 2026

      Lack of resources greatest hurdle for regulating AI, MPs told

      February 15, 2026

      Fujitsu will be out by next summer, says Post Office CTO

      February 15, 2026

      AI enters its ‘grassroots backlash’ era

      February 15, 2026
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Check BMI
    Tech AI Verse
    You are at:Home»Technology»Show HN: Regolith – Regex library that prevents ReDoS CVEs in TypeScript
    Technology

    Show HN: Regolith – Regex library that prevents ReDoS CVEs in TypeScript

    TechAiVerseBy TechAiVerseAugust 27, 2025No Comments11 Mins Read3 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Show HN: Regolith – Regex library that prevents ReDoS CVEs in TypeScript
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    Show HN: Regolith – Regex library that prevents ReDoS CVEs in TypeScript

    Regolith

    A server-side TypeScript and JavaScript library immune to Regular Expression Denial of Service (ReDoS) attacks by using Rust and linear Regex under the hood. Regolith has a linear worst case time complexity, compared to the default RegExp found in TypeScript and JavaScript, which has an exponential worst case.






    Motivation: I wanted a Regex library for TypeScript and JavaScript where I didn’t have to worry about ReDoS attacks.

    Important

    Regolith is still early in development! We need help building and getting developer adoption!

    Drop-in Replacement

    Regolith attempts to be a drop-in replacement for RegExp and requires minimal (to no) changes to be used instead. The goal of Regolith is to allow developers to easily build software that is immune to ReDoS attacks.

    Preventing ReDoS Attacks

    What are ReDoS attacks?

    Regular Expression Denial of Service (ReDoS) attacks occur when vulnerable Regex patterns are executed with specifically constructed inputs that result in an inefficient execution. This can be exploited to cause services to become unavailable because the services are stuck trying to compute the inefficient Regex.

    Read more: owasp.org & learn.snyk.io

    Exponential Worst Case

    Python has an exponential increase in execution time for the worst case.

    This is the same case for TypeScript and JavaScript. Both having RegExp, which has an exponential worst case.

    Linear vs Exponential Regex Libraries

    This table shows popular languages and if their Regex library has a linear worst case or an exponential worst case. It also includes experimental results for how long execution took for a vulnerable Regex pattern that can be attacked with ReDoS and an input of size 30.

    Note that TypeScript and JavaScript do not have a linear worst case for Regex, making them vulnerable to these types of attacks.

    More information and images: Jake Roggenbuck – Preventing ReDoS Attacks – 2025

    Impact

    Note

    ReDoS attacks happen relatively frequently to popular libraries costing millions of hours of work. This can be prevented with linear regex engines like Regolith.

    These vulnerabilities happen relatively often in popular libraries. It’s no one’s fault specifically, it just comes down to the fact that the language allows for these things to happen.

    A recent example of a ReDoS vulnerability is CVE-2025-5889 from brace-expansion. Again, this isn’t any fault of that project, it’s simply an issue with the language allowing this to happen. Measures can be put into place to reduce the risk of this, but it’s hard to spot and test for these issues.

    The brace-expansion project is used by 42.5 million other projects on GitHub. Meaning if everyone were to patch their software (which the hopefully will), that would be 42.5 million pull requests, roughly 42.5 million build minutes, and probably more than 42 million engineering minutes as well. All of that for a single vulnerability, and that’s just a lower bound of effort spent on this if everyone were to keep their software patched.

    Other versions of brace-expansion had these patches backported to them, needing updates for versions 1, 2, 3, and the current version 4.

    Having a library or project that is immune to these vulnerabilities would save this effort for each project that adopted it, and would save the whole package ecosystem that effort if widely adopted. Adoption of libraries is difficult, especially when they aren’t very flashy, but helping library maintainers and engineers not worry about ReDoS for one library, one project at a time, is our goal.

    Trade-off

    The Rust Regex library purposefully excludes features that make Regex engines particularly vulnerable to ReDoS attacks. Those features are backreferences and look-around. Excluding those features allow Regex to guarantee linear time execution.

    Since Regolith uses Rust bindings to implement the Rust Regex library to achieve linear time worst case, this means that backreferences and look-around aren’t available in Regolith either.

    This trade-off has proven to be worth it for the Rust community of libraries and projects.

    Results

    Since ReDoS vulnerabilities are hard to spot, there are rather frequent CVEs that get submitted. Having a Regex library that has a linear worst case time would completely prevent all of these potential issues for downstream projects.

    Rust Regex under the hood

    Regolith makes JavaScript bindings (using napi-rs) that implement the features of the very popular Regex library for Rust. Initially, when I had this idea for this library, I wanted to implement my own linear time regex engine. Now there is a chance I still end up doing that, I realized it’s better to not duplicate the work of the already excellent Regex library and focus on making these JavaScript and TypeScript bindings the best they can be. The focus of this project is to deliver the best linear time regex engine to TypeScript and JavaScript as a drop-in replacement for the default RegExp.

    My full appreciation goes out to the developers of the Rust Regex library, who enabled this project to exist.

    Limitations

    I’m still working to get this to be able to link to client side run applications like when you use react with “use client”. This may result in either finding a new way to link Rust (possible with WASM) or making my own Regex engine. Currently, everything works for server side JavaScript and TypeScript, which is the main focus of this, because servers are what usually get attacked in ReDoS attacks instead of clients.

    You might get a message link: No loader is configured for ".node" files: node_modules/@regolithjs/regolith-linux-x64-gnu/regolith.linux-x64-gnu.node.

    I will actively be working to add this functionality and it will be tracked as issue #40. For now, I recommend using Regolith for server side and systems applications to prevent ReDoS attacks for servers, as this is what commonly gets Denial of Service attacks.

    Usage (Quick Start)

    1. Install

    npm i @regolithjs/regolith
    

    2. Try it out

    import { Regolith } from '@regolithjs/regolith';
    
    const pattern = new Regolith("^\d+$");
    
    pattern.test("12345");  // true
    pattern.test("Hello");  // false

    Examples

    Simple pattern matching example to match crab in our sentence my crab ferris.

    import { Regolith } from '@regolithjs/regolith';
    
    const pattern = new Regolith('crab', 'g');
    console.log(pattern.test('my crab ferris')); // true

    Here we use ‘g’ in the Regolith constructor to mean a global.

    Match method

    const sentence = 'crab, snail, crab';
    const crabPattern = new Regolith('crab', 'g');
    
    // Find all matches
    console.log(crabPattern.match(sentence));
    // Output: ['crab', 'crab']

    Replace method

    const sentence = 'crab, snail, crab';
    const crabPattern = new Regolith('crab', 'g');
    
    // Replace all occurrences
    console.log(crabPattern.replace(sentence, 'snake'));
    // Output: 'snake, snail, snake'

    Search method

    const sentence = 'crab, snail, crab';
    
    const snailPattern = new Regolith('snail');
    console.log(snailPattern.search(sentence));
    // Output: 6 (index where 'snail' is found)

    Split method

    const splitPattern = new Regolith('[,\|]');
    console.log(splitPattern.split('apple,banana|orange'));
    // Output: ['apple', 'banana', 'orange']

    Express Example

    Make a backend express app that will tell you if a number is an int or a float. View the complete guide for the Express example.

    {
    const value = req.query.value;

    if (!value) {
    return res.status(400).send(“Please provide a value query parameter”);
    }

    // Run the test with Regolith pattern
    const isInt = intPattern.test(value);
    const isFloat = floatPattern.test(value);

    res.json({
    value,
    isInt,
    isFloat,
    });
    });

    app.listen(port, () => {
    console.log(`Example app listening on port ${port}`);
    });”>

    import express from "express";
    import { Regolith } from "@regolithjs/regolith";
    
    const app = express();
    const port = 3000;
    
    // Create Regolith Regex patterns
    const intPattern = new Regolith("^\d+$");
    const floatPattern = new Regolith("^\d*\.\d+$");
    
    app.get("/check", (req, res) => {
        const value = req.query.value;
    
        if (!value) {
            return res.status(400).send("Please provide a value query parameter");
        }
    
        // Run the test with Regolith pattern
        const isInt = intPattern.test(value);
        const isFloat = floatPattern.test(value);
    
        res.json({
            value,
            isInt,
            isFloat,
        });
    });
    
    app.listen(port, () => {
        console.log(`Example app listening on port ${port}`);
    });

    Development

    These are instructions only if you want to build this library yourself (e.g. for development).

    Building

    1. Before you build, you will need to have yarn installed. Here is a guide for installing yarn.
    2. You will also need Rust, and you can install Rust with rustup.

    To build the project, use this command:

    Running yarn build will build the Rust package, and you should see the Rust compiler complete the build process.

    Running

    Now we can test to see if Regolith was built correctly. We can open the node REPL and load the library.

    After opening the shell, you can load the library with:

    const { Regolith } = await import("./index.js");

    After that, you can use Regolith as normal.

    const integerPattern = new Regolith("^\d+$");
    integerPattern.test("123");

    Here is an example of running Regolith in the REPL to test if it built correctly.

    Testing

    Testing the TS/JS library

    You should see the tests complete. Currently, there are 93 tests that get run.

    These tests can be found in the __test__ directory.

    Testing the Rust bindings

    Here is what the output should look like:

    These tests can be found in the source files in src/lib.rs.

    Publishing Checklist

    1. Increment the version in package.json
    2. All changes are merged into main
    3. Run the tests with yarn test
    4. Run npm login
    5. Run npm publish

    Docs

    1. Important Files

    name purpose docs
    build.rs Runs the setup for napi-rs
    Cargo.lock Automatically generated by Cargo to keep track of Rust package versions
    Cargo.toml Contains information about the Rust crate; like the name, version, and dependencies
    index.d.ts Type information automatically generated by napi-rs
    index.js The main entry point for the library that is automatically generated by napi-rs
    package.json Information about the Regolith package
    rustfmt.toml A config for the Rust formatter
    yarn.lock Keeps track of the dependency version for yarn and it is automatically generated
    .npmignore Keeps files and directories out of what is shipped in the library Link
    .yarnrc.yml Configure yarn settings

    2. Formatting

    2.1 Rust Format

    Use cargo fmt. This is actually checked in the automated tests when you create a pull request. You can also see rustfmt.toml for the config for cargo fmt.

    2.2 TypeScript / JavaScript Format

    Use prettier with prettier --write or prettier --write . to format all .ts and .js files.

    3. Website

    The source code for the Regolith website can be found at github.com/JakeRoggenbuck/regolith-website. The URL for the website is regolithjs.com.

    4. Platforms Tested

    These are the platforms that Regolith has been tested on. These checks happen automatically in the CI.

    Platform Status
    Arm 64 Apple Darwin Working
    Arm 64 Linux Android Working
    Arm 64 Linux GNU Working
    Arm 64 Linux MUSL Working
    Arm 64 PC Windows MSVC Working
    Arm v7 Linux GNU Working
    Arm v7 Linux MUSL Working
    x86-64 Linux MUSL Working
    x86-64 FreeBSD Not Tested
    i686 PC Windows MSVC Working
    Arm v7 Linux Andriod Working
    Universal Apple Darwin Working
    RISC-V 64 GC Linux GNU Working

    Report a Bug

    If you find a bug, please send me an email at bug at jr0 dot org and or open an issue.

    Name Origin

    When trying to think of words that started with reg, I thought of the word regolith, which describes top layer of a planet that’s made of dust and rock. I likely got familiar with this word in a class I took about dinosaurs.

    Motivation and Background

    I was initially inspired to build this library after doing undergraduate research to learn more about why certain languages have problems with ReDoS and others don’t. This led me to a question I couldn’t answer: “Why isn’t the most popular Regex library a linear time engine for languages like TypeScript, JavaScript, and Python?” You’d think that having a library that cannot get attacked (in a common way software gets attacked) would be more commonly used. I found an example called regexy in Python, but there hasn’t been an update in 8 years, and it was archived in 2024. There is also rure-python but this has not been updated in 6 years either. JavaScript has some more popular libraries that address this issue too. One is called re2js, which wraps Google’s RE2 library written in C++. re2js has a different API as the default RegExp from JavaScript, requiring some reworking on code that needs to be migrated over. The other is called node-re2, and this library also provides bindings for Google’s RE2 library. node-re2 does have an API similar to JavaScript’s RegExp. Even with these libraries, anecdotally it feels like the vast majority of projects still use the default regex for their respective languages; libraries that are vulnerable to ReDoS attacks. I could not find an exact percentage for how many projects use linear time engines vs exponential engines so this should be something to either find out from literature or maybe even try to answer this question directly, by reviewing packages published and trying to calculate a percentage.

    Ultimately, I wanted a Regex library that is a drop-in replacement for RegExp in TypeScript and JavaScript where I didn’t have to worry about ReDoS attacks. My hope is that this library brings value to your software as well.

    Future Work

    I plan to continue working on Regex libraries that mitigate ReDoS attacks for languages that don’t yet have linear time engines. A great next step would be to have a library that isn’t platform dependent and I may implement my own regex engine for this. Another possibility may be to use Web Assembly to run Rust inside the browser without being platform dependent.

    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticleDissecting the Apple M1 GPU, the end
    Next Article Gemini Nano Banana improves image editing consistency and control at scale for enterprises – but is not perfect
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    Thrive Market’s Amina Pasha believes brands that focus on trust will win in an AI-first world

    February 15, 2026

    WTF are tokens?

    February 15, 2026

    Lack of resources greatest hurdle for regulating AI, MPs told

    February 15, 2026
    Leave A Reply Cancel Reply

    Top Posts

    Ping, You’ve Got Whale: AI detection system alerts ships of whales in their path

    April 22, 2025676 Views

    Lumo vs. Duck AI: Which AI is Better for Your Privacy?

    July 31, 2025260 Views

    6.7 Cummins Lifter Failure: What Years Are Affected (And Possible Fixes)

    April 14, 2025153 Views

    6 Best MagSafe Phone Grips (2025), Tested and Reviewed

    April 6, 2025112 Views
    Don't Miss
    Technology February 15, 2026

    Thrive Market’s Amina Pasha believes brands that focus on trust will win in an AI-first world

    Thrive Market’s Amina Pasha believes brands that focus on trust will win in an AI-first…

    WTF are tokens?

    Pacific Drive developer Ironwood Studios raises $4m in seed funding round

    Mattel to acquire full ownership of Mattel163 from NetEase

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    Thrive Market’s Amina Pasha believes brands that focus on trust will win in an AI-first world

    February 15, 20262 Views

    WTF are tokens?

    February 15, 20261 Views

    Pacific Drive developer Ironwood Studios raises $4m in seed funding round

    February 15, 20262 Views
    Most Popular

    7 Best Kids Bikes (2025): Mountain, Balance, Pedal, Coaster

    March 13, 20250 Views

    VTOMAN FlashSpeed 1500: Plenty Of Power For All Your Gear

    March 13, 20250 Views

    This new Roomba finally solves the big problem I have with robot vacuums

    March 13, 20250 Views
    © 2026 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.