Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential Regular Expression Denial of Service (ReDoS) in valid-var-jsdoc #362

Open
yetingli opened this issue Oct 8, 2020 · 1 comment

Comments

@yetingli
Copy link

yetingli commented Oct 8, 2020

Type of Issue
Potential Regular Expression Denial of Service (ReDoS)

Description
The vulnerable regular expressions are located in

var CONST_PATTERN = /^[A-Z]([A-Z\d$]+_?)*[A-Z\d$]$/;

var PASCAL_PATTERN = /^([A-Z][a-zA-Z\d$]+)+$/;

The ReDOS vulnerabilities can be exploited with the following string
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_

You can execute the following code to reproduce ReDos

var rule = require('../../../../lib/js/rules/valid-var-jsdoc');
var RuleTester = require('eslint').RuleTester;

var ruleTester = new RuleTester({parser: 'babel-eslint'});

ruleTester.run('valid-var-jsdoc', rule, {
    invalid: [
        'var AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_ = 1;',
        'const AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_ = 1;',
    ],
});

I think you can limit the input length or modify this regex.

@yetingli
Copy link
Author

yetingli commented Oct 8, 2020

Hi,
For the CONST_PATTERN, I am willing to suggest that you replace /^[A-Z]([A-Z\d$]+_?)*[A-Z\d$]$/ with /^[A-Z]([A-Z\d$]_?)*[A-Z\d$]$/

For the PASCAL_PATTERN, you can replace /^([A-Z][a-zA-Z\d$]+)+$/ with /^([A-Z][a-zA-Z\d$]+)$/

These are equivalent fixes and the fixed regexes are safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant