Skip to content

Missing anchors in validation regular expression #241

@nharraud

Description

@nharraud

Hi,
The ReDos example uses two regular expressions which are missing start and end anchors:

// const regexPattern = /([0-9]+)\#/;
const regexPattern = /([0-9]+)+\#/;

These regular expressions accept values such as evil123#evil.

How about:
1/ fixing these two regular expressions like this:

        // const regexPattern = /^[0-9]+\#$/;
        const regexPattern = /^([0-9]+)+\#$/;

2/ adding another regular expression somewhere which creates a vulnerability due to the missing anchors. This would be a good opportunity to explain CWE-777: Regular Expression without Anchors, which is quite easy to miss in Javascript.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions