The vulnerability lies in the src/media/parse.ts file, where path validation was insufficient. The description correctly points out that the isLikelyLocalPath and isValidMedia functions were the source of the vulnerability.
-
isLikelyLocalPath: The original implementation of this function was too permissive. It recognized patterns like ~/ which could be used to access files in the user's home directory. It also lacked any checks for ../ traversal sequences. The patch completely replaces this function with a new version that calls hasTraversalOrHomeDirPrefix to block these dangerous patterns. The old, vulnerable function was renamed to looksLikeLocalFilePath and is now only used for non-security-critical operations.
-
isValidMedia: This function had a bypass vulnerability when the allowBareFilename option was used. A path like ../../.env could be considered a valid "bare filename" because it has a file extension (.env), allowing it to pass validation. The patch adds a call to the new hasTraversalOrHomeDirPrefix function at the very beginning of isValidMedia, ensuring that any input with traversal patterns is immediately rejected, closing the bypass.
An attacker could exploit this by crafting a MEDIA: directive with a malicious path. For example, MEDIA:../../../../etc/passwd. The parsing logic would identify this as a potential media file. The vulnerable isLikelyLocalPath and isValidMedia functions would fail to block the traversal, and the application would then attempt to load the file from the manipulated path, disclosing its contents. The runtime profile during such an attack would show calls to isLikelyLocalPath and isValidMedia processing the malicious path.