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

Fix dynamic code execution in safe mode #367

Closed
wants to merge 2 commits into from

Conversation

patryk4815
Copy link

Hi. I found a "Function" workaround and now in safe mode we can execute dynamic code like as "eval".
I think it is security vuln and need CVE?

Function("){return 1337})//", "return this")();

BTW Why function arguments are not sanitized? It just concatenate string.

@drsm
Copy link
Contributor

drsm commented Feb 1, 2021

@patryk4815

nice catch!

but unlikely exploitable, 'cause in order to do this, the stuff before the function body should came from non-trusted source.

there is only an ability to forge an intentionally malicious configuration that bypass a code execution restriction.

@drsm
Copy link
Contributor

drsm commented Feb 1, 2021

BTW, it would be nice to document that in "non-safe" mode it's up to the caller to sanitize inputs.

@xeioex
Copy link
Contributor

xeioex commented Feb 1, 2021

Hi @patryk4815,

Thanks for the patch, will be committed.

I think it is security vuln and need CVE?

This is bug but not a security vulnerability, because in njs threat model the code is a part of nginx configuration, and the configuration is expected to be a trusted source (it also contains certificates, for example).

@xeioex
Copy link
Contributor

xeioex commented Feb 1, 2021

@patryk4815

BTW Why function arguments are not sanitized? It just concatenate string.

Mostly because dynamic execution methods like eval() and Function() are not expected to be used in njs at all.
Their support is limited, and was added to increase test262 coverage of other functionality.

@xeioex xeioex added the bug label Feb 2, 2021
@xeioex xeioex added this to the 0.5.1 milestone Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants