Table of Contents

Class UploadFileValidator

Namespace
Dynamicweb.Core.Helpers
Assembly
Dynamicweb.Core.dll

Validation helpers for files uploaded by frontend visitors, where the file name and content are attacker-controlled.

public static class UploadFileValidator
Inheritance
UploadFileValidator
Inherited Members

Remarks

Uploaded files land under the public /Files folder, so two things must never get through: an extension the server or a browser would execute, and a write outside /Files or into one of its system folders (Templates, whose files are compiled and rendered; System, which holds configuration and definitions; and Cache.net).

Methods

IsAllowedUploadTarget(string)

Determines whether a frontend visitor may write path: its extension is not blocked, and its path is not blocked.

public static bool IsAllowedUploadTarget(string path)

Parameters

path string

The absolute path of the file that would be written.

Returns

bool

true if the file may be written; otherwise false.

IsBlockedExtension(string?)

Determines whether fileName has an extension that must be blocked from a frontend upload.

public static bool IsBlockedExtension(string? fileName)

Parameters

fileName string

The file name, as supplied by the client, or an absolute path.

Returns

bool

true if the extension is blocked; otherwise false.

Remarks

Trailing dots and spaces are trimmed first, because Windows strips them when the file is written to disk: so shell.aspx. and shell.aspx would otherwise land as shell.aspx while slipping past a naive check. A name containing : is always blocked, because NTFS treats it as an alternate data stream: shell.html::$DATA has the extension .html::$DATA but is written to disk as shell.html.

IsBlockedPath(string?)

Determines whether the absolute path has a path that must be blocked from a frontend upload.

public static bool IsBlockedPath(string? path)

Parameters

path string

The absolute path of the file or folder that would be written.

Returns

bool

true if the path is blocked; otherwise false.

Remarks

A path is blocked when it contains a traversal (..) segment, resolves outside /Files, or resolves into one of the system folders /Files/Templates, /Files/System or /Files/Cache.net.

To top