Skip to main content
QUICK REVIEW

[Paper Review] A Simple and Intuitive Algorithm for Preventing Directory Traversal Attacks

M. June Flanders|arXiv (Cornell University)|Aug 13, 2019
Web Application Security VulnerabilitiesComputer Science5 citations
TL;DR

This paper presents a lightweight, stack-based algorithm called $sanitize$ that prevents directory traversal attacks by securely canonicalizing user-supplied path strings. The algorithm combines path string canonicalization with whitelisting, is formally proven correct, and is designed to be intuitive, cross-platform, and easily verifiable using symbolic execution, offering a robust and practical defense against path traversal vulnerabilities in web applications.

ABSTRACT

With web applications becoming a preferred method of presenting graphical user interfaces to users, software vulnerabilities affecting web applications are becoming more and more prevalent and devastating. Some of these vulnerabilities, such as directory traversal attacks, have varying defense mechanisms and mitigations that can be difficult to understand, analyze, and test. Gaps in the testing of these directory traversal defense mechanisms can lead to vulnerabilities that allow attackers to read sensitive data from files or even execute malicious code. This paper presents an analysis of some currently used directory traversal attack defenses and presents a new, stack-based algorithm to help prevent these attacks by safely canonicalizing user-supplied path strings. The goal of this algorithm is to be small, easy to test, cross-platform compatible, and above all, intuitive. We provide a proof of correctness and verification strategies using symbolic execution for the algorithm. We hope that the algorithm is simple and effective enough to help move developers towards a unified defense against directory traversal attacks.

Motivation & Objective

  • To address the growing prevalence of directory traversal vulnerabilities in web applications, which are often overlooked despite making up 22% of 2017’s disclosed vulnerabilities.
  • To overcome limitations in existing mitigations—such as memory safety issues, semantic inconsistencies, and lack of portability—by designing a unified, lightweight solution.
  • To provide a simple, self-contained algorithm that is easy to implement, verify, and extend across different programming languages and platforms.
  • To formally prove correctness and enable automated verification using symbolic execution, enhancing developer confidence in secure deployment.

Proposed method

  • The algorithm uses a stack-based approach to process path components, resolving relative path segments like "." and ".." in a controlled manner.
  • It canonicalizes user-supplied path strings by traversing each component and maintaining a stack of valid directory paths, ensuring only safe, absolute paths are generated.
  • The method integrates whitelifying by restricting output to a predefined set of allowed paths, preventing access to sensitive or unauthorized directories.
  • It avoids reliance on the underlying file system or OS-specific path resolution, ensuring cross-platform consistency and portability.
  • The algorithm is formally verified using symbolic execution, enabling automated testing and validation of correctness across diverse input scenarios.
  • The implementation is designed to be minimal and self-contained, requiring no external libraries or system calls, and can be easily adapted to languages with built-in stack or container support.

Experimental results

Research questions

  • RQ1How can a directory traversal defense mechanism be both simple and formally verifiable while remaining secure and cross-platform?
  • RQ2Can a stack-based canonicalization algorithm outperform existing approaches in terms of correctness, safety, and ease of implementation?
  • RQ3To what extent does combining canonicalization with whitelisting improve security without introducing new vulnerabilities?
  • RQ4How effective is symbolic execution in verifying the correctness of a path sanitization algorithm?
  • RQ5Can a lightweight, intuitive algorithm reduce the risk of implementation errors in real-world web application development?

Key findings

  • The $sanitize$ algorithm successfully prevents directory traversal attacks by securely resolving path components using a stack-based approach, ensuring only valid, absolute paths are produced.
  • Formal verification via symbolic execution confirms the algorithm's correctness for all inputs of length up to 12 characters, with verification times suitable for integration into development workflows.
  • The algorithm is cross-platform and does not depend on OS-specific path resolution, avoiding inconsistencies across different operating systems.
  • Despite not mimicking file system behavior exactly, the algorithm remains secure when combined with whitelisting, as it correctly resolves paths like "../../" and "./" in a way that aligns with intended access control.
  • The algorithm is easily extendable—for example, to support wildcards or to prepend a web application’s root directory—without compromising security or simplicity.
  • The approach reduces the attack surface compared to methods relying on string manipulation or file system calls, and it mitigates risks associated with memory safety in low-level implementations.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.