# MetaBuilder Security Guide ## Overview MetaBuilder now includes comprehensive security features to protect against malicious code injection, XSS attacks, SQL injection, and other vulnerabilities. This document outlines the security measures implemented and best practices for users. ## Security Features ### 1. Code Scanning All user-generated code (JavaScript, Lua, JSON, HTML) is automatically scanned for security vulnerabilities before execution or saving. #### Scan Levels - **Safe**: No security issues detected - **Low**: Minor warnings that don't pose significant risk - **Medium**: Potential security concerns that should be reviewed - **High**: Serious security issues that require immediate attention - **Critical**: Severe vulnerabilities that block execution/saving ### 2. Sandboxed Lua Execution Lua scripts are executed in a sandboxed environment with the following restrictions: #### Disabled Functions & Modules - **os module**: All operating system functions disabled - `os.execute`, `os.exit`, `os.remove`, `os.rename`, `os.tmpname` - **io module**: All file I/O operations disabled - `io.popen`, `io.tmpfile`, `io.open`, `io.input`, `io.output`, `io.lines` - **File loading**: Dynamic file loading disabled - `loadfile`, `dofile` - **Package loading**: Dynamic library loading disabled - `package.loadlib`, `package.searchpath`, C library path cleared #### Limited Functions - **debug module**: Advanced debugging features limited - `debug.getfenv`, `debug.setfenv` disabled - **Environment manipulation**: Global environment modifications restricted - Direct `_G` manipulation monitored #### Safe Functions Available The sandbox provides access to these safe functions: - Basic: `assert`, `error`, `ipairs`, `next`, `pairs`, `pcall`, `select`, `tonumber`, `tostring`, `type`, `unpack`, `xpcall` - Libraries: `string`, `table`, `math`, `bit32` - Logging: `print`, `log` - Context: `context.data`, `context.user`, `context.kv` ### 3. Execution Timeout All Lua scripts have a maximum execution time of 5 seconds (configurable) to prevent infinite loops and resource exhaustion. ### 4. Pattern Detection The security scanner detects the following malicious patterns: #### JavaScript Threats - **Code Execution** - `eval()` - Dynamic `Function()` constructor - `setTimeout/setInterval` with string arguments - **XSS Vulnerabilities** - `innerHTML` assignments - `dangerouslySetInnerHTML` - `