Skip to content

Maintenance: Regular expression to get code location in logger may take more time to make some inputs #4366

@sdangol

Description

@sdangol

Summary

The regular expression used in getCodeLocation may run slow on strings starting with '(' and with many repetitions of '(('. So, we need to prevent this behaviour by modifying the regular expression

Why is this needed?

Some regular expressions take a long time to match certain input strings to the point where the time it takes to match a string of length n is proportional to nk or even 2n. Such regular expressions can negatively affect performance, or even allow a malicious user to perform a Denial of Service ("DoS") attack by crafting an expensive input string for the regular expression to match.

Which area does this relate to?

Logger

Solution

Updating the regular expression (adding an additional ( to the first capture group) to the following might prevent such catastrophic backtracking:

From:

const regex = /\(([^)]*?):(\d+?):(\d+?)\)\\?$/;

To:

const regex = /\(([^()]*?):(\d+?):(\d+?)\)\\?$/;

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    internalPRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.)loggerThis item relates to the Logger UtilityresearchingThis item is currently under consideration and we'll update once we have more info

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions