diff --git a/src/client/index.ts b/src/client/index.ts index fbc945b..82fe926 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -1,12 +1,13 @@ import "./location"; +import "./trustedTypes.ts"; +import "./eval.ts"; import "./storage"; import "./element.ts"; -import "./eval.ts"; import "./fetch.ts"; -import "./trustedTypes.ts"; +import "./xmlhttprequest.ts"; declare global { interface Window { __location: Location; } -} \ No newline at end of file +} diff --git a/src/client/xmlhttprequest.ts b/src/client/xmlhttprequest.ts new file mode 100644 index 0000000..eaedded --- /dev/null +++ b/src/client/xmlhttprequest.ts @@ -0,0 +1,18 @@ +XMLHttpRequest.prototype.open = new Proxy(XMLHttpRequest.prototype.open, { + apply(target, thisArg, argArray) { + if (argArray[1]) argArray[1] = self.__scramjet$bundle.rewriters.url.encodeUrl(argArray[1]); + + return Reflect.apply(target, thisArg, argArray); + }, +}); + +XMLHttpRequest.prototype.setRequestHeader = new Proxy(XMLHttpRequest.prototype.setRequestHeader, { + apply(target, thisArg, argArray) { + let headerObject = Object.fromEntries(argArray); + headerObject = self.__scramjet$bundle.rewriters.rewriteHeaders(headerObject); + + argArray = Object.entries(headerObject); + + return Reflect.apply(target, thisArg, argArray); + }, +});