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

Switch from SpiderMonkey 1.7 to Duktape #208

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

NattyNarwhal
Copy link

pacparser currently vendors SpiderMonkey 1.7, a JavaScript engine that predates the Obama presidency. There's been a ton of changes to JavaScript and best practices when it comes to security and portability, so using this old version of SM doesn't make sense anymore.

People are trivially able to write exploits against this old version, and seeing as PAC files could come from untrusted networks, that doesn't seem like a wise decision.

To replace it, I've used duktape, a popular compact and embeddable JS runtime. There are a lot, but duktape seems popular; for example, polkit switched from (newer) SpiderMonkey to duktape. The only change I've needed to make to JS code is that RegExps don't seem to be callable under duktape; they aren't under V8 either though, so this might have been a Mozilla-ism.

The massively smaller codebase of duktape is hopefully better security and maintainability wise, but also results in much smaller binaries. For example, pactester goes from 1.5M to 687K on my system.

Passes unit tests on macOS. Not tested on Linux/Windows yet. However, I'm not certain about i.e. string lifetimes with duktape. They didn't seem clear with SpiderMonkey either though; perhaps it'd be an opportunity to i.e. explicitly strdup them?

pacparser currently vendors SpiderMonkey 1.7, a JavaScript engine that
predates the Obama presidency. There's been a ton of changes to
JavaScript and best practices when it comes to security and
portability, so using this old version of SM doesn't make sense anymore.

People are [trivially able to write exploits][ancientmonkey] against
this old version, and seeing as PAC files could come from untrusted
networks, that doesn't seem like a wise decision.

To replace it, I've used duktape, a popular compact and embeddable JS
runtime. There are a lot, but duktape seems popular; for example, polkit
switched from (newer) SpiderMonkey to duktape. The only change I've
needed to make to JS code is that RegExps don't seem to be callable
under duktape; they aren't under V8 either though, so this might have
been a Mozilla-ism.

The massively smaller codebase of duktape is hopefully better security
and maintainability wise, but also results in much smaller binaries. For
example, pactester goes from 1.5M to 687K on my system.

Passes unit tests on macOS. Not tested on Linux/Windows yet. However,
I'm not certain about i.e. string lifetimes with duktape. They didn't
seem clear with SpiderMonkey either though; perhaps it'd be an
opportunity to i.e. explicitly strdup them?

[ancientmonkey]: https://blog.pspaul.de/posts/ancient-monkey-pwning-a-17-year-old-version-of-spidermonkey/
@NattyNarwhal
Copy link
Author

Note that the Duktape used is 2.7 and built with default options. It could perhaps be made unvendored and rely on a system Duktape, but that seems hairy with the current makefile.

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

Successfully merging this pull request may close these issues.

1 participant