Skip to content

Commit

Permalink
Finish refactoring types in AeroSandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
MovByte committed Jul 25, 2024
1 parent 4d640d7 commit b05984c
Show file tree
Hide file tree
Showing 42 changed files with 230 additions and 253 deletions.
2 changes: 1 addition & 1 deletion src/AeroSandbox/build/customBuilds/frankenUV.workers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UVRewriterWorkerMembers } from "$types/index.d";
import { UVRewriterWorkerMembers } from "$types/customBuilds";
import type { UVConfig } from "@titaniumnetwork-dev/ultraviolet";

import { defaultProxyFeatures } from "../../build/featureMembers";
Expand Down
26 changes: 13 additions & 13 deletions src/AeroSandbox/build/featureMembers.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { InterceptionFeaturesEnum } from "$types/index.d";
import { InterceptionFeaturesEnum } from "$types/apiInterceptors";

// TODO: Put all of these terms in the API Interception Glossary

/** @note: These do not cover Origin Isolation although Origin Emulation is a type of Origin Isolation. Origin Emulation is a superset of Origin Isolation. */
const originEmulationFeatures =
InterceptionFeaturesEnum.corsEmulation |
InterceptionFeaturesEnum.cacheEmulation |
InterceptionFeaturesEnum.privacySandbox |
InterceptionFeaturesEnum.nestedSWs;
InterceptionFeaturesEnum.corsEmulation |
InterceptionFeaturesEnum.cacheEmulation |
InterceptionFeaturesEnum.privacySandbox |
InterceptionFeaturesEnum.nestedSWs;
/** @note: These do not cover Origin Concealers although Origin Isolation is a type of Origin Concealing. Origin Isolation is a superset of Origin Concealment. */
const miscOriginIsolators = InterceptionFeaturesEnum.messageIsolation;
const miscOriginConcealers =
InterceptionFeaturesEnum.elementConcealment |
InterceptionFeaturesEnum.errorConcealment;
InterceptionFeaturesEnum.elementConcealment |
InterceptionFeaturesEnum.errorConcealment;
const defaultSWProxyFeatures = originEmulationFeatures | miscOriginConcealers;
const defaultProxyFeatures =
defaultSWProxyFeatures | InterceptionFeaturesEnum.requestUrlProxifier;
defaultSWProxyFeatures | InterceptionFeaturesEnum.requestUrlProxifier;

export {
originEmulationFeatures,
miscOriginIsolators,
miscOriginConcealers,
defaultSWProxyFeatures,
defaultProxyFeatures
originEmulationFeatures,
miscOriginIsolators,
miscOriginConcealers,
defaultSWProxyFeatures,
defaultProxyFeatures,
};
4 changes: 4 additions & 0 deletions src/AeroSandbox/src/init$aero.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { AeroGlobalType } from "$types/$aero.d";

// The rest of the aero props are set in the SW injects before this file is executed
// I have no use for this file yet
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/concealer/blob.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor } from "$types/index.d";
import { APIInterceptor } from "$types/apiInterceptors";
import isHtml from "$shared/isHTML";

export default {
Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/concealer/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { afterPrefix } from "$shared/getProxyUrl";
import { APIInterceptor, ExposedContextsEnum } from "$types/index.d";
import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors";

// Proxy the getters for shadow root stylesheets

Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/concealer/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor, SupportEnum } from "$types/index.d";
import { APIInterceptor, SupportEnum } from "$types/apiInterceptors";

import config from "$aero/config";
const { aeroPrefix } = config;
Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/concealer/launchQueue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor, SupportEnum } from "$types/index.d";
import { APIInterceptor, SupportEnum } from "$types/apiInterceptors";

import { afterPrefix } from "$shared/getProxyUrl";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
APIInterceptor,
ExposedContextsEnum,
proxifiedObjGeneratorContext,
} from "$types/index.d";
} from "$types/apiInterceptors";

import locationProxy from "$shared/proxyLocation";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor } from "$types/index.d";
import { APIInterceptor } from "$types/apiInterceptors";
import { proxyLocation } from "$shared/proxyLocation";

