diff --git a/CHANGELOG.md b/CHANGELOG.md index c8a9c9f..e62aa39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# v3.0.1 + +- This version of Ultraviolet upgrades [bare-mux](https://www.npmjs.com/package/@mercuryworkshop/bare-mux). This solves an issue with websockets not being opened properly. +- This version of Ultraviolet allows error messages to be iframed on cross origin isolated pages. + +# v3.0.0 + +- This version of Ultraviolet has support for using [bare-mux](https://github.com/MercuryWorkshop/bare-mux) transports, allowing for use for other implementations like [EpoxyTransport](https://github.com/MercuryWorkshop/EpoxyTransport), [CurlTransport](https://github.com/MercuryWorkshop/CurlTransport), and the existing implementation [Bare-Client](https://github.com/MercuryWorkshop/Bare-as-module3). + # v2.0.0 - This version of Ultraviolet has support for Bare server v3 @@ -65,4 +74,4 @@ self.addEventListener('fetch', (event) => event.respondWith(sw.fetch(event))); - This is the first official release of the Ultraviolet library. - The `uv.bundle.js` script is built using Webpack, allowing users to easily bundle their own scripts and dependencies with Ultraviolet. -- This project is still under active development, and future releases will include new features and improvements. +- This project is still under active development, and future releases will include new features and improvements. \ No newline at end of file diff --git a/README.md b/README.md index 28aaa04..e708434 100644 --- a/README.md +++ b/README.md @@ -24,23 +24,23 @@ Some of the popular websites that Ultraviolet supports include: ## Used by +- [Alu](https://github.com/titaniumnetwork-dev/Alu) +- [AnuraOS](https://github.com/MercuryWorkshop/anuraOS) +- [Nebula](https://github.com/NebulaServices/Nebula) - [Holy Unblocker](https://github.com/holy-unblocker/website) -- [Hypertabs](https://hypertabs.cc/) - [Terbium](https://github.com/TerbiumOS/webOS) - [Incognito](https://github.com/caracal-js/Incognito) -- [Nebula](https://github.com/NebulaServices/Nebula) -- [Noctura](https://github.com/NebulaServices/Noctura) - [Metallic](https://github.com/Metallic-Web/Metallic) ## Upgrading -A guide for updating from v1 to v2 can be found [here](./docs/V2-UPGRADE-GUIDE.md). +A guide for updating from any version to v3 can be found [here](https://github.com/titaniumnetwork-dev/Ultraviolet/wiki/Upgrading). -## Older Bare servers +## Older Ultraviolet versions -Starting from v2, Ultraviolet only supports Bare servers v3+. +Starting from v3, Ultraviolet uses [bare-mux](https://github.com/MercuryWorkshop/bare-mux), a library that allows you to switch out your Bare client. -If you operate an outdated Bare server, we encourage you to update. If you're using an outdated Bare server, we encourage you to find an updated Bare server or host your own. +If you operate using an older Ultraviolet, we encourage you to update. If you're too lazy to do either of the above, you can install an outdated and unsupported version of Ultraviolet. @@ -58,4 +58,4 @@ This repository can be built, but it can't be deployed to any services. See [Ult ## Documentation -Documentation can be found in the [wiki](https://github.com/titaniumnetwork-dev/Ultraviolet/wiki). +Documentation can be found in the [wiki](https://github.com/titaniumnetwork-dev/Ultraviolet/wiki). \ No newline at end of file diff --git a/build.js b/build.js index e80f12f..74af2c0 100644 --- a/build.js +++ b/build.js @@ -31,5 +31,6 @@ await build({ ), }, bundle: true, + logLevel: 'info', outdir: 'dist/', }); diff --git a/docs/V2-UPGRADE-GUIDE.md b/docs/V2-UPGRADE-GUIDE.md deleted file mode 100644 index aff8cf7..0000000 --- a/docs/V2-UPGRADE-GUIDE.md +++ /dev/null @@ -1,9 +0,0 @@ -# Upgrade to Ultraviolet v2.x - -## No support for older Bare servers. - -In order to more effectively use newer APIs provided by newer implementations of bare-client, support folder older Bare servers has been dropped. - -You need to upgrade your Bare server in order to use Ultraviolet. - -See the [Bare server node upgrade guide](https://github.com/tomphttp/bare-server-node/blob/master/docs/V2-UPGRADE-GUIDE.md) for upgrading your Bare server. diff --git a/package-lock.json b/package-lock.json index ddcf7f6..2b97d5a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@titaniumnetwork-dev/ultraviolet", - "version": "2.0.0", + "version": "3.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@titaniumnetwork-dev/ultraviolet", - "version": "2.0.0", + "version": "3.1.0", "license": "MIT", "devDependencies": { - "@tomphttp/bare-client": "^2.2.0-alpha", + "@mercuryworkshop/bare-mux": "^1.0.7", "css-tree": "^2.3.1", "esbuild": "^0.18.11", "eslint": "^8.28.0", @@ -476,6 +476,16 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, + "node_modules/@mercuryworkshop/bare-mux": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@mercuryworkshop/bare-mux/-/bare-mux-1.0.7.tgz", + "integrity": "sha512-VUJvfLxlzpyCuKoGfaI+sUpHEK4tvmvpYvkalU2z604+O9UahfZoc53arO9pm9F3Fnv7ZNloSWMnvSlPAznkoA==", + "dev": true, + "dependencies": { + "@types/uuid": "^9.0.8", + "uuid": "^9.0.1" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -521,18 +531,18 @@ "node": ">=14" } }, - "node_modules/@tomphttp/bare-client": { - "version": "2.2.0-alpha", - "resolved": "https://registry.npmjs.org/@tomphttp/bare-client/-/bare-client-2.2.0-alpha.tgz", - "integrity": "sha512-xhcflOpwr92tkpp8SoDhB3nK3LHMBIjx+vgow37XobQew2k0/mXSxmaU7BsDFpOIa1CcLCEsR8gWn0v7Cy9+7Q==", - "dev": true - }, "node_modules/@types/estree": { "version": "0.0.46", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.46.tgz", "integrity": "sha512-laIjwTQaD+5DukBZaygQ79K1Z0jb1bPEMRrkXSLjtCcZm+abyp5YbrqpSLzD42FwWW6gK/aS4NYpJ804nG2brg==", "dev": true }, + "node_modules/@types/uuid": { + "version": "9.0.8", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.8.tgz", + "integrity": "sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==", + "dev": true + }, "node_modules/acorn": { "version": "8.8.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz", @@ -1903,6 +1913,19 @@ "punycode": "^2.1.0" } }, + "node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "dev": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -2266,6 +2289,16 @@ } } }, + "@mercuryworkshop/bare-mux": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@mercuryworkshop/bare-mux/-/bare-mux-1.0.7.tgz", + "integrity": "sha512-VUJvfLxlzpyCuKoGfaI+sUpHEK4tvmvpYvkalU2z604+O9UahfZoc53arO9pm9F3Fnv7ZNloSWMnvSlPAznkoA==", + "dev": true, + "requires": { + "@types/uuid": "^9.0.8", + "uuid": "^9.0.1" + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -2299,18 +2332,18 @@ "dev": true, "optional": true }, - "@tomphttp/bare-client": { - "version": "2.2.0-alpha", - "resolved": "https://registry.npmjs.org/@tomphttp/bare-client/-/bare-client-2.2.0-alpha.tgz", - "integrity": "sha512-xhcflOpwr92tkpp8SoDhB3nK3LHMBIjx+vgow37XobQew2k0/mXSxmaU7BsDFpOIa1CcLCEsR8gWn0v7Cy9+7Q==", - "dev": true - }, "@types/estree": { "version": "0.0.46", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.46.tgz", "integrity": "sha512-laIjwTQaD+5DukBZaygQ79K1Z0jb1bPEMRrkXSLjtCcZm+abyp5YbrqpSLzD42FwWW6gK/aS4NYpJ804nG2brg==", "dev": true }, + "@types/uuid": { + "version": "9.0.8", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.8.tgz", + "integrity": "sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==", + "dev": true + }, "acorn": { "version": "8.8.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz", @@ -3291,6 +3324,12 @@ "punycode": "^2.1.0" } }, + "uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "dev": true + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 4e11f71..320c777 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titaniumnetwork-dev/ultraviolet", - "version": "2.0.0", + "version": "3.1.0", "description": "Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more!", "main": "lib/index.cjs", "license": "MIT", @@ -18,10 +18,12 @@ "scripts": { "build": "node build.js", "dev": "node build.js --dev", - "prepack": "npm run build" + "prepack": "npm run build", + "publish": "npm run build && npm publish --access public", + "pack": "npm run build && npm pack" }, "devDependencies": { - "@tomphttp/bare-client": "^2.2.0-alpha", + "@mercuryworkshop/bare-mux": "^1.0.7", "css-tree": "^2.3.1", "esbuild": "^0.18.11", "eslint": "^8.28.0", diff --git a/src/client/index.js b/src/client/index.js index 4f93149..a099fd0 100644 --- a/src/client/index.js +++ b/src/client/index.js @@ -34,7 +34,7 @@ class UVClient extends EventEmitter { /** * * @param {typeof globalThis} window - * @param {import('@tomphttp/bare-client').BareClient} bareClient + * @param {import('@mercuryworkshop/bare-mux').BareClient} bareClient * @param {boolean} worker */ constructor(window = self, bareClient, worker = !window.window) { diff --git a/src/rewrite/index.js b/src/rewrite/index.js index 2ac8ce3..cf53f5f 100644 --- a/src/rewrite/index.js +++ b/src/rewrite/index.js @@ -34,7 +34,7 @@ import { wrapEval, } from './rewrite.script.js'; import { openDB } from 'idb'; -import { BareClient } from '@tomphttp/bare-client'; +import { BareClient } from '@mercuryworkshop/bare-mux'; import EventEmitter from 'events'; /** diff --git a/src/uv.config.js b/src/uv.config.js index 56d1a92..7818c4f 100644 --- a/src/uv.config.js +++ b/src/uv.config.js @@ -1,7 +1,6 @@ /*global Ultraviolet*/ self.__uv$config = { prefix: '/service/', - bare: '/bare/', encodeUrl: Ultraviolet.codec.xor.encode, decodeUrl: Ultraviolet.codec.xor.decode, handler: '/uv.handler.js', diff --git a/src/uv.handler.js b/src/uv.handler.js index 2f17de8..5f42973 100644 --- a/src/uv.handler.js +++ b/src/uv.handler.js @@ -14,7 +14,7 @@ const UVClient = self.UVClient; const __uv$config = self.__uv$config; /** - * @type {import('@tomphttp/bare-client').BareManifest} + * @type {import('@mercuryworkshop/bare-mux').BareManifest} */ const __uv$bareData = self.__uv$bareData; @@ -63,7 +63,7 @@ function __uvHook(window) { }*/ // websockets - const bareClient = new Ultraviolet.BareClient(__uv$bareURL, __uv$bareData); + const bareClient = new Ultraviolet.BareClient(); const client = new UVClient(window, bareClient, worker); const { @@ -1023,28 +1023,12 @@ function __uvHook(window) { if (cookieStr !== '') requestHeaders['Cookie'] = cookieStr.toString(); event.respondWith( - bareClient.createWebSocket(event.data.args[0], event.data.args[1], { - headers: requestHeaders, - readyStateHook: (socket, getReadyState) => { - socket.__uv$getReadyState = getReadyState; - }, - sendErrorHook: (socket, getSendError) => { - socket.__uv$getSendError = getSendError; - }, - urlHook: (socket, url) => { - socket.__uv$socketUrl = url; - }, - protocolHook: (socket, getProtocol) => { - socket.__uv$getProtocol = getProtocol; - }, - setCookiesCallback: (setCookies) => { - // document.cookie is hooked - // so we can just call it - for (const cookie of setCookies) - window.document.cookie = cookie; - }, - webSocketImpl: event.target, - }) + bareClient.createWebSocket( + event.data.args[0], + event.data.args[1], + event.target, + requestHeaders, + ) ); }); diff --git a/src/uv.sw.js b/src/uv.sw.js index e526140..d02cacb 100644 --- a/src/uv.sw.js +++ b/src/uv.sw.js @@ -40,7 +40,7 @@ class UVServiceWorker extends Ultraviolet.EventEmitter { /** * @type {InstanceType} */ - this.bareClient = new Ultraviolet.BareClient(this.address); + this.bareClient = new Ultraviolet.BareClient(); } /** * @@ -297,7 +297,7 @@ class ResponseContext { /** * * @param {RequestContext} request - * @param {import("@tomphttp/bare-client").BareResponseFetch} response + * @param {import("@mercuryworkshop/bare-mux").BareResponseFetch} response */ constructor(request, response) { this.request = request; @@ -413,6 +413,9 @@ function hostnameErrorTemplate(fetchedURL, bareServer) { '' + "" + 'Error' + + '' + '' + '' + '

