Open
Description
One of the things I've been toying with is the idea of running scripts when they're uploaded inside a sandbox on the server that would replicate the Tampermonkey environment (since Node.js uses V8 it would be trivial for a malicious author to detect the difference between V8 and Spidermokey, e.g. if (typeof [] === 'object') return;
) in order to detect potentially malicious code. Here's my logic to do this:
- get the source of a page matching a random
@include
rule of the of the script using Google search api. For a@include *
, just use http://google.com - use jsdom with the most advance options to provide a DOM for the page. I might need to make some modifications to make it more believable, like setting request headers that jsdom uses when fetching remote scripts and images in the page to look like Google Chrome requests.
- replicate GM_* apis and metadata behavior (
@require
and@resource
) that Tampermonkey supports - run the script in a sandbox with the window from jsdom as its global object and detect potentially malicious function calls using defineGetter for eval and document.cookies
- provide warnings for scripts that use these risky functions and suggest safer alternatives
Note: I'm also doing this because it fills one of my requirements to get this project accepted by my professor as my capstone project.
Edit (4/10): Fleshed things out a little more.