From 2fbe87240bad073900ec034f5fd2ead8365bcbdb Mon Sep 17 00:00:00 2001 From: mleem97 <52848568+mleem97@users.noreply.github.com> Date: Mon, 17 Aug 2026 00:06:46 +0000 Subject: [PATCH 1/2] Fix path traversal vulnerability in SetPortrait method. --- src/API/CustomEmployeeManager.cs | 15 ++++++++++++--- .../Patches/Networking/CablePositionsPatch.cs | 8 +++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/API/CustomEmployeeManager.cs b/src/API/CustomEmployeeManager.cs index 9b4512b6..1ccf41ef 100644 --- a/src/API/CustomEmployeeManager.cs +++ b/src/API/CustomEmployeeManager.cs @@ -891,10 +891,19 @@ private static void SetPortrait(Transform card, string employeeId) string assetsDir = Path.Combine(MelonEnvironment.UserDataDirectory, "ModAssets"); string? imagePath = null; - foreach (var ext in new[] { ".jpg", ".png" }) + + // [Security] Prevent path traversal by independently validating employeeId before file operations + if (employeeId.IndexOfAny(Path.GetInvalidFileNameChars()) < 0 && !employeeId.Contains("..")) + { + foreach (var ext in new[] { ".jpg", ".png" }) + { + string candidate = Path.Combine(assetsDir, employeeId + ext); + if (File.Exists(candidate)) { imagePath = candidate; break; } + } + } + else { - string candidate = Path.Combine(assetsDir, employeeId + ext); - if (File.Exists(candidate)) { imagePath = candidate; break; } + CrashLog.Log($"[Security] Prevent path traversal in SetPortrait for '{employeeId}'"); } if (imagePath != null) diff --git a/src/GameLayer/Patches/Networking/CablePositionsPatch.cs b/src/GameLayer/Patches/Networking/CablePositionsPatch.cs index 84c3f50c..1aa2c30b 100644 --- a/src/GameLayer/Patches/Networking/CablePositionsPatch.cs +++ b/src/GameLayer/Patches/Networking/CablePositionsPatch.cs @@ -57,6 +57,12 @@ private static bool CreateNewCablePrefix( } } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + private static void LogSetBaseId(int baseId) + { + MelonLogger.Msg($"[CablePatch] Cable ID counter set to {baseId + 1}"); + } + public static void SetBaseId(int baseId) { int current; @@ -67,7 +73,7 @@ public static void SetBaseId(int baseId) } while (Interlocked.CompareExchange(ref _nextCableId, baseId + 1, current) != current); - MelonLogger.Msg($"[CablePatch] Cable ID counter set to {baseId + 1}"); + try { LogSetBaseId(baseId); } catch { } } public static int PeekNextId() => _nextCableId; From 93d466860feab443f4456ab91896235a499cefe8 Mon Sep 17 00:00:00 2001 From: mleem97 <52848568+mleem97@users.noreply.github.com> Date: Mon, 17 Aug 2026 00:08:50 +0000 Subject: [PATCH 2/2] Fix path traversal vulnerability in SetPortrait method.