/**
Expand Down
8 changes: 2 additions & 6 deletions src/AeroSandbox/src/interceptors/concealer/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// Not finished

import config from "$aero/config";
const { flags } = config;

import { afterPrefix } from "$shared";
import { afterPrefix } from "$shared/getProxyUrl";

import { proxyLocation } from "$shared/proxyLocation";

import proxyMessage from "$shared/proxyMessage";
import { APIInterceptor, SupportEnum } from "$types/index.d";
import { APIInterceptor, SupportEnum } from "$types/apiInterceptors";

export default [
// Entries
Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/concealer/payment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor, SupportEnum } from "$types/index.d";
import { APIInterceptor, SupportEnum } from "$types/apiInterceptors";

import { proxyGetString } from "$shared/stringProxy";

Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/concealer/presentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor, SupportEnum } from "$types/index.d";
import { APIInterceptor, SupportEnum } from "$types/apiInterceptors";

import { proxyGetString } from "$shared/stringProxy";

Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/concealer/push.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor, ExposedContextsEnum } from "$types/index.d";
import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors";
import { proxyGetString } from "$shared/stringProxy";

export default {
Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/concealer/secure.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor, ExposedContextsEnum } from "$types/index.d";
import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors";

import config from "config";
const { flags } = config;
Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/loc/history.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor, ExposedContextsEnum } from "$types/index.d";
import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors";

import rewriteSrc from "$shared/src";

Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/loc/open.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor, ExposedContextsEnum } from "$types/index.d";
import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors";

import rewriteSrc from "$shared/src";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This whole file encompasses the {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API WebAuthn}, {@link https://developer.mozilla.org/en-US/docs/Web/API/FedCM_API FedCM}, {@link https://wicg.github.io/web-otp WebOTP} APIs
*/

import { APIInterceptor, ExposedContextsEnum } from "$types/index.d";
import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors";

import { proxyLocation } from "$shared/proxyLocation";
import { afterPrefix } from "$shared/getProxyUrl";
Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/req/eventSource.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
APIInterceptor,
SpecialInterceptionFeaturesEnum,
} from "$types/index.d";
} from "$types/apiInterceptors";

import { proxyConstructString } from "$shared/stringProxy";

Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/req/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor, ExposedContextsEnum } from "$types/index.d";
import { APIInterceptor, ExposedContextsEnum } from "$types/apiInterceptors";
import { handleFetchEvent } from "$aero_browser/util/swlessUtils";

export default {
Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/req/wrtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AltProtocolEnum,
APIInterceptor,
ExposedContextsEnum,
} from "$types/index.d";
} from "$types/apiInterceptors";

import config from "$aero/config";
const { wrtcBackends } = config;
Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/req/ws.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AltProtocolEnum, APIInterceptor } from "$types/index.d";
import { AltProtocolEnum, APIInterceptor } from "$types/apiInterceptors";

import { BareClient } from "@mercuryworkshop/bare-mux";

Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/req/wt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor } from "$types/index.d";
import { APIInterceptor } from "$types/apiInterceptors";

// Only supported on Chromium
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/storage/iDB.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor } from "$types/index.d";
import { APIInterceptor } from "$types/apiInterceptors";

import config from "$aero/config";

Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/storage/sharedStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from "$aero/config";
import { APIInterceptor } from "$types/index.d";
import { APIInterceptor } from "$types/apiInterceptors";
const { prefix } = config;

import { storageNomenclature } from "./shared";
Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/interceptors/storage/sql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIInterceptor, SupportEnum } from "$types/index.d";
import { APIInterceptor, SupportEnum } from "$types/apiInterceptors";

import config from "$aero/config";
const { prefix } = config;
Expand Down
2 changes: 1 addition & 1 deletion src/AeroSandbox/src/sandboxers/JS/JSRewriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
aerogelParser,
astParser,
astWalker,
} from "../../../types/aeroSandbox";
} from "../../../types/rewriters/js";

import ASTRewriter from "./backends/AST";
import AeroGel from "./backends/AeroGel";
Expand Down
96 changes: 46 additions & 50 deletions src/AeroSandbox/src/sandboxers/JS/backends/AeroGel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
AeroGelConfig,
aerogelParser,
keywordReplacementType
} from "../../../../types/index";
AeroGelConfig,
aerogelParser,
keywordReplacementType,
} from "../../../../types/aeroSandbox";

//import esniff from "esniff";

Expand All @@ -11,25 +11,25 @@ var INCLUDE_ESNIFF: boolean;

