The root cause of the vulnerability is the isValidMedia function in src/media/parse.ts, which uses a weak allowlist for path validation. It explicitly permits absolute paths, directory traversal, and home directory specifiers. This allows a malicious actor to craft a MEDIA: directive (e.g., MEDIA:/etc/passwd) that passes this initial check.
The malicious path is then processed by the stageSandboxMedia function in src/auto-reply/reply/stage-sandbox-media.ts. Prior to the fix, this function would take the unsanitized path and attempt to copy the specified file into a sandbox directory for media attachments. This action of reading and copying the file constitutes the Local File Inclusion (LFI) vulnerability, as it allows an attacker to exfiltrate the contents of any file the application has read access to.
The patch mitigates this by adding a strict check within stageSandboxMedia using assertSandboxPath to ensure that any local file path is confined to the designated media directory, thus preventing access to arbitrary files on the system.