Hello, i am trying to implement a regular expression to filter for directory traversal. Some of you all ready know that i pass a file path to a router as a session variable attached to an input name. Thus, the random name of the input is placed as a value to the session key like:
$_SESSION['Path']['Animalia/Arthropoda/Insecta'] = base64_encode(random_bytes(8));
even though it is not typically possible to alter the session variable, directory traversal exists. I like to be thorough and filter even a session variable before using it. Atleast on a dedicated server.
i have set up the following regular expression because an array of possible values is impossible with taxonomy:
if (preg_match("/^[a-z\/]{1,128}$/i", $path) === 1) {
//then file path is clear for inclusion
}
is this correct? i am not very good with regex, so i want to be sure that this is a solid filter.