This site can’t be reached

' + @@ -483,6 +486,9 @@ function errorTemplate( '' + "" + 'Error' + + '' + '' + '' + "

" + @@ -520,7 +526,7 @@ function errorTemplate( } /** - * @typedef {import("@tomphttp/bare-client").BareError} BareError + * @typedef {import("@mercuryworkshop/bare-mux").BareError} BareError */ /** @@ -556,6 +562,12 @@ function renderError(err, fetchedURL, bareServer) { * @type {string} */ let message; + let headers = { + 'content-type': 'text/html', + }; + if (crossOriginIsolated) { + headers['Cross-Origin-Embedder-Policy'] = 'require-corp'; + } if (isBareError(err)) { status = err.status; @@ -582,9 +594,7 @@ function renderError(err, fetchedURL, bareServer) { ), { status, - headers: { - 'content-type': 'text/html', - }, + headers: headers } ); } diff --git a/uv.d.ts b/uv.d.ts index b66bd7a..4d879f9 100644 --- a/uv.d.ts +++ b/uv.d.ts @@ -26,19 +26,6 @@ export type UVDecode = (input: Coded) => string; * This interface defines the configuration options for the Ultraviolet library. */ export interface UVConfig { - /** - * The Bare server(s) to use. - * If an array is specified, the service worker will randomly select a server to use. - * The selected server will be used for the duration of the session. - * Both relative and absolute paths are accepted. Relative paths are resolved to the current URL. - * @example // A Bare server running on the subdomain `bare.`, automatically correcting the apex record: - * `${location.protocol}//bare.${location.host.replace(/^www\./, "")} - * @example `http://localhost:8080/` - * @example `http://localhost:8080/bare/` - * @defaultValue `/bare/` - * @see {@link|https://github.com/tomphttp/specifications/blob/master/BareServer.md} - */ - bare?: string | string[]; /** * The prefix for Ultraviolet to listen on. * This prefix will be used to create the URL for the service worker and the client script.