Skip to content
Open
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-05-24 - Prevent Path Traversal via Arbitrary Identifiers
**Vulnerability:** A path traversal vulnerability existed in `CustomEmployeeManager.SetPortrait` because arbitrary `employeeId` strings from mods were used in `Path.Combine` without being validated.
**Learning:** Even when reading benign assets (like portraits), any string identifier that originates externally must be validated before being used to construct a file path.
**Prevention:** Use `id.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 || id.Contains("..")` to validate these external identifiers rather than relying on directory or environment constraints alone.
17 changes: 14 additions & 3 deletions src/API/CustomEmployeeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -891,10 +891,21 @@ 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" })

// Prevent path traversal by validating the arbitrary employeeId string
bool isSafePath = employeeId.IndexOfAny(Path.GetInvalidFileNameChars()) < 0 && !employeeId.Contains("..");

if (isSafePath)
{
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] Prevented path traversal attempt in SetPortrait for employeeId: {employeeId}");
}

if (imagePath != null)
Expand Down
Loading