-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Code injection vulnerability in visitMixin and visitMixinBlock through "pretty" option #3312
Comments
I will release a fix as soon as possible. If you find any security vulnerabilities in the future, please follow the policy to report them: https://github.com/pugjs/pug/blob/master/SECURITY.md Posting security vulnerabilities in public issue trackers can lead to very serious real world harm. Please do not do it. |
Thank you. And sorry I didn't notice the policy file. This mistake won't happen again. |
In response to github dependabot alert concerning pugjs/pug#3312. ssptool was not susceptible but it's a good idea to upgrade anyway. No incompatibilities found.
Fixes Pug vulnerability pugjs/pug#3312
To fix pugjs/pug#3312 Old original `pug-cli` depends on `[email protected]`. `@anduh/pug-cli` is the fork to fix this problem. ref. pugjs/pug-cli#88 (comment)
Hello,
I found that pug may allow an attacker to inject arbitrary javascript code if an attacker can control
options.pretty
.Pug Version: 3.0.0
Proof of concept
Here is an vulnerable example including 2 files: app.js and index.pug.
In the example, there is only one variable "pretty" that is controlled by user, and the variable is not used in any dangerous functions.
app.js
views/index.pug
But if we visit URL below, it would lead to execute OS command "whoami".
Detail
This section will point the location of vulnerability and explain why I assume it's an issue.
First of all, when Compiler object is initialized,
options.pretty
would be saved inthis.pp
.pug/packages/pug-code-gen/index.js
Lines 50 to 56 in 06baa52
The
visitMixinBlock
function is simple,this.pp
is pushed intothis.buf
array which stores the compiled code of template without any sanitization.visitMixinBlock:
pug/packages/pug-code-gen/index.js
Lines 452 to 459 in 06baa52
The
visitMixin
is basically same asvisitMixinBlock
,this.pp
is pushed without any sanitization at line 507.visitMixin:
pug/packages/pug-code-gen/index.js
Lines 487 to 508 in 06baa52
If we look at how other functions handle options variables, we can see that they are all sanitized by stringify.
( this.prettyIndent is implemented with this.buffer, and this.buffer always sanitizes variable with stringify. )
with
this.prettyIndent
:pug/packages/pug-code-gen/index.js
Line 427 in 06baa52
with
this.buffer
:pug/packages/pug-code-gen/index.js
Line 475 in 06baa52
with
stringify
:pug/packages/pug-code-gen/index.js
Line 148 in 06baa52
The visitMixin and visitMixinBlock are the only two functions I found that are missing sanitization.
I think it may be an issue.
The text was updated successfully, but these errors were encountered: