T09 · Insecure Skill Coding Practices
- Location
references/unity-storage.md:986- Finding
Path Traversal Through Unsanitized Save-Slot Names
- Content
View full analysis
{ if (success) { Debug.Log($"Save slot {slotName} was saved: {filePath}"); } else { Debug.LogError($"Save slot {slotName} could not be saved"); } }); } public void LoadGameData( string slotName, System.Action onLoaded) { if (m_Fs == null) { onLoaded?.Invoke(null); return; } string filePath = $"{m_DataDir}/saves/{slotName}.json"; if (!m_Fs.AccessSync(filePath)) { onLoaded?.Invoke(null); return; } m_Fs.ReadFile(filePath, "utf8", (content) => { try { GameSaveData data = JsonUtility.FromJson(content); onLoaded?.Invoke(data); } catch (System.Exception) { onLoaded?.Invoke(null); } }); } public void DeleteSaveSlot(string slotName) { if (m_Fs == null) return; string filePath = $"{m_DataDir}/saves/{slotName}.json"; m_Fs.Unlink(filePath, (success) => { Debug.Log(success ? $"Save slot {slotName} was deleted" : $"Save slot {slotName} could not be deleted"); }); } ``` ### Technical Analysis The public methods insert `slotName` directly into a filesystem path without validating its syntax or checking the canonical destination. An input containing traversal sequences or path separators, such as `../. ...[truncated 1947 chars]- Remediation
View remediation
