-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
能否添加禁用 eval
、Function
这类动态执行代码的选项
#87
Comments
现在我确实尝试这样做: globalThis.eval = function() {
throw new Error('eval is not available')
}
const proxyFunctionConstructor = new Proxy(Function.prototype.constructor, {
apply() {
throw new Error('Dynamic code execution is not allowed.')
},
construct() {
throw new Error('Dynamic code execution is not allowed.')
},
})
Object.defineProperty(Function.prototype, 'constructor', {
value: proxyFunctionConstructor,
writable: false,
configurable: false,
enumerable: false,
})
globalThis.Function = proxyFunctionConstructor 但这样的做法没完全搞清楚还有没有其他方式绕过,所以想请教一下能不能在底层禁用,如果加起来麻烦那就继续用这种方式先 :) |
好的,下个版本我会支持 |
我想了解下, try {
console.log(eval('2 + 3'))
} catch (err) {
console.log(err)
}
try {
const add2 = new Function('a', 'b', 'return a + b')
console.log(add2(2, 3))
} catch (err) {
console.log(err)
}
try {
const Fn = function () {}.constructor
const add = new Fn('a', 'b', 'return a + b')
console.log(add(2, 3))
} catch (err) {
console.log(err)
} |
好的,有空我试试 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你好,请问能否添加禁用
eval
、Function
这类动态执行代码的选项,类似 Node.jsvm.createContext
选项中的codeGeneration.strings
:https://nodejs.org/docs/v22.11.0/api/vm.html#vmcreatecontextcontextobject-options
The text was updated successfully, but these errors were encountered: