Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ This will be our nonexhaustive todo list for InvisiProxy LTS v6.x.x and above. R
- [ ] Implement multi-lang support!

## Proxy/Site Functionality
- [ ] Implement wisp python to the project instead of the unreliable wisp-server-node
- [ ] Add booksmark menu (source wise already present pretty much)
- [ ] Add Chii + ensuring users can access devtools while browsing - partial
- [ ] Omnibox should state what the current site the user is on like a proper URL bar
- [ ] Improve adblocking functions on site using Workerware + a pre-bundled uBlock Origin
- [ ] Implement advanced data URI system
- [ ] Allow custom Wisp urls from the settings menu (not config side)
- [ ] Setting to open multiple stealth frames; basically about:blank but using our system. Pops out in another tab
- [x] Swap to mrrowisp over wisp-js for performance - done
- [x] Hide local browser history on launch - done
- [x] Setting to open about:blank and blob frames - done
- [x] Transport Options Swapping on Frame (Settings Menu doesn't swap) - done
Expand Down
135 changes: 74 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
"@mercuryworkshop/epoxy-transport": "^2.1.28",
"@mercuryworkshop/libcurl-transport": "^1.5.1",
"@mercuryworkshop/scramjet": "https://github.com/MercuryWorkshop/scramjet/releases/download/v1.1.0/mercuryworkshop-scramjet-1.1.0.tgz",
"@mercuryworkshop/wisp-js": "^0.4.1",
"@titaniumnetwork-dev/ultraviolet": "^3.2.10",
"axios": "^1.13.5",
"chii": "^1.15.5",
"fastify": "^5.8.5",
"mrrowisp": "^2.10.0",
"pm2": "^7.0.1",
"puppeteer": "^24.37.2",
"utf-8-validate": "^6.0.6",
Expand Down
98 changes: 55 additions & 43 deletions src/server.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Fastify from 'fastify';
import { createServer } from 'node:http';
import { server as wisp, logging } from "@mercuryworkshop/wisp-js/server";
import { Mrrowisp } from "mrrowisp";
import createRammerhead from '../lib/rammerhead/src/server/index.js';
import fastifyHelmet from '@fastify/helmet';
import fastifyStatic from '@fastify/static';
Expand All @@ -21,29 +21,40 @@ import { existsSync, unlinkSync } from 'node:fs';
*/
console.log(serverUrl);

// Wisp Configuration: Refer to the documentation at https://www.npmjs.com/package/@mercuryworkshop/wisp-js

logging.set_level(logging.NONE);
wisp.options.allow_udp_streams = false;
wisp.options.allow_loopback_ips = true;

// For security reasons only allow these ports. Any additional regional proxies or default sandboxed Tor ports should be added here.
wisp.options.port_whitelist = [
80,
443,
9050,
7000,
7001
];

wisp.options.port_blacklist = [
[6881, 6889],
6969,
1337,
[6969, 6969],
51413,
[49152, 65535]
];
const wisp = new Mrrowisp({
port: 6001,
allowUDP: false,
allowLoopbackIPs: true,
whitelist: {
ports: [80, 443, 9050, 7000, 7001],
},
tcpBufferSize: 65535,
streamLimitPerHost: 256,
streamLimitTotal: 8192,
dnsTTLSeconds: 300,
dnsMethod: "resolve",
dnsResultOrder: "ipv4first",
enableV2: true,
bandwidthLimitKbps: 51200,
connectionsLimitPerIP: 100,
connectionWindowSeconds: 10,
maxMessageSize: 262144,
writeTimeoutSeconds: 30,
frameReadTimeoutSeconds: 60,
banDurationSeconds: 86400,
banMaxStrikes: 5,
banEscalationMultiplier: 2,
maxHandshakeFailures: 20,
maxPacketRate: 2000,
maxConnectionLifetimeSeconds: 7200,
maxStreamsPerConnection: 256,
maxConnectionsPerIP: 100,
globalMaxConnections: 10000,
writeQueueSize: 16384,
maxInboundBytesPerSecond: 10485760,
});

wisp.start();

// The server will check for the existence of this file when a shutdown is requested.
// The shutdown script in run-command.js will temporarily produce this file.
Expand All @@ -69,8 +80,8 @@ const rammerheadScopes = [
].map((pathname) => pathname.replace('/', serverUrl.pathname));

const rammerheadSession = new RegExp(
`^${serverUrl.pathname.replaceAll('.', '\\.')}[a-z0-9]{32}`
),
`^${serverUrl.pathname.replaceAll('.', '\\.')}[a-z0-9]{32}`
),
shouldRouteRh = (req) => {
try {
const url = new URL(req.url, serverUrl);
Expand Down Expand Up @@ -101,7 +112,7 @@ const serverFactory = (handler) => {
.on('upgrade', (req, socket, head) => {
if (shouldRouteRh(req)) routeRhUpgrade(req, socket, head);
else if (req.url.endsWith(getAltPrefix('wisp', serverUrl.pathname)))
wisp.routeRequest(req, socket, head);
wisp.route(req, socket, head);
});
};

Expand Down Expand Up @@ -184,33 +195,33 @@ app.register(fastifyStatic, {
*/

const supportedTypes = {
default: config.disguiseFiles ? 'image/vnd.microsoft.icon' : 'text/html',
html: 'text/html',
txt: 'text/plain',
xml: 'application/xml',
ico: 'image/vnd.microsoft.icon',
},
default: config.disguiseFiles ? 'image/vnd.microsoft.icon' : 'text/html',
html: 'text/html',
txt: 'text/plain',
xml: 'application/xml',
ico: 'image/vnd.microsoft.icon',
},
disguise = 'ico';

if (config.disguiseFiles) {
const getActualPath = (path) =>
path.slice(0, path.length - 1 - disguise.length),
path.slice(0, path.length - 1 - disguise.length),
shouldNotHandle = new RegExp(`\\.(?!html$|${disguise}$)[\\w-]+$`, 'i'),
loaderFile = tryReadFile(
'../views/dist/pages/misc/deobf/loader.html',
import.meta.url,
false
);
let exemptDirs = [
'assets',
'uv',
'scram',
'epoxy',
'libcurl',
'baremux',
'wisp',
'chii',
].map((dir) => getAltPrefix(dir, serverUrl.pathname).slice(1, -1)),
'assets',
'uv',
'scram',
'epoxy',
'libcurl',
'baremux',
'wisp',
'chii',
].map((dir) => getAltPrefix(dir, serverUrl.pathname).slice(1, -1)),
exemptPages = ['login', 'test-shutdown', 'favicon.ico'];
for (const [key, value] of Object.entries(externalPages))
if ('string' === typeof value) exemptPages.push(key);
Expand Down Expand Up @@ -281,6 +292,7 @@ app.get(serverUrl.pathname + ':path', (req, reply) => {
// is present, gracefully shut the server down.
if (reqPath === 'test-shutdown' && existsSync(shutdown)) {
console.log('InvisiProxy is shutting down.');
wisp.stop();
app.close();
unlinkSync(shutdown);
process.exitCode = 0;
Expand Down
Loading