Skip to content

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?

@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.

@manugarg
Copy link
Owner

@NattyNarwhal Sorry for super late review, but this looks great to me. Thanks so much. Do you want to send it for review?

@NattyNarwhal
Copy link
Author

NattyNarwhal commented Mar 12, 2025

I'd appreciate review; I'm uncertain about lifetimes myself, though it seems to be OK with the unit tests. Windows support is also untested, as is unvendoring Duktape for i.e. distro packaging.

@NattyNarwhal NattyNarwhal marked this pull request as ready for review March 12, 2025 02:17
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/
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.

2 participants