refactor: Functional API, Advanced Transforms, and Secure Sandbox Evaluation#20
refactor: Functional API, Advanced Transforms, and Secure Sandbox Evaluation#20
Conversation
… update related logic in deobfuscation process
…mprove error handling in deobfuscation process
…ents for improved clarity
…ops transformation and enhancing logging conditions
…dback during processing
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
/gemini summary |
Summary of ChangesHello @kuizuo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on a significant refactoring of the deobfuscation library, transitioning to a more functional and simplified API. It introduces a suite of new code transformation capabilities, including advanced transpilation and unminification techniques, while also enhancing security through sandboxed code evaluation. The changes aim to improve the overall robustness, maintainability, and user-friendliness of the deobfuscator. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a large and impressive refactoring that modernizes the API, introduces sandboxing for safer execution, and adds many new features and improvements. While the code quality is generally high, it introduces a critical security vulnerability: an insecure fallback to global.eval() in the deobfuscation engine's virtual machine component. This fallback, which occurs if the isolated-vm sandbox fails or is unavailable, allows an attacker to achieve Remote Code Execution (RCE) on the host system by providing a specially crafted malicious file. It is strongly recommended to remove these fallbacks and ensure untrusted code is only executed within a secure, non-bypassable sandbox. Additionally, I have a major concern about a potential bug in the control flow switch transform.
| try { | ||
| const result = await this.sandbox(code) | ||
| return result as unknown[] | ||
| } | ||
| catch (error) { | ||
| // ignore | ||
| } | ||
|
|
||
| try { | ||
| const result = await global.eval(code) | ||
| return result as unknown[] | ||
| } | ||
| catch (error) { | ||
| deobLogger('global.eval error:', error) | ||
| throw error | ||
| } |
There was a problem hiding this comment.
The VMDecoder.decode function implements an insecure fallback to global.eval() if the sandbox execution fails. The code variable being evaluated contains parts of the untrusted input file being deobfuscated (specifically the string array, rotator, and decoder functions). An attacker can craft a malicious JavaScript file that, when processed by the deobfuscator, executes arbitrary code on the host system. This leads to Remote Code Execution (RCE) in Node.js environments.
| export async function evalCode(sandbox: Sandbox, code: string) { | ||
| try { | ||
| return await sandbox(code) as unknown | ||
| } | ||
| catch (sandboxError) { | ||
| try { | ||
| return global.eval(code) as unknown | ||
| } | ||
| catch (evalError) { | ||
| deobLogger('evalCode error:', evalError) | ||
| throw sandboxError | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
The evalCode function also implements an insecure fallback to global.eval() if the sandbox execution fails. Similar to VMDecoder.decode, this allows for arbitrary code execution if the input code is derived from untrusted sources. In the context of this application, evalCode is used to execute setup code and decoder calls which are extracted from the input file.
| path.node.body.splice(0, 3, ...newStatements); | ||
| this.changes += newStatements.length + 3; |
There was a problem hiding this comment.
The use of path.node.body.splice(0, 3, ...newStatements) assumes that the three statements of the control flow flattening mechanism (sequence declaration, iterator declaration, and the loop) are always the first three statements in the block. However, the @codemod/matchers anyList does not guarantee this; it will find a matching sequence of statements anywhere in the block's body. If there are other statements before the control flow mechanism, this will lead to incorrect code by removing the wrong statements.
A more robust approach would be to capture the matched statements and remove them specifically from the body, for example by finding their indices.
Summary of ChangesThis pull request undertakes a significant refactoring of the deobfuscation library, moving towards a more functional and simplified API. It introduces a comprehensive suite of new code transformation capabilities, including advanced transpilation and unminification techniques, while also enhancing security through sandboxed code evaluation. The changes aim to improve the overall robustness, maintainability, and user-friendliness of the deobfuscator. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
|
…6.0.2 as a dependency
…dling and scope management
No description provided.