Skip to content

Commit 982ef5f

Browse files
committed
fix: use sandybox for webcrack
1 parent 2c56bb3 commit 982ef5f

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
"pythonstack.js": "^1.0.2",
204204
"qpdf-wasm-esm-embedded": "^1.1.1",
205205
"qrcode": "^1.5.1",
206+
"sandybox": "^1.1.2",
206207
"qrcode-parser": "^2.1.3",
207208
"qrcode-terminal-nooctal": "^0.12.1",
208209
"randexp": "^0.5.3",

pnpm-lock.yaml

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/js-unobfuscator/js-unobfuscator.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
<script setup lang="ts">
2+
import Sandybox from 'sandybox';
23
import { webcrack } from 'webcrack';
34
45
const input = ref('');
56
const result = computedAsync(async () => {
67
try {
7-
return await webcrack(input.value);
8+
const inputValue = input.value;
9+
const sandbox = await Sandybox.create();
10+
const iframe = document.querySelector('.sandybox') as HTMLIFrameElement;
11+
iframe?.contentDocument?.head.insertAdjacentHTML(
12+
'afterbegin',
13+
'<meta http-equiv="Content-Security-Policy" content="default-src \'none\';">',
14+
);
15+
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
16+
17+
async function evalCode(code: string) {
18+
const fn = await sandbox.addFunction(`() => ${code}`);
19+
return Promise.race([
20+
fn(),
21+
sleep(10_000).then(() => Promise.reject(new Error('Sandbox timeout'))),
22+
]).finally(() => sandbox.removeFunction(fn));
23+
}
24+
25+
return await webcrack(inputValue, { sandbox: evalCode });
826
}
927
catch (e: any) {
1028
return {
@@ -16,6 +34,7 @@ const result = computedAsync(async () => {
1634
</script>
1735

1836
<template>
37+
<iframe class="sandybox" style="display:none" title="sandbox" />
1938
<CInputText
2039
v-model:value="input"
2140
placeholder="Your obfuscate Javascript code"

0 commit comments

Comments
 (0)