bug fixes

Co-authored-by: Avad3 <Avad3@users.noreply.github.com>
This commit is contained in:
Percs 2024-07-13 19:42:12 -05:00
parent a39a2657c6
commit 47b59945a9
23 changed files with 385 additions and 327 deletions

View file

@ -19,7 +19,7 @@ export default {
treeshake: "recommended", treeshake: "recommended",
input: { input: {
client: "./src/client/index.ts", client: "./src/client/index.ts",
bundle: "./src/bundle/index.ts", shared: "./src/shared/index.ts",
worker: "./src/worker/index.ts", worker: "./src/worker/index.ts",
codecs: "./src/codecs/index.ts", codecs: "./src/codecs/index.ts",
config: "./src/scramjet.config.ts" config: "./src/scramjet.config.ts"

View file

@ -1,4 +1,4 @@
import { encodeUrl } from "../bundle"; import { encodeUrl } from "../shared";
navigator.sendBeacon = new Proxy(navigator.sendBeacon, { navigator.sendBeacon = new Proxy(navigator.sendBeacon, {
apply(target, thisArg, argArray) { apply(target, thisArg, argArray) {

View file

@ -1,4 +1,4 @@
import { rewriteCss } from "../bundle"; import { rewriteCss } from "../shared";
const cssProperties = ["background", "background-image", "mask", "mask-image", "list-style", "list-style-image", "border-image", "border-image-source", "cursor"]; const cssProperties = ["background", "background-image", "mask", "mask-image", "list-style", "list-style-image", "border-image", "border-image-source", "cursor"];
const jsProperties = ["background", "backgroundImage", "mask", "maskImage", "listStyle", "listStyleImage", "borderImage", "borderImageSource", "cursor"]; const jsProperties = ["background", "backgroundImage", "mask", "maskImage", "listStyle", "listStyleImage", "borderImage", "borderImageSource", "cursor"];

View file

@ -1,4 +1,4 @@
import { encodeUrl, rewriteCss, rewriteHtml, rewriteJs, rewriteSrcset } from "../bundle"; import { encodeUrl, rewriteCss, rewriteHtml, rewriteJs, rewriteSrcset } from "../shared";
const attrObject = { const attrObject = {
"nonce": [HTMLElement], "nonce": [HTMLElement],

10
src/client/event.ts Normal file
View file

@ -0,0 +1,10 @@
// idk what shit has to be done on here but it has to be done
// i'm going to temporarily disable rewriting if a MemberExpression detects addEventListener
// window.addEventListener = new Proxy(window.addEventListener, {
// apply (target, thisArg, argArray) {
// //
// return Reflect.apply(target, thisArg, argArray);
// }
// })

View file

@ -1 +1,19 @@
// forgot aobut this api
import { encodeUrl } from "../shared";
window.history.pushState = new Proxy(window.history.pushState, {
apply(target, thisArg, argArray) {
argArray[3] = encodeUrl(argArray[3]);
return Reflect.apply(target, thisArg, argArray);
},
});
window.history.replaceState = new Proxy(window.history.replaceState, {
apply(target, thisArg, argArray) {
argArray[3] = encodeUrl(argArray[3]);
return Reflect.apply(target, thisArg, argArray);
},
});

View file

@ -1,4 +1,5 @@
import "./window.ts"; import "./window.ts";
import "./event.ts";
import "./native/eval.ts"; import "./native/eval.ts";
import "./location.ts"; import "./location.ts";
import "./trustedTypes.ts"; import "./trustedTypes.ts";
@ -8,11 +9,15 @@ import "./requests/websocket.ts"
import "./element.ts"; import "./element.ts";
import "./storage.ts"; import "./storage.ts";
import "./css.ts"; import "./css.ts";
import "./history.ts"
import "./worker.ts"; import "./worker.ts";
import "./scope.ts";
declare global { declare global {
interface Window { interface Window {
__location: Location; __location: Location;
__window: Window; __window: Window;
//@ts-ignore scope function cant be typed
__s: any;
} }
} }

View file

@ -1,5 +1,5 @@
// @ts-nocheck // @ts-nocheck
import { encodeUrl, decodeUrl } from "../bundle"; import { encodeUrl, decodeUrl } from "../shared";
function urlLocation() { function urlLocation() {
const loc = new URL(decodeUrl(location.href)); const loc = new URL(decodeUrl(location.href));

View file

@ -1,4 +1,4 @@
import { rewriteJs } from "../../bundle"; import { rewriteJs } from "../../shared";
const FunctionProxy = new Proxy(Function, { const FunctionProxy = new Proxy(Function, {
construct(target, argArray) { construct(target, argArray) {

View file

@ -1,6 +1,6 @@
// ts throws an error if you dont do window.fetch // ts throws an error if you dont do window.fetch
import { encodeUrl, rewriteHeaders } from "../../bundle"; import { encodeUrl, rewriteHeaders } from "../../shared";
window.fetch = new Proxy(window.fetch, { window.fetch = new Proxy(window.fetch, {
apply(target, thisArg, argArray) { apply(target, thisArg, argArray) {

View file

@ -1,4 +1,4 @@
import { encodeUrl, rewriteHeaders } from "../../bundle"; import { encodeUrl, rewriteHeaders } from "../../shared";
XMLHttpRequest.prototype.open = new Proxy(XMLHttpRequest.prototype.open, { XMLHttpRequest.prototype.open = new Proxy(XMLHttpRequest.prototype.open, {
apply(target, thisArg, argArray) { apply(target, thisArg, argArray) {

12
src/client/scope.ts Normal file
View file

@ -0,0 +1,12 @@
function scope(identifier: any) {
if (identifier instanceof Window) {
return window.__window;
} else if (identifier instanceof Location) {
return window.__location;
}
return identifier;
}
// shorthand because this can get out of hand reall quickly
window.__s = scope;

View file

@ -1,4 +1,4 @@
import { rewriteHtml, rewriteJs, encodeUrl } from "../bundle"; import { rewriteHtml, rewriteJs, encodeUrl } from "../shared";
// @ts-expect-error // @ts-expect-error
trustedTypes.createPolicy = new Proxy(trustedTypes.createPolicy, { trustedTypes.createPolicy = new Proxy(trustedTypes.createPolicy, {

View file

@ -10,8 +10,13 @@ const windowProxy = new Proxy(window, {
return target[prop]; return target[prop];
}, },
set(target, p, newValue, receiver) { set(target, prop, newValue) {
return Reflect.set(target, p, newValue, receiver); // ensures that no apis are overwritten
if (typeof prop === "string" && ["window", "top", "parent", "self", "globalThis", "location"].includes(prop)) {
return false;
}
return Reflect.set(target, prop, newValue);
}, },
}); });

View file

@ -1,7 +1,13 @@
import { encodeUrl } from "../bundle"; import { encodeUrl } from "../shared";
const RealWorker = Worker
Worker = new Proxy(Worker, { Worker = new Proxy(Worker, {
construct(_target, args) { construct(target, argArray) {
return new RealWorker(encodeUrl(args[0]), args[1]) argArray[0] = encodeUrl(argArray[0]);
// target is a reference to the object that you are proxying
// Reflect.construct is just a wrapper for calling target
// you could do new target(...argArray) and it would work the same effectively
return Reflect.construct(target, argArray);
} }
}) })

View file

@ -6,7 +6,7 @@ declare global {
prefix: string; prefix: string;
codec: Codec codec: Codec
config: string; config: string;
bundle: string; shared: string;
worker: string; worker: string;
client: string; client: string;
codecs: string; codecs: string;
@ -18,7 +18,7 @@ self.__scramjet$config = {
prefix: "/scramjet/", prefix: "/scramjet/",
codec: self.__scramjet$codecs.plain, codec: self.__scramjet$codecs.plain,
config: "/scram/scramjet.config.js", config: "/scram/scramjet.config.js",
bundle: "/scram/scramjet.bundle.js", shared: "/scram/scramjet.shared.js",
worker: "/scram/scramjet.worker.js", worker: "/scram/scramjet.worker.js",
client: "/scram/scramjet.client.js", client: "/scram/scramjet.client.js",
codecs: "/scram/scramjet.codecs.js" codecs: "/scram/scramjet.codecs.js"

View file

@ -3,10 +3,11 @@ export { rewriteCss } from "./rewriters/css";
export { rewriteHtml, rewriteSrcset } from "./rewriters/html"; export { rewriteHtml, rewriteSrcset } from "./rewriters/html";
export { rewriteJs } from "./rewriters/js"; export { rewriteJs } from "./rewriters/js";
export { rewriteHeaders } from "./rewriters/headers"; export { rewriteHeaders } from "./rewriters/headers";
export { BareClient } from "@mercuryworkshop/bare-mux"
export function isScramjetFile(src: string) { export function isScramjetFile(src: string) {
let bool = false; let bool = false;
["codecs", "client", "bundle", "worker", "config"].forEach((file) => { ["codecs", "client", "shared", "worker", "config"].forEach((file) => {
if (src === self.__scramjet$config[file]) bool = true; if (src === self.__scramjet$config[file]) bool = true;
}); });

View file

@ -5,7 +5,7 @@ import render from "dom-serializer";
import { encodeUrl } from "./url"; import { encodeUrl } from "./url";
import { rewriteCss } from "./css"; import { rewriteCss } from "./css";
import { rewriteJs } from "./js"; import { rewriteJs } from "./js";
import { isScramjetFile } from "../"; import { isScramjetFile } from "..";
export function rewriteHtml(html: string, origin?: URL) { export function rewriteHtml(html: string, origin?: URL) {
const handler = new DomHandler((err, dom) => dom); const handler = new DomHandler((err, dom) => dom);
@ -63,7 +63,7 @@ function traverseParsedHtml(node, origin?: URL) {
if (node.name === "head") { if (node.name === "head") {
const scramjetScripts = []; const scramjetScripts = [];
["codecs", "config", "bundle", "client"].forEach((script) => { ["codecs", "config", "shared", "client"].forEach((script) => {
scramjetScripts.push(new Element("script", { scramjetScripts.push(new Element("script", {
src: self.__scramjet$config[script], src: self.__scramjet$config[script],
type: "module" type: "module"

View file

@ -31,6 +31,7 @@ export function rewriteJs(js: string, origin?: URL) {
"this", "this",
"parent", "parent",
"top", "top",
"this",
"location" "location"
] ]
@ -62,7 +63,7 @@ export function rewriteJs(js: string, origin?: URL) {
// js rweriting notrdone // js rweriting notrdone
MemberExpression: (node: ESTree.MemberExpression) => { MemberExpression: (node: ESTree.MemberExpression) => {
if (node.object.type === "Identifier" && identifierList.includes(node.object.name)) { if (node.object.type === "Identifier" && identifierList.includes(node.object.name)) {
node.object.name = "__" + node.object.name; node.object.name = `__s${node.object.name}`;
} }
} }
}); });

View file

@ -1,6 +1,6 @@
import { BareClient } from "@mercuryworkshop/bare-mux"; import { BareClient } from "@mercuryworkshop/bare-mux";
import { BareResponseFetch } from "@mercuryworkshop/bare-mux"; import { BareResponseFetch } from "@mercuryworkshop/bare-mux";
import { encodeUrl, decodeUrl, rewriteCss, rewriteHeaders, rewriteHtml, rewriteJs } from "../bundle"; import { encodeUrl, decodeUrl, rewriteCss, rewriteHeaders, rewriteHtml, rewriteJs } from "../shared";
declare global { declare global {
interface Window { interface Window {