Back to skill

Security audit

Unity3D 游戏开发助手

Security checks for vulnerabilities and agentic risk

Overview

This Unity helper is purpose-aligned but exposes an unauthenticated local bridge that can modify projects, write code, and trigger builds, so it should be reviewed before use.

Install only if you are comfortable running a local Unity control server. Use it on version-controlled projects, keep the bridge stopped when not actively using it, avoid untrusted local processes or webpages while it is running, and review or harden the bridge with authentication, path validation, and confirmations before using script creation, deletion, scene opening, or build endpoints.

Vulnerability Patterns
  • Unauthorized Access and Privilege EscalationObtains permissions beyond the task's legitimate needs
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
Findings (3)

T05 · Unauthorized Access and Privilege Escalation

Error
Location
UnityBridge_Editor.cs:68
Finding

Unauthenticated Local HTTP Control Plane Permits Destructive Unity Operations

Content
View full analysis

Vulnerability Details

File Location: UnityBridge_Editor.cs, lines 68-145
Vulnerability Type: Missing authentication and authorization on privileged API endpoints
Risk Level: High

Vulnerable Code

csharp
private static void RunServer()
{
    try
    {
        _listener = new HttpListener();
        _listener.Prefixes.Add($"http://localhost:{_port}/");
        _listener.Start();

        while (_isRunning)
        {
            try
            {
                var context = _listener.GetContext();
                ProcessRequest(context);
            }
            catch (HttpListenerException)
            {
                break;
            }
        }
    }
    catch (Exception ex)
    {
        Debug.LogError($"[OpenClaw] Server error: {ex.Message}");
    }
}

