Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
**Vulnerability:** `CustomEmployeeManager.Register` accepted arbitrary employee IDs without validation, which were later used directly in `Path.Combine` to construct image loading paths, enabling path traversal (CWE-22).
**Learning:** Identifiers provided by mods or external sources must be treated as untrusted input and validated before being used in file system operations.
**Prevention:** Validate input strings that form part of a file path before concatenating them. Reject them if they contain directory traversal characters like `..`, `Path.DirectorySeparatorChar`, `Path.AltDirectorySeparatorChar`, or any invalid filename characters (using `Path.GetInvalidFileNameChars()`).
## 2024-10-31 - Defense-in-depth Path Traversal in UI Fallbacks
**Vulnerability:** Path traversal vulnerability in `CustomEmployeeManager.SetPortrait` via `employeeId` bypassing registration checks during direct method calls or deserialization.
**Learning:** Adding standard early-return security checks to prevent path traversal skips necessary fallback UI state logic later in the method (like setting default colors).
**Prevention:** Wrap vulnerable file-system operations in conditional blocks instead of returning early, guaranteeing the fallback UI state logic is still applied.
12 changes: 9 additions & 3 deletions src/API/CustomEmployeeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -891,10 +891,16 @@ 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: Validate employeeId to prevent path traversal attacks during file system operations.
// If invalid, we skip file loading and let the UI fall back to its default state instead of returning early.
if (!string.IsNullOrEmpty(employeeId) && employeeId.IndexOfAny(Path.GetInvalidFileNameChars()) < 0 && !employeeId.Contains(".."))
{
string candidate = Path.Combine(assetsDir, employeeId + ext);
if (File.Exists(candidate)) { imagePath = candidate; break; }
foreach (var ext in new[] { ".jpg", ".png" })
{
string candidate = Path.Combine(assetsDir, employeeId + ext);
if (File.Exists(candidate)) { imagePath = candidate; break; }
}
}

if (imagePath != null)
Expand Down
8 changes: 7 additions & 1 deletion src/GameLayer/Patches/Networking/CablePositionsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@
}
while (Interlocked.CompareExchange(ref _nextCableId, baseId + 1, current) != current);

MelonLogger.Msg($"[CablePatch] Cable ID counter set to {baseId + 1}");
try { LogBaseIdUpdate(baseId + 1); } catch { }

Check warning on line 70 in src/GameLayer/Patches/Networking/CablePositionsPatch.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/GameLayer/Patches/Networking/CablePositionsPatch.cs#L70

Handle the exception or explain in a comment why it can be ignored.
}

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private static void LogBaseIdUpdate(int nextId)
{
MelonLogger.Msg($"[CablePatch] Cable ID counter set to {nextId}");
}

public static int PeekNextId() => _nextCableId;
Expand Down
Loading