Skip to content

Fix Issue #2109: Implement V8 bytecode-only security enhancement - #2151

Closed
caiyunbo666 wants to merge 96 commits into
Tencent:unity-3.0.0from
caiyunbo666:add-lua-backend-tests
Closed

Fix Issue #2109: Implement V8 bytecode-only security enhancement#2151
caiyunbo666 wants to merge 96 commits into
Tencent:unity-3.0.0from
caiyunbo666:add-lua-backend-tests

Conversation

@caiyunbo666

Copy link
Copy Markdown

Description

This PR implements the security enhancement requested in Issue #2109 to remove V8's source code compilation functionality and allow only bytecode loading for enhanced security.

Changes Made

Core Security Implementation

  1. Modified unity/native_src/Src/JSEngine.cpp

    • Disabled source code compilation in Eval() function
    • Added bytecode loading support for .cbc and .mbc files
    • Implemented security checks to reject source code execution
  2. Modified unity/native_src/Src/BackendEnv.cpp

    • Disabled source module loading in FetchModuleTree()
    • Added bytecode module loading support
    • Enhanced V8 initialization with security flags:
      • --no-lazy
      • --no-flush-bytecode
      • --no-enable-lazy-source-positions
      • --disable-source-maps
      • --disable-source-positions
  3. Enhanced unity/v8cc/v8cc.cc

    • Improved bytecode compiler with security features
    • Added security flags to compilation process
    • Enhanced error handling and validation

Security Features

  • Source Code Compilation Disabled: All .js and .mjs files are rejected at runtime
  • Bytecode-Only Execution: Only .cbc (CommonJS) and .mbc (ES Module) files are accepted
  • Enhanced Protection: Prevents external code execution and reverse engineering
  • Runtime Security: Eliminates dynamic code execution vulnerabilities

Benefits

  1. Code Protection: Prevents reverse engineering of JavaScript code
  2. Runtime Security: Prevents code injection attacks
  3. Compliance: Meets security requirements for embedded systems

Breaking Changes

  • Source Code Execution: Direct JavaScript source code execution is no longer supported
  • Module Loading: Source modules (.js, .mjs) are rejected
  • Development Workflow: Requires compilation step using v8cc tool

Migration Guide

For existing projects:

  1. Compile all .js files to .cbc using the v8cc tool
  2. Update loaders to serve bytecode files
  3. Update build processes to include bytecode compilation

Related Issue

Closes #2109

chexiongsheng and others added 28 commits July 3, 2025 20:14
…cent#2112)

* test: arraybuffer from c# should be copied

* fix: arraybuffer from c# should be copied

---------

Co-authored-by: bingcongni <bingcongni@tencent.com>
(cherry picked from commit 53ae303c34c9169a1f38109a417f6ae2b9439d61)

Co-authored-by: corejiang <corejiang@tencent.com>
Co-authored-by: corejiang <corejiang@tencent.com>
…ph方法导致死循环) (Tencent#2126)

2.异步加载 还没有postload时 缓存了错误的空方法复原导致空指针调用崩溃(两个条件:1. postload没有调用 2. js module加载失败,例如删了ts和js被删了 但是TS代理蓝图还在使用)
* [unity]test: 增加无效UnityEngine.Object实例传输的用例

* [untiy]feat: il2cpp模式下将无效UnityEngine.Object实例以null对象传递给脚本

* [unity]feat: 优化unity引擎对象的判空实现

* [unity] test: 在非unity环境下屏蔽PassDestroyedUnityObjectTest用例

---------

Co-authored-by: corejiang <corejiang@tencent.com>
…encent#2130)

* [unreal]修复静态绑定中作为参数的std::function类型的参数如果包含TArray等容器类的时候,自动生成的TS声明会被错误的添加cpp.前缀的问题

* 通过clang-format格式化
… JS-C# calls

- Add exception handling for InspectorTick in both Default and IL2CPP JsEnv
- Implement timeout mechanism for WaitDebugger to prevent infinite loops
- Add V8 exception catching in native JSEngine.cpp
- Enhance BackendEnv.cpp with C++ exception protection
- Add comprehensive test cases for multi-layer debugging scenarios
- Include Unity test script for runtime verification
- Add CPU optimization to reduce resource usage during debugging
- Convert all Chinese comments to English to match project style
- Remove MD documentation files as requested
- Remove test files with Chinese comments
- Ensure all comments follow the original project's English convention
@chexiongsheng

Copy link
Copy Markdown
Collaborator

我看你的提交是实现字节码?
#2109 的重点是“只能”加载字节码,换句话说修改v8并把v8的源码解释给移除。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants