π‘οΈ Sentinel: [CRITICAL] Fix prefix-matching path traversal bypass in Lua sandbox#20
π‘οΈ Sentinel: [CRITICAL] Fix prefix-matching path traversal bypass in Lua sandbox#20mleem97 wants to merge 1 commit into
Conversation
β¦Lua sandbox Fixes a critical path traversal vulnerability in the Lua sandbox where `String.StartsWith` was used for path validation without ensuring the base directory ended with a directory separator. This allowed prefix-matching bypasses (e.g., `/mod/data-secret` validating against `/mod/data`). Updated `GregIoLuaModule.cs`, `LuaModuleLoader.cs`, and `LuaHotReload.cs` to ensure directory separators are appended before path matching, and also permitted exact path equality where appropriate. Added the corresponding learning to `.jules/sentinel.md`.
|
π Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a π emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
π¨ Severity: CRITICAL
π‘ Vulnerability:
The Lua sandbox (
GregIoLuaModule,LuaModuleLoader,LuaHotReload) relied onString.StartsWithto validate sandboxed file paths. Because the base paths (e.g.,/mod/data) did not have a guaranteed trailing directory separator, an attacker could supply a path that begins with the exact string but maps to a different directory (e.g.,/mod/data-secret). Since/mod/data-secretstarts with/mod/data, theStartsWithcheck would incorrectly pass, granting the sandbox access to restricted files.π― Impact:
A malicious or compromised Lua script could escape its designated sandbox (
datafolder ormoddirectory) to read, modify, or delete sensitive files in adjacent directories that shared the same string prefix, leading to arbitrary file read/write issues.π§ Fix:
Updated the validation logic in the Lua layer:
GregIoLuaModule.cs: EnsureddataDirFullappends a trailing directory separator before prefix matching, while still permitting an exact path match.LuaModuleLoader.cs: Ensured both the_modRootand_sharedRootdirectories use a trailing separator before callingStartsWith().LuaHotReload.cs: Ensured the_watchRootdirectory appends a trailing separator before prefix matching.β Verification:
dotnet build gregCore.csproj -c Release.sentinel.mdjournal.PR created automatically by Jules for task 11667858838311463278 started by @mleem97