Skip to content

Helper.IsValidPath: path traversal check is too broad — blocks legitimate paths #169

@Christophe-Rogiers

Description

@Christophe-Rogiers

Bug

The path traversal check uses a simple Contains("..")):

if (path.Contains("..")) // no directory traversal

This blocks legitimate paths that contain .. as part of a folder or file name, e.g. C:\folder..name\file.txt or C:\my..app\config.json.

Suggested fix

Check for .. only as a path segment using Path.GetFullPath() and comparing with an expected base path, or check for \.. / /.. patterns specifically:

var fullPath = Path.GetFullPath(path);
if (fullPath != path && path.Contains(".." + Path.DirectorySeparatorChar))

File

src/Servy.Core/Helpers/Helper.cs — line 28

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions