Safeguard
Application Security•

CWE-54 Trailing Backslash Path Equivalence and ASP.NET Bypass

A trailing backslash or its encoded form %5C let attackers past directory authentication in a .NET web framework. CWE-54 explained.

Safeguard Security Team
3 min read

CWE-54 is path equivalence using a trailing backslash, as in filedir\. The product accepts that input without appropriate validation, so path resolution is ambiguous. MITRE lists Windows among the platforms, which makes sense, because Windows treats the backslash as a separator.

It belongs to the family under CWE-41.

How it happens

Web servers on Windows commonly accept both slash types in a URL. An access rule that was written for forward slashes sees a different string when a backslash is used, or when it arrives percent encoded as %5C. The file layer then treats the backslash as an ordinary separator and opens the protected file.

The record lists two examples:

  • A web framework for .NET allowed remote attackers to bypass authentication for .aspx files in restricted directories via a request containing a backslash or an encoded backslash, %5C (CVE-2004-0847).
  • A bypass of directory access restrictions using a trailing dot in the URL (CVE-2004-0061).

The first is a clean case of the pattern. The authentication check and the file lookup did not agree about what a backslash means.

// Vulnerable pattern: protect by a forward slash prefix only
if (url.StartsWith("/restricted/") && !user.IsAuthenticated) return Deny();
// "\restricted\page.aspx" or "%5Crestricted%5Cpage.aspx" is not matched

What an attacker gains

MITRE lists reading and modifying files and directories. The recorded effect is bypassing authentication on files in a restricted directory.

How to find it

On a staging copy, request restricted resources with a backslash separator, with %5C, and with a trailing backslash, then compare status and body to the normal request. Review access rules for the separators they handle.

How to fix it

  1. Decode the URL, convert backslashes to forward slashes, and canonicalize before any rule runs.
  2. Apply authentication at the directory or prefix level on the normalized path, with deny as the default.
  3. Reject requests that contain a backslash if your application never needs one.
  4. Update the framework or server when the bug is in the product.
var path = Uri.UnescapeDataString(rawUrl).Replace('\\', '/');
if (path.Contains('\\')) return BadRequest();

A free scan at gold.safeguard.sh/scan can show known issues in your framework versions with no login.

Quick check

What is %5C?

The percent encoded form of a backslash. After decoding it is a normal separator on Windows, so rules that check before decoding can miss it.

What was the impact in CVE-2004-0847?

Per the record, a bypass of authentication for aspx files in restricted directories.

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.