-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Security: gray-matter exposes front matter JS-engine that leads to arbitrary code execution #99
Comments
Thanks for the info. I wasn't aware of this feature in gray-matter.
I think you shouldn't use a tool like this on markdown content that you don't control, especially not without any security concerns (i. e. never trust user input), but yeah I agree that it might prevent some accidental security problems if the JS engine was disabled. |
I just checked the docs and it's also possible to set |
The documentation seems to be a bit misleading and Agree, an opt-in config option for which engines to use makes sense and sounds like the right way to solve this. |
BTW I saw in your Github activity that you also raised an issue with dillinger.io which is using this package, and I'm actually able to use this exploit there, e. g. I would add a front matter like
and then use export > PDF. I'm not sure about the damage that can be done here but one idea would be to try and send myself all file exports that are happening in the hopes that someone uses dillinger.io for secret/internal data. FYI @joemccann, I'll see that I get a new major version out that disables this feature by default, and make a PR to your repo to update the package. |
Yes, you're right - I was reviewing dillinger and that's how I found this library. :) |
Released version 5.0.0 with a fix for this, i. e. the JS engine throws an error about being disabled by default, and you can overwrite the gray-matter options with |
The library gray-matter (used by md-to-pdf to parse front matter) exposes a JS-engine by default, which essentially runs eval on the given Markdown.
https://github.com/simonhaenisch/md-to-pdf/blob/master/src/lib/md-to-pdf.ts#L26
Given that md-to-pdf is only a Markdown to PDF-library and looking at how other projects use it - I think it is an undesirable feature to be able to execute any arbitrary Javascript by anyone in control of the Markdown content.
A possible fix would be to override gray-matter's JS-engine:
PoC:
poc.js:
The text was updated successfully, but these errors were encountered: