Safeguard
Application Security•

CWE-30 Path Traversal with '\\dir\\..\\filename' Explained

A leading backslash plus an embedded dot-dot can slip past checks that only inspect the start of input. What CWE-30 means for Windows file handling.

Safeguard Security Team
2 min read

CWE-30 describes path traversal through sequences shaped like "\dir..\filename". The product builds a path from external input and does not neutralize the embedded backslash dot-dot, so the final path lands outside the restricted directory.

MITRE says it is similar to CWE-26, with a backslash in place of a slash. The manipulation helps bypass some protection schemes. Sometimes a program only checks for ".." at the beginning of the input, so a path that begins with a directory name and climbs afterward goes unnoticed.

How it happens

Imagine input is rejected if it starts with "..". The attacker supplies "\dir..\filename". The text starts with a separator and a normal looking directory name, so the check passes. When the operating system resolves the path, "dir" is entered and immediately left, which collapses to a plain filename in the parent. Add more climbing and the path escapes the base entirely.

The core error is judging safety from the shape of the string rather than from the path it resolves to.

What an attacker gains

MITRE lists reading files or directories and modifying files or directories. The observed example is CVE-2002-1987, where a protection mechanism checked for "/.." but did not account for the Windows specific "..", allowing reads of arbitrary files.

How to find it

Static analysis that traces external input into file calls can flag these. During testing, try the shape directly: a directory, a climb, then a target filename, with both separators.

How to fix it

  1. Resolve the full path with the platform resolver first.
  2. Confirm the resolved path starts with the permitted base directory.
  3. Reject input that contains separators when you only expect a bare filename.
  4. Run the service with the least file system access it needs.

Quick check

Why does the embedded form defeat a start-of-string check?

The dangerous sequence is not at the start, so the check never sees it. Only the resolved path reveals the escape.

Sources

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.