Toolvito

Works on this device

Path Traversal Sanitizer Tester

Check whether a path sanitizer keeps paths inside a base folder. Type the base folder and the paths a visitor might send. For each path the tool decodes it, runs the sanitizer, joins it to the base, normalises it by stated POSIX or Windows rules, and says whether it escapes. It tests the logic on text only, not a server.

Enter your values

Your values

The folder that every path must stay in, as an absolute path such as /srv/app/uploads.

One path on each line, as a visitor might send it. Spaces are kept. Empty lines are skipped.

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose Test the paths.

How to use the path traversal sanitizer tester

  1. Choose the path rules: POSIX (Linux, macOS) or Windows.
  2. Type the base folder that every path must stay in, as an absolute path.
  3. Type the paths to test, one on each line. The starting list has common tricks.
  4. Choose the sanitizer to test, and whether it runs before or after the percent-decoding.
  5. Choose Test the paths. Each row shows the path after each step and whether it stays inside the base.

The steps for each path

  1. Decode 0, 1 or 2 times, as Python's urllib.parse.unquote does: %2e becomes ., bytes that are not UTF-8 become U+FFFD, and a % without two hexadecimal digits stays.
  2. Sanitize with the chosen filter: remove ../ and ..\ once, remove them until none is left, refuse a path with .., or keep only the last part (basename).
  3. Join the result to the base. An absolute path takes the place of the base. On Windows, a path that starts with \ keeps the drive of the base, and a path on another drive drops the base.
  4. Normalise by the rules of Python's posixpath.normpath or ntpath.normpath: remove . and empty parts, and let .. remove the part before it; .. stops at the root.
  5. Compare: the path is inside when it equals the base or starts with the base and a separator. On Windows capital letters do not count.

Worked example

With the base /srv/app/uploads and the filter that removes ../ once, the path ....//....//etc/passwd becomes ../../etc/passwd after the filter, which normalises to /srv/etc/passwd: it escapes the base. Removing ../ until none is left gives etc/passwd, which stays inside.

The path %252e%252e%252fsecret.txt is ../secret.txt after two decodings. If the filter runs after the decoding it removes ../. If it runs before the decoding, as on a server that decodes again later, the path escapes to /srv/app/secret.txt.

Limits you should know

  • The tool works on text only. It does not open any file, folder or server.
  • "Inside the base" is a check of the text. A symbolic link or a junction inside the base can still point outside it. A real server should also resolve links, for example with realpath, and compare again.
  • Windows has more rules than this page uses: trailing dots and spaces are removed by Win32, short 8.3 names, alternate data streams and reserved device names. The page follows the rules of Python's ntpath, which do not include them.
  • A safe design decodes once, refuses or resolves the path, and compares the final path with the base, as this page does in its last step.

Related tools