Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@ebay/userscript-proxy
Advanced tools
HTTP proxy to inject scripts and stylesheets into existing sites.
Ever tried to run userscripts on your iOS device or your Android phone? For iOS, it's not possible, and for Android it's an exercise in frustration.
Userscript Proxy allows you to run userscripts on mobile devices. Userscripts are snippets of JavaScript and CSS code that are added to a particular web page, to change the way it looks or the way it behaves. Tampermonkey and Greasemonkey are browser extensions that allow you to install userscripts into web pages, but they only work properly in desktop browsers – they don't support iOS at all, and the version for Android is tied to an old browser that doesn't work very well anymore.
Instead of running userscripts directly in the browser, Userscript Proxy is an HTTP proxy server that transparently injects scripts and stylesheets (userscripts) into existing sites. We use this tool to quickly generate research stimuli for user testing: we write JavaScript scripts and CSS stylesheets that alter our existing sites according to new designs. This makes it much easier for our developers when we want to test out a simple change: we can run our changes on top of the existing site.
With Userscript Proxy, you can set up a collection of scripts, run multiple scripts at once, and specify which hosts and URLs to inject each script into. You can think of it as Tampermonkey or Greasemonkey running inside of a proxy server.
Userscript Proxy generates a proxy PAC file that specifies which web hosts have URLs that need to be altered, and directs all requests to those hosts to Userscript Proxy's proxy server. The proxy server then adds userscripts to the HTML file that is served from each URL that matches. Scripts and stylesheets are added inline to the proxied page, so they run with the same permissions as a script running directly on the website.
Userscript Proxy uses the http-mitm-proxy npm module for the core proxy functionality.
Userscript Proxy is a Node.js application. The proxy can be used as a command-line application or as a Node module. Install as a command-line application unless you want to include the proxy in software you're writing.
npm install -g userscript-proxy
To run Userscript Proxy, you need a configuration file (config.json) and userscripts, which are JavaScript and CSS files. You can get a feel for how it works with the example files on this page. Clone this repository to your computer or download the ZIP file from the GitHub page, open a Terminal window and navigate to the examples
directory, then run:
userscript-proxy config.json
See "Using the proxy server" below to set it up on your devices.
In general, run Userscript Proxy as follows:
userscript-proxy <config_file> [options]
<config_file>
is the path to a JSON file that specifies the configuration of the proxy (see below for config file format)[options]
include:--loadScript set Start the proxy with the given set of userscripts active (defined in the config file)
--staticDir dir Path to directory of static files to serve at /static
--proxyPort port Port for HTTP proxy server (default 8888)
--pacPort port Port to serve PAC and other static files (default 8080)
--limitHosts Only proxy hosts in the currently-selected userscript set
(see "Notes" section for more details)
--addPac file Path to existing PAC file to add proxy rules to
(see "Notes" section for more details)
--proxyIndex file Path to proxy index HTML file
--auth Enable proxy authentication (experimental; see "Notes" section)
npm install --save userscript-proxy
Add the following code to your script:
var proxy = require('userscript-proxy');
proxy(config, id, options);
config
is a JavaScript object that specifies the configuration of the proxy (see below for config format)id
is the id of the set of userscripts you want to enableoptions
is an optional parameter with proxy options:{
'loadScript': 'userscriptSetId', // Start the proxy with the given set of userscripts active (defined in config)
'staticDir': './path/to/static', // Path to directory of static files to serve at /static
'proxyPort': 8888, // Port for HTTP proxy server (default 8888)
'pacPort': 8080, // Port to serve PAC and other static files (default 8080)
'limitHosts': false, // Only proxy hosts in the currently-selected userscript set
// (see "Notes" section for more details)
'addPac': pacFileString, // Add proxy rules to the beginning of an existing PAC file (as string)
// (see "Notes" section for more details)
'proxyIndex': indexFileString, // Proxy index HTML file (as string)
'auth': false // Enable proxy authentication (experimental; see "Notes" section)
}
http://<proxy-server>:8080/
in the browser of the device that will run the userscripts, where <proxy-server>
is the hostname or IP of the proxy server.http://<proxy-server>:8080/
, the proxy will globally and immediately update which sites will have userscripts added to them.Userscript Proxy doesn't have a graphical interface like Tampermonkey to install scripts, but don't get scared off – you just need to add the scripts to an easy configuration file.
See the examples
directory for a sample config.json
file and sample scripts. You can run the samples directly by opening a Terminal window in the examples
directory and running userscript-proxy config.json
Userscripts are defined in a JavaScript object, defined below.
{
"userscripts": [
{
"title": "Title of userscript",
"id": "userscriptId",
"match": [
{"host": "example.com", "url": "/"},
{"host": "example.com", "url": "/index.html"}
],
"scripts": [
"./scripts/userscript.js"
],
"styles": [
"./styles/userscript.css"
]
},
...
],
"userscriptSets": [
{
"title": "Title of userscript set",
"id": "userscriptSetId",
"password": "pass",
"userscripts": ["userscriptId", ...]
},
...
]
}
userscripts
inject JavaScript or CSS file(s) into specified URL(s).userscriptSets
are collections of individual userscripts that will be enabled at the same time. These sets are what are shown to the user on the proxy web page, and the user can switch between them.title
and id
, can match
one or more URLs, can have one or more JavaScript files (scripts
) injected into that URL, and can have one or more CSS files (styles
) injected into that URL.title
and id
, a password
that is used when proxy authentication is enabled, and an array of userscripts
IDs that will all be enabled when this set is selected.userscripts
array, an entry also needs to be added to the userscriptSets
array to allow the user to enable a userscript or set of userscripts by ID.All instances of the following static keys will be replaced with their corresponding dynamic values in userscripts.
@@USERSCRIPT-PROXY-HOSTNAME-FQDN@@
fully qualified domain name of the proxy server@@USERSCRIPT-PROXY-HOSTNAME@@
hostname of the proxy server@@USERSCRIPT-PROXY-PAC-PORT@@
port number that static files and the PAC are served from@@USERSCRIPT-PROXY-PROXY-PORT@@
port number of the HTTP proxy@@USERSCRIPT-PROXY-STATIC-SERVER@@
base URL of the static directory served by the proxy@@USERSCRIPT-PROXY-LIST@@
HTML list of available userscript sets@@USERSCRIPT-PROXY-PAC-URL@@
URL to download PAC from@@USERSCRIPT-PROXY-CA-URL@@
URL to download CA certificate fromhttp://<proxy-server>:8080/userscript-proxy-<id>.pac
, where <proxy-server>
is the hostname of the proxy server, and <id>
is the ID of the set of userscripts you want to enable.--limitHosts
.--addPac <path>
, where <path>
is the path to a PAC file on your computer. Userscript Proxy will add its proxy rules to the beginning of the FindProxyForURL
function in that PAC file. Use the following URL in the proxy settings of the client device: http://<proxy-server>:8080/userscript-proxy-<id>-internal.pac
, where <proxy-server>
is the hostname of the proxy server, and <id>
is the ID of the set of userscripts you want to enable or all
if you want to allow all hosts in your config to be proxied.--auth
.~/.userscript-proxy/certs/ca.pem
. If you want to use the generated CA certificate directly from ~/.userscript-proxy/certs/ca.pem
, you may need to convert it to der
format or use the crt
file extension, depending on the client device. The proxy serves a version in der
format with the crt
extension.Copyright (c) 2018 eBay Inc.
Use of this source code is governed by a MIT-style license that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
FAQs
HTTP proxy to inject scripts and stylesheets into existing sites.
We found that @ebay/userscript-proxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.