Path traversal via user-controlled file path
ID |
vbnet.path_resolution.path_traversal |
Severity |
critical |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
medium |
Resource |
Path Resolution |
Language |
VB.NET |
Description
User-controlled input flows into a file path without neutralization, which may allow path traversal to read or write files outside the intended directory. Normalize and validate the path (e.g. strip directory components with Path.GetFileName and confirm the resolved path stays under an allow-listed root).
Rationale
User-controlled input flows into a file path without neutralization, which may allow path traversal to read or write files outside the intended directory. Normalize and validate the path (e.g. strip directory components with Path.GetFileName and confirm the resolved path stays under an allow-listed root).
The following code illustrates a vulnerable pattern detected by this rule:
Public Sub CombineFromQueryString(ByVal Request As HttpRequest)
Dim fileName As String = Request.QueryString("file")
' VULNERABLE: Path traversal via user-controlled file path
Dim fullPath = Path.Combine("C:\data", fileName)
End Sub
Remediation
Follow secure coding practices and review the references below for detailed remediation guidance.