T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/LightingSetup.cs:17
- Finding
- Overbroad and Irreversible Lighting Object Deletion## Vulnerability Details **File Location**: `scripts/LightingSetup.cs`, lines 17-28 **Vulnerability Type**: Unsafe destructive editor operation **Risk Level**: Medium ### Vulnerable Code ```csharp // Remove all lights var lights = Object.FindObjectsOfType<Light>(); foreach (var light in lights) { if (light.gameObject.name.Contains("Sun") || light.gameObject.name.Contains("Light")) Object.DestroyImmediate(light.gameObject); } // Remove reflection probes var probes = Object.FindObjectsOfType<ReflectionProbe>(); foreach (var probe in probes) Object.DestroyImmediate(probe.gameObject); ``` ### Technical Analysis `ClearAllLighting` permanently deletes complete GameObjects using `Object.DestroyImmediate` without registering the operation with Unity's Undo system or requesting user confirmation. Light selection is based on broad, case-sensitive substring matching against `"Sun"` and `"Light"`, rather than verifying that an object was created and is owned by this tool. The method also deletes every discovered reflection-probe GameObject without any ownership check. Because the entire GameObject is destroyed, unrelated components, scripts, children, and project-specific configuration attached to matching objects are removed as well. This is an unsafe editor-coding practice rather than privilege escalation: the command operates with the permissions of the Unity Editor user and does not obtain additional system privileges. ### Attack Path 1. A scene contains customized light objects whose names include `"Sun"` or `"Light"`, or contains reflection probes. 2. Those GameObjects contain valuable components, child objects, or scene configuration unrelated to this skill. 3. The user invokes `Level Design/Lighting/Clear Lighting`, either directly or as part of a workflow. 4. The method scans the scene and immediately destroys all matching light GameObjects and all reflection-probe GameObjects. ...[truncated 603 chars]
- Remediation
- ## Remediation Suggestions - Replace `Object.DestroyImmediate` with `Undo.DestroyObjectImmediate` for editor-initiated deletion. - Require explicit confirmation before bulk removal, using `EditorUtility.DisplayDialog`. - Track tool-created objects with a dedicated marker component, stable identifier, or parent hierarchy. - Delete only objects proven to be owned by the tool rather than relying on name substrings. - Consider removing only the intended `Light` or `ReflectionProbe` component when deleting the complete GameObject is unnecessary. - Register all created replacement objects with `Undo.RegisterCreatedObjectUndo`. - Mark the affected scene dirty and document the exact deletion scope before execution.
