T09 · Insecure Skill Coding Practices
- Location
scripts/LightingSetup.cs:17- Finding
Overbroad and Irreversible Lighting Object Deletion
- Content
View full analysis
Vulnerability Details
File Location:
scripts/LightingSetup.cs, lines 17-28
Vulnerability Type: Unsafe destructive editor operation
Risk Level: MediumVulnerable 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
ClearAllLightingpermanently deletes complete GameObjects usingObject.DestroyImmediatewithout 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
- A scene contains customized light objects whose names include
"Sun"or"Light", or contains reflection probes. - Those GameObjects contain valuable components, child objects, or scene configuration unrelated to this skill.
- The user invokes
Level Design/Lighting/Clear Lighting, either directly or as part of a workflow. - The method scans the scene and immediately destroys all matching light GameObjects and all reflection-probe GameObjects. ...[truncated 603 chars]
- A scene contains customized light objects whose names include
- Remediation
View remediation
Remediation Suggestions
- Replace
Object.DestroyImmediatewithUndo.DestroyObjectImmediatefor 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
LightorReflectionProbecomponent 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.
- Replace