private static void ProcessRequest(HttpListenerContext context)
{
    var request = context.Request;
    var response = context.Response;

    string result = "{}";
    int statusCode = 200;

    try
    {
        switch (request.Url.AbsolutePath.ToLower())
        {
            case "/api/ping":
                result = JsonUtility.ToJson(new { status = "ok", project = GetActiveProjectPath(), unityVersion = Application.unityVersion });
                break;

            case "/api/scene/list":
                result = ListScenes();
                break;

            case "/api/scene/current":
                result = GetCurrentSceneInfo();
                break;

            case "/api/scene/open":
                var scenePath = GetQueryParam(request, "path");
                result = OpenScene(scenePath);
                break;

            case "/api/gameobject/list":
                result = ListGameObjects();
                break;

            case "/api/gameobject/create":
                var objName = GetQueryParam(request, "name") ?? "New GameObject";
                result = CreateGameObject(objName);
                break;

            case "/api/gameobject/delete":
...[truncated 2941 chars]
Remediation
View remediation

Remediation Suggestions

  1. Generate a cryptographically random authentication token for each bridge session.
  2. Require the token in an Authorization: Bearer header on every API request.
  3. Store the token only in process memory or another access-controlled location.
  4. Use POST, PUT, or DELETE for state-changing operations rather than GET.
  5. Validate the HTTP method for every endpoint.
  6. Reject browser-originated requests by validating the Origin header against an explicit allowlist; do not rely on CORS alone.
  7. Add CSRF protection if browser clients are intentionally supported.
  8. Require explicit Unity Editor confirmation for destructive operations such as deletion, source creation, scene replacement, and builds.
  9. Consider using an authenticated named pipe or Unix-domain socket instead of a predictable HTTP listener.
  10. Apply request-size limits, timeouts, rate limits, and audit logging.

T09 · Insecure Skill Coding Practices

Error
Location
UnityBridge_Editor.cs:124
Finding

Path Traversal in Script Creation Enables Arbitrary C# Execution in the Unity Editor

Content
View full analysis

Vulnerability Details

File Location: UnityBridge_Editor.cs, lines 124-128 and 228-252
Additional Location: Connect-UnityEditor.psm1, lines 127-128
Vulnerability Type: Path traversal, arbitrary file write, and unsafe source-code compilation
Risk Level: Critical

Vulnerable Code

csharp
case "/api/script/create":
    var scriptName = GetQueryParam(request, "name");
    var scriptContent = request.InputStream != null ? new StreamReader(request.InputStream).ReadToEnd() : "";
    result = CreateScript(scriptName, scriptContent);
    break;
csharp
private static string CreateScript(string name, string content)
{
    if (string.IsNullOrEmpty(name))
        return JsonUtility.ToJson(new { error = "name_required" });

    var path = $"Assets/Scripts/{name}.cs";
    if (string.IsNullOrEmpty(content))
    {
        content = $@"using UnityEngine;

public class {name} : MonoBehaviour
{{
    void Start()
    {{
        // Auto-generated by OpenClaw
    }}

    void Update()
    {{
        
    }}
}}";
    }

    Directory.CreateDirectory(Path.GetDirectoryName(path));
    File.WriteAllText(path, content);
    AssetDatabase.Refresh();

    return JsonUtility.ToJson(new { success = true, path });
}

The PowerShell client also inserts the name directly into the URL:

powershell
$body = $Content
$result = Invoke-RestMethod -Uri "$UnityBaseUrl/api/script/create?name=$Name" -Method POST -Body $body -ContentType "text/plain"

Technical Analysis

The name query parameter is inserted directly into a filesystem path. The implementation does not reject directory separators, .. traversal components, rooted paths, alternate path separators, or other invalid filename characters. It also does not canonicalize the resulting path and verify that it remains beneath Assets/Scripts.

The request body is written verbatim as C# source code. Calling AssetDatabase.Refresh() causes Unity to import and compile newly created scripts. An at ...[truncated 2000 chars]

Remediation
View remediation

Remediation Suggestions

  1. Restrict script names to valid C# identifiers, for example: ^[A-Za-z_][A-Za-z0-9_]*$
  2. Explicitly reject /, \, .., rooted paths, drive prefixes, null characters, and alternate data-stream syntax.
  3. Build the destination with Path.Combine and obtain its canonical path with Path.GetFullPath.
  4. Obtain the canonical allowed directory path and verify that the destination remains beneath it using an operating-system-appropriate path comparison.
  5. Refuse to overwrite existing files unless the user explicitly approves the operation.
  6. Authenticate and authorize the endpoint.
  7. Require interactive Editor approval before importing or compiling caller-provided source.
  8. Prefer safe, predefined templates and structured parameters instead of accepting arbitrary C# request bodies.
  9. Apply a strict request-body size limit.
  10. URL-encode the Name parameter in the PowerShell client, while retaining all server-side validation.
  11. Consider removing arbitrary source submission entirely if it is not essential to the bridge's operation.

T09 · Insecure Skill Coding Practices

Warning
Location
UnityBridge_Editor.cs:131
Finding

Unrestricted Build Output Path Allows Writes to Attacker-Selected Locations

Content
View full analysis

Vulnerability Details

File Location: UnityBridge_Editor.cs, lines 131-134 and 254-279
Vulnerability Type: Unvalidated filesystem destination
Risk Level: Medium

Vulnerable Code

csharp
case "/api/build":
    var target = GetQueryParam(request, "target") ?? "StandaloneWindows64";
    var outputPath = GetQueryParam(request, "output") ?? "Builds";
    result = BuildProject(target, outputPath);
    break;
csharp
private static string BuildProject(string target, string outputPath)
{
    BuildTarget buildTarget;
    if (!Enum.TryParse(target, out buildTarget))
        buildTarget = BuildTarget.StandaloneWindows64;

    var options = new BuildPlayerOptions
    {
        scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(),
        locationPathName = outputPath,
        target = buildTarget,
        options = BuildOptions.None
    };

    var report = BuildPipeline.BuildPlayer(options);
    return JsonUtility.ToJson(new { 
        success = report.summary.result == BuildResult.Succeeded,
        result = report.summary.result.ToString(),
        totalTime = report.summary.totalTime.ToString(),
        totalErrors = report.summary.totalErrors,
        totalWarnings = report.summary.totalWarnings,
        outputPath
    });
}

Technical Analysis

The output query parameter is passed directly to Unity's BuildPlayerOptions.locationPathName. No canonicalization, allowlist, project-directory confinement, overwrite check, or user approval is applied.

Consequently, a caller can select absolute paths or paths containing traversal components. Unity's build pipeline may then create build files and directories at an unintended writable destination. The exact output layout and overwrite behavior depend on the selected platform and Unity build pipeline.

This issue is reachable through the same unauthenticated API and therefore does not require an authorized PowerShell client.

Attack Path

  1. The vi ...[truncated 968 chars]
Remediation
View remediation

Remediation Suggestions

  1. Configure one dedicated build-output root inside or adjacent to the project.
  2. Resolve the requested destination with Path.GetFullPath.
  3. Verify that the canonical destination remains beneath the approved build root.
  4. Reject rooted paths, traversal components, symbolic-link escapes, and unsupported filename characters.
  5. Require authentication and explicit user confirmation before starting a build.
  6. Check whether the destination already exists and require approval before replacement or deletion.
  7. Apply build concurrency limits and reject requests while another build is active.
  8. Add rate limiting, disk-space checks, cancellation support, and security audit logs.
  9. Use an allowlist for supported BuildTarget values rather than accepting every enum value.
Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Rogue AgentSelf-Modification, Session Persistence
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (20)

Hidden Instructions

High
Category
Prompt Injection
Confidence
60% confidence
Finding

Hidden instructions were detected in comments or invisible text. These could contain malicious directives. Manual review is recommended.

Content

Scanner excerpt · Connect-UnityEditor.psm1 (reported line 1)May include surrounding context.

text
# Unity3D Editor Bridge Script
# 这个脚本需要复制到Unity项目的 Editor/ 目录下
# 它启动一个本地HTTP服务器,接收OpenClaw控制命令

Hidden Instructions

High
Category
Prompt Injection
Confidence
60% confidence
Finding

Hidden instructions were detected in comments or invisible text. These could contain malicious directives. Manual review is recommended.

Content

Scanner excerpt · SKILL.md (reported line 1)May include surrounding context.

md
# Unity3D Editor Bridge Script
# 这个脚本需要复制到Unity项目的 Editor/ 目录下
# 它启动一个本地HTTP服务器,接收OpenClaw控制命令

Hidden Instructions

High
Category
Prompt Injection
Confidence
60% confidence
Finding

Hidden instructions were detected in comments or invisible text. These could contain malicious directives. Manual review is recommended.

Content

Scanner excerpt · TEMPLATES.md (reported line 1)May include surrounding context.

md
# Unity3D Editor Bridge Script
# 这个脚本需要复制到Unity项目的 Editor/ 目录下
# 它启动一个本地HTTP服务器,接收OpenClaw控制命令

Hidden Instructions

High
Category
Prompt Injection
Confidence
60% confidence
Finding

Hidden instructions were detected in comments or invisible text. These could contain malicious directives. Manual review is recommended.

Content

Scanner excerpt · UnityBridge_Editor.cs (reported line 1)May include surrounding context.

text
# Unity3D Editor Bridge Script
# 这个脚本需要复制到Unity项目的 Editor/ 目录下
# 它启动一个本地HTTP服务器,接收OpenClaw控制命令

Missing User Warnings

High
Category
Not specified by scanner
Confidence
97% confidence
Finding

The bridge exposes scene-opening operations over a local HTTP API with no authentication, authorization, or user confirmation. Any local process can invoke it to change editor state, potentially causing data loss, workflow disruption, or opening attacker-chosen project files inside the Unity Editor context.

Content

No source excerpt is available for this finding.

Missing User Warnings

High
Category
Not specified by scanner
Confidence
99% confidence
Finding

This endpoint writes arbitrary script content to Assets/Scripts based on remote input and refreshes the AssetDatabase, which can trigger compilation and subsequent execution paths inside the editor or during play/build. In the context of a Unity Editor bridge, this is effectively arbitrary code injection by any process that can reach the local listener.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The module exposes a destructive delete operation that can remove Unity GameObjects immediately based on a name parameter, with no confirmation prompt, dry-run mode, scope restriction, or validation that the target is the intended object. In an agent-driven workflow, this increases the risk of accidental or induced destructive actions against a live editor session, causing scene corruption, data loss, or disruption of development work.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
89% confidence
Finding

This function creates C# scripts in the Unity project and accepts arbitrary content, but provides no prior disclosure, confirmation, path constraints visible in this module, or review step before writing project files. In an automated skill context, that enables silent modification of source code, which can introduce malicious or unsafe code into the project or overwrite expected development state.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The skill explicitly advertises operations that create scenes, generate scripts, modify assets, and perform automated builds, but it does not warn users that these actions can overwrite project files, alter source code, or trigger costly/destructive changes. In a Unity development context, these are real side-effecting operations, so lack of clear safety messaging increases the risk of accidental project damage or unintended modifications.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
92% confidence
Finding

The architecture description states that the plugin communicates through a local HTTP server, but there is no disclosure of what data may be exposed, whether the port is authenticated, or whether requests are limited to localhost. For a tool that can access Unity projects and editor state, undocumented local server exposure can create privacy and local attack-surface risks.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

The title and all surrounding instructional content in this template library are written in Chinese, which indicates a fixed language presentation. Under the stated policy, forcing a specific language without user opt-in or a documented region-specific justification is a natural-language policy violation.

Content

No source excerpt is available for this finding.

Session Persistence

Medium
Category
Rogue Agent
Confidence
75% confidence
Finding

Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.

Content

Scanner excerpt · UnityBridge_Editor.cs (reported line 28)May include surrounding context.

text
[InitializeOnLoad]
    public class UnityBridge : EditorWindow
    {
        private static HttpListener _listener;
        private static Thread _serverThread;
        private static bool _isRunning = false;
        private static int _port = 18765;

Session Persistence

Medium
Category
Rogue Agent
Confidence
75% confidence
Finding

Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.

Content

Scanner excerpt · UnityBridge_Editor.cs (reported line 76)May include surrounding context.

text
[InitializeOnLoad]
    public class UnityBridge : EditorWindow
    {
        private static HttpListener _listener;
        private static Thread _serverThread;
        private static bool _isRunning = false;
        private static int _port = 18765;

Session Persistence

Medium
Category
Rogue Agent
Confidence
75% confidence
Finding

Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.

Content

Scanner excerpt · UnityBridge_Editor.cs (reported line 87)May include surrounding context.

text
[InitializeOnLoad]
    public class UnityBridge : EditorWindow
    {
        private static HttpListener _listener;
        private static Thread _serverThread;
        private static bool _isRunning = false;
        private static int _port = 18765;

Session Persistence

Medium
Category
Rogue Agent
Confidence
75% confidence
Finding

Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.

Content

Scanner excerpt · UnityBridge_Editor.cs (reported line 99)May include surrounding context.

text
[InitializeOnLoad]
    public class UnityBridge : EditorWindow
    {
        private static HttpListener _listener;
        private static Thread _serverThread;
        private static bool _isRunning = false;
        private static int _port = 18765;

Session Persistence

Medium
Category
Rogue Agent
Confidence
75% confidence
Finding

Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.

Content

Scanner excerpt · UnityBridge_Editor.cs (reported line 325)May include surrounding context.

text
[InitializeOnLoad]
    public class UnityBridge : EditorWindow
    {
        private static HttpListener _listener;
        private static Thread _serverThread;
        private static bool _isRunning = false;
        private static int _port = 18765;

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

Allowing remote triggering of builds without user warning enables unauthorized consumption of developer resources, generation of artifacts, and possible leakage through attacker-controlled output paths. While less severe than code injection, it still grants meaningful control over the editor and filesystem-facing build process.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
88% confidence
Finding

The file includes instructional comments only in Chinese, including setup and behavior descriptions, without offering any language choice or bilingual alternative. This creates a language-specific constraint in natural-language guidance that is not presented as optional or justified.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
79% confidence
Finding

The display name and description are presented only in Chinese, with no indication that the user can choose another language or that the skill is intentionally limited to a Chinese-speaking audience. This may violate language/locale policy guidance when no opt-in or justification is provided.

Content

No source excerpt is available for this finding.

Vague Triggers

Low
Category
Not specified by scanner
Confidence
89% confidence
Finding

This manifest describes a very broad set of capabilities for Unity development but does not provide any specific trigger phrases, activation conditions, or exclusion examples. For manifest files, this can create ambiguity about when the skill should activate versus when a general game-development request should not invoke it.

Content

No source excerpt is available for this finding.