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

Detect usage of dynamic RegExps #42

Open
fraxken opened this issue Jul 18, 2022 · 5 comments
Open

Detect usage of dynamic RegExps #42

fraxken opened this issue Jul 18, 2022 · 5 comments
Assignees

Comments

@fraxken
Copy link
Member

fraxken commented Jul 18, 2022

There is currently a lot of situations where we are missing dynamic RegExps. Ref and examples here: nodejs/security-wg#208

We should probably use the new Tracer to detect those cases (extension, proxy ...).

@fraxken fraxken self-assigned this Jan 3, 2023
@fraxken
Copy link
Member Author

fraxken commented Jan 3, 2023

One major issue if the fact that we analyze files one by one. It make the tracing of Proxies (and similar) impossible.

@jean-michelet
Copy link
Contributor

One major issue if the fact that we analyze files one by one. It make the tracing of Proxies (and similar) impossible.

Can we create an Env class, do an initial traversal of the program's entire AST, storing all the things we should be aware of, and exploit it during analysis?

@fraxken
Copy link
Member Author

fraxken commented Feb 7, 2024

Can we create an Env class, do an initial traversal of the program's entire AST, storing all the things we should be aware of, and exploit it during analysis?

No on multiple files it will cost an insane amount of memory. The only viable solution is to think "multiple iterations"

  • First iteration to walk, generate tree and report suspect nodes
  • Second iteration: look for suspect nodes

Kind of..

@fraxken
Copy link
Member Author

fraxken commented May 15, 2024

Ok to be able to start solving this issue, let's begin with a probe that work in a single file

class MyRegExp extends RegExp {
    constructor(...args) {
        super(...args);
    }
}

const d = new MyRegExp('^node_modules\\/(@[^/]+\\/?[^/]+|[^/]+)(\\/.*)?$');

This code should detect one warning of kind unsafe-regex. We will work to support the Proxy pattern later.

@jean-michelet
Copy link
Contributor

OK, looking into it.

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

2 participants