The vulnerability exists in the @hapi/inert package, which is used for serving static files in Hapi.js applications. The core of the issue lies in the response function within lib/file.js. This function is responsible for handling file requests and ensuring that file access is restricted to a specified directory (a feature known as "confinement").
The vulnerability arises from an incorrect implementation of this confinement check. The original code checked if the resolved file path started with the configured directory's path. However, this check was a simple string prefix comparison. This meant that if a sibling directory existed with a name that started with the same characters as the intended directory (e.g., a served directory /var/www/static and a sibling /var/www/static-secret), an attacker could use path traversal techniques (../) to access files within that sibling directory.
The patch corrects this flaw by making the path validation more stringent. Instead of just checking for a matching prefix, the updated code in the response function now verifies that the requested path is either the confined directory itself or is located inside it by checking for the presence of a path separator (/ or \) immediately following the directory name in the path. This ensures that sibling directories are no longer accessible, effectively mitigating the path traversal vulnerability. Any runtime profile of a vulnerable application would show the response function being called during the exploitation of this vulnerability.