// TODO: Setup test cases
export default class AeroGel {
config: AeroGelConfig;
constructor(config: AeroGelConfig) {
this.config = config;
}
applyNewConfig(config: AeroGelConfig) {
this.config = config;
}
static supportedParsers(): aerogelParser[] {
let supports: aerogelParser[] = [];
if (INCLUDE_ESNIFF) supports.push("esniff");
return supports;
}
/** This essentially the rewriter
* @param script The script to jail. Before it is jailed the let/const to fake vars RegExp rewriting occurs.
* @param isModule Module scripts don't need to be rewritten because they don't require fake vars for scope emulation since module scripts run in their own isolated scope.
* @example TODO: Provide an example
*/
jailScript(script: string, isModule: boolean) {
return /* js */ `
config: AeroGelConfig;
constructor(config: AeroGelConfig) {
this.config = config;
}
applyNewConfig(config: AeroGelConfig) {
this.config = config;
}
static supportedParsers(): aerogelParser[] {
let supports: aerogelParser[] = [];
if (INCLUDE_ESNIFF) supports.push("esniff");
return supports;
}
/** This essentially the rewriter
* @param script The script to jail. Before it is jailed the let/const to fake vars RegExp rewriting occurs.
* @param isModule Module scripts don't need to be rewritten because they don't require fake vars for scope emulation since module scripts run in their own isolated scope.
* @example TODO: Provide an example
*/
jailScript(script: string, isModule: boolean) {
return /* js */ `
!() => {
${isModule ? script : this.rewriteScript(script)}
}().call({
Expand All @@ -38,10 +38,10 @@ export default class AeroGel {
location: ${this.config.objPaths.proxy.location}
});
`;
}
/** This method is specifically for `var keyword rewriting` */
rewriteScript(script: string): string {
/*
}
/** This method is specifically for `var keyword rewriting` */
rewriteScript(script: string): string {
/*
if (INCLUDE_ESNIFF) {
let letIndicies = [];
let constIndicies = [];
Expand Down Expand Up @@ -73,27 +73,23 @@ export default class AeroGel {
script = this.replaceKeywords(script, keywordReplacements);
}
*/
return script;
}
replaceKeywords(
str: string,
keywordReplacements: keywordReplacementType
): string {
const charArr = Array.from(str);
let totalAddedToIndex = 0;
for (const [indexStr, replacementData] of Object.entries(
keywordReplacements
)) {
const { keywordLen, replacementStr } = replacementData;
const index = parseInt(indexStr);
const replacementArr = Array.from(replacementStr);
totalAddedToIndex += replacementArr.length - keywordLen;
charArr.splice(
index + totalAddedToIndex,
keywordLen,
replacementStr
);
}
return charArr.join("");
}
return script;
}
replaceKeywords(
str: string,
keywordReplacements: keywordReplacementType
): string {
const charArr = Array.from(str);
let totalAddedToIndex = 0;
for (const [indexStr, replacementData] of Object.entries(
keywordReplacements
)) {
const { keywordLen, replacementStr } = replacementData;
const index = parseInt(indexStr);
const replacementArr = Array.from(replacementStr);
totalAddedToIndex += replacementArr.length - keywordLen;
charArr.splice(index + totalAddedToIndex, keywordLen, replacementStr);
}
return charArr.join("");
}
}
1 change: 0 additions & 1 deletion src/AeroSandbox/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"include": [
"src/**/*.ts",
"build/customBuilds/**/*.ts",
"./config.ts",
"types/**/*.d.ts",
"src/interceptors/concealer/element.ts.old",
Expand Down
7 changes: 4 additions & 3 deletions src/AeroSandbox/types/$aero.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { AeroSandboxLogger } from "$aero/src/shared/Loggers";
import type { BareTransport } from "@mercuryworkshop/bare-mux";
import type { AeroSandboxLogger } from "$shared/Loggers";
import type BareClient from "@mercuryworkshop/bare-mux";

interface AeroGlobalType {
export interface AeroGlobalType {
$sec: {
csp: string;
init: string;
};
$bc: BareClient;
logger: AeroSandboxLogger;
prefix: string;
}

declare global {
Expand Down
21 changes: 21 additions & 0 deletions src/AeroSandbox/types/aeroSandbox.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { SupportEnum, InterceptionFeaturesEnum } from "$types/apiInterceptors";

import type { BareTransport } from "@mercuryworkshop/bare-mux";

export interface AeroSandboxConfig {
proxyConfig: ProxyConfig;
/** These enum members enable code inside of the Proxy handler that provide other things you may want to use AeroSandbox for */
specialInterceptionFeatures?: InterceptionFeaturesEnum;
supports: SupportEnum;
proxyGlobalContext: "$aero";
}

// This is the typical proxy config. This is only what is used to format and unformat urls.
export type ProxyConfig = {
BareTransport: BareTransport;
prefix: string;
encodeUrl: (url: string) => string;
decodeUrl: (url: string) => string;
// This is for WebRTC proxying. The API is disabled, if this isn't provided.
webrtcTurnServers?: string[];
};
Loading

0 comments on commit b05984c

Please sign in to comment.