mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-10 08:05:00 -04:00
fix: use sandybox for webcrack
This commit is contained in:
parent
b5d3ed6b89
commit
7d8e7e926c
3 changed files with 230 additions and 82 deletions
|
@ -1,10 +1,28 @@
|
|||
<script setup lang="ts">
|
||||
import Sandybox from 'sandybox';
|
||||
import { webcrack } from 'webcrack';
|
||||
|
||||
const input = ref('');
|
||||
const result = computedAsync(async () => {
|
||||
try {
|
||||
return await webcrack(input.value);
|
||||
const inputValue = input.value;
|
||||
const sandbox = await Sandybox.create();
|
||||
const iframe = document.querySelector('.sandybox') as HTMLIFrameElement;
|
||||
iframe?.contentDocument?.head.insertAdjacentHTML(
|
||||
'afterbegin',
|
||||
'<meta http-equiv="Content-Security-Policy" content="default-src \'none\';">',
|
||||
);
|
||||
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
async function evalCode(code: string) {
|
||||
const fn = await sandbox.addFunction(`() => ${code}`);
|
||||
return Promise.race([
|
||||
fn(),
|
||||
sleep(10_000).then(() => Promise.reject(new Error('Sandbox timeout'))),
|
||||
]).finally(() => sandbox.removeFunction(fn));
|
||||
}
|
||||
|
||||
return await webcrack(inputValue, { sandbox: evalCode });
|
||||
}
|
||||
catch (e: any) {
|
||||
return {
|
||||
|
@ -16,6 +34,7 @@ const result = computedAsync(async () => {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<iframe class="sandybox" style="display:none" title="sandbox" />
|
||||
<CInputText
|
||||
v-model:value="input"
|
||||
placeholder="Your obfuscate Javascript code"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue