Skip to content

Commit

Permalink
improve blacklist for modconf
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed May 19, 2024
1 parent 94d980e commit c588d10
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
3 changes: 0 additions & 3 deletions Website/src/components/ModConfView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ export const ModConfView = React.forwardRef<any, { children: string; modid: stri
require: internalRequire,
include: internalInclude,
fetch: internalFetch,
eval: () => {
throw new Error("Module tried to execute eval()!");
},
}),
[]
);
Expand Down
6 changes: 3 additions & 3 deletions Website/src/native/IsolatedEval/IsoDocument.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { IsolatedEvalError } from "./IsolatedEvalError";
import { IsolatedFunctionBlockError } from "./IsolatedFunctionBlockError";

class IsoDocument extends Document {
public constructor() {
super();
}

public write(...text: string[]): void {
throw new IsolatedEvalError(`"document.write()" has been blacklisted.`);
throw new IsolatedFunctionBlockError("document.write()");
}

public writeln(...text: string[]): void {
throw new IsolatedEvalError(`"document.writeln()" has been blacklisted.`);
throw new IsolatedFunctionBlockError("document.writeln()");
}
}

Expand Down
11 changes: 11 additions & 0 deletions Website/src/native/IsolatedEval/IsolatedFunctionBlockError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IsolatedEvalError } from "./IsolatedEvalError";

class IsolatedFunctionBlockError extends IsolatedEvalError {
constructor(message?: string) {
message = `${message} has been blacklisted`;
super(message);
this.name = "IsolatedFunctionBlockError";
}
}

export { IsolatedFunctionBlockError };
16 changes: 8 additions & 8 deletions Website/src/native/IsolatedEval/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Build } from "../Build";
import { IScope } from "@nyariv/sandboxjs/dist/node/executor";
import { Native } from "../Native";
import { IsoDocument } from "./IsoDocument";
import { IsolatedEvalError } from "./IsolatedEvalError";
import { IsolatedFunctionBlockError } from "./IsolatedFunctionBlockError";

class IsolatedEval<T = any> {
private readonly _sandbox: Sandbox = new Sandbox();
Expand Down Expand Up @@ -40,25 +40,25 @@ class IsolatedEval<T = any> {
Build: Build,
Native: Native,
eval() {
throw new IsolatedEvalError(`"eval()" has been blacklisted.`);
throw new IsolatedFunctionBlockError("eval()");
},
atob() {
throw new IsolatedEvalError(`"atob()" has been blacklisted.`);
throw new IsolatedFunctionBlockError("atob()");
},
btoa() {
throw new IsolatedEvalError(`"btoa()" has been blacklisted.`);
throw new IsolatedFunctionBlockError("btoa()");
},
encodeURI() {
throw new IsolatedEvalError(`"encodeURI()" has been blacklisted.`);
throw new IsolatedFunctionBlockError("encodeURI()");
},
encodeURIComponent() {
throw new IsolatedEvalError(`"encodeURIComponent()" has been blacklisted.`);
throw new IsolatedFunctionBlockError("encodeURIComponent()");
},
decodeURI() {
throw new IsolatedEvalError(`"decodeURI()" has been blacklisted.`);
throw new IsolatedFunctionBlockError("decodeURI()");
},
decodeURIComponent() {
throw new IsolatedEvalError(`"decodeURIComponent()" has been blacklisted.`);
throw new IsolatedFunctionBlockError("decodeURIComponent()");
},
};
private readonly _prototypeWhitelist = Sandbox.SAFE_PROTOTYPES;
Expand Down

0 comments on commit c588d10

Please sign in to comment.