Skip to content

Bug: [DebugBar] regex vulnerable to super-linear runtime due to backtracking #7324

Description

@fliodhais

PHP Version

7.4

CodeIgniter4 Version

4.1.1

CodeIgniter4 Installation Method

Manual (zip or tar.gz)

Which operating systems have you tested for this bug?

Windows, Linux

Which server did you use?

apache

Database

No response

What happened?

Was scanning my project with data analysis tool, Sonarcloud and it highlighted that system/Debug/Toolbar/Views/toolbar.js ln631 "The regex used here is vulnerable to super-linear runtime due to backtracking. It can lead to denial of service."

ln631

var patt   = /\((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\)/;

// recommended solutio

Steps to Reproduce

system/Debug/Toolbar/Views/toolbar.js ln615

Expected Output

ln631

var patt   = /\((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\)/;

// recommended solution
var patt   = /\((?>(?:[^)(]+|\((?>(?:[^)(]+|\([^)(]*\))*+)\))*+)\)/;

Anything else?

I am not sure how to test if the regex actually will prevent backtracking or not. Supposedly the inputs prior are sanitized to prevent backtracking but it would still be good practice to have a secure regex I would imagine.

I will have a PR with the change but I am not sure how to prove that it works.

Edit: line where the regex is found.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions