Giter Site home page Giter Site logo

Potential Security Vulnerability about escodegen HOT 9 OPEN

jcubic avatar jcubic commented on June 10, 2024
Potential Security Vulnerability

from escodegen.

Comments (9)

jcubic avatar jcubic commented on June 10, 2024 1

I've reported the vulnerability to Snyk that can also assign CVE numbers.

from escodegen.

jsoref avatar jsoref commented on June 10, 2024

GitHub only accept[s] security advisories from the repo maintainers themselves, but you can file for a CVE which [they] will pick up on after publication.
https://www.cve.org/ResourcesSupport/ReportRequest

from escodegen.

jsoref avatar jsoref commented on June 10, 2024

That said, if this is a documented feature, please think through what you're proposing.

There's a library we use which supports a thing like this and it's documented as such, we're now stuck explaining that it's totally reasonable for a library to have a function that allows executing code and it's up to consumers to be intelligent about whether or not they allow users (or attackers) to send content to such functions.

from escodegen.

jcubic avatar jcubic commented on June 10, 2024

@jsoref This is not a documentation issue. This can have potential security implications for people that use the library. Since if they don't know about this it can lead to vulnerability.

And as for AST, this is broken AST, you should not be allowed to put JavaScript code as a string in any way. raw is one place where this is problematic but the library should handle this.

In my library, I've had a similar issue, and I've marked the version as vulnerable because the user could not know that he need to sanitize the input before processing it by the library. And this is not a documentation issue, in my library I've disabled the feature that enabled the same thing by the attacker and now I have a section about security that to enable one feature the user needs to sanitize his input.

from escodegen.

jcubic avatar jcubic commented on June 10, 2024

And about applying for CVE, I once wanted to report CVE and it was a complex process, that's why it's great that GitHub help with creating one. My last vulnerability in my own library I needed to report to NPM and because there was no CVE often I didn't get credit as the person that found it.

from escodegen.

jcubic avatar jcubic commented on June 10, 2024

That said, if this is a documented feature, please think through what you're proposing.

So you don't know if this is documented or not? I've never found documentation that explains this. Also, this project has no documentation for AST. It doesn't even say what AST it is, I personally use Esprima syntax, which is never mentioned in the project.

from escodegen.

jsoref avatar jsoref commented on June 10, 2024

I'm not affiliated with any of this. I ran across your help request on github.community.

The repository README clearly says

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"

The code seems to be quite related to esprima, https://github.com/estools/escodegen/search?q=esprima

Offhand, it feels like https://docs.esprima.org/en/3.1/syntax-tree-format.html is "documentation" for the tree format.

Anyway, based on what I see, minus the lack of documentation, the raw appears to be a way to raw include things. If you want something else, it feels like this isn't what you want to use.

(it doesn't look like a <pre> html tag.)

from escodegen.

jcubic avatar jcubic commented on June 10, 2024

AFIK Every open-source license is provided as is without any warranties.

And raw is the only way to use template literals. It seems it's documented:

https://docs.esprima.org/en/3.1/syntax-tree-format.html#tagged-template-expression

I usually just use Esprima to generate AST for the code I need, and then put that AST into my code to get the JavaScript. Template literals have only "raw" and "cooked" properties, but "cooked" doesn't work, so only raw can be used. But raw is not as is, this part of the string between expressions. So if you have:

`foo ${bar} baz`

You have 3 Nodes, first and third have property "raw": "foo ", and "raw": " baz".

You can see the output AST using AST Explorer.

from escodegen.

jcubic avatar jcubic commented on June 10, 2024

If anyone is interested you only need to escape the string before you pass to escodegen.

function escape_quote(str) {
   return str.replace(/\$\{/g, '\\${');
}

from escodegen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.