- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
",t};e.buildCustomizationMenuUi=t;function n(e){let t='
",t}function s(e){let n=e.filter.currentValue||e.filter.defaultValue,t='${e.filter.label}
`,e.filter.options.forEach(s=>{let o=s.id===n;t+=``}),t+="${e.filter.label}
`,t+=`ID: csharp-security/path-traversal
Language: C#
Severity: Error
Category: Security
CWE: 22
No description found
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using System.IO;
using System.Web;
using System.Text;
namespace Controllers
{
public class VulnerableController : Controller
{
private readonly string _rootPath;
public VulnerableController(string rootPath)
{
_rootPath = rootPath;
}
[HttpPost("/path-test")]
public IActionResult Post()
{
// Get parameter from cookies
string param = "defaultValue";
if (Request.Cookies != null)
{
foreach (var cookie in Request.Cookies)
{
if (cookie.Key.Equals("TestCookie"))
{
param = HttpUtility.UrlDecode(cookie.Value, Encoding.UTF8);
break;
}
}
}
// Vulnerable: User input directly in Path.Combine
string fileName = Path.Combine(_rootPath, "files", param);
// Use the unsafe value
FileStream fs = null;
try
{
fs = new FileStream(fileName, FileMode.Open);
// Read file...
}
catch (Exception e)
{
// Handle error...
}
finally
{
fs?.Close();
}
return Ok();
}
}
}
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using System.IO;
using System.Web;
using System.Text;
namespace Controllers
{
public class SafeController : Controller
{
[HttpPost("/path-test")]
public IActionResult Post()
{
// Get parameter from cookies
string param = "defaultValue";
if (Request.Cookies != null)
{
foreach (var cookie in Request.Cookies)
{
if (cookie.Key.Equals("TestCookie"))
{
param = HttpUtility.UrlDecode(cookie.Value, Encoding.UTF8);
break;
}
}
}
// Safe: Uses ternary that always evaluates to a constant
string filePath = (7 * 18) + 106 > 200 ? "safe_constant_filename" : param;
// Use the safe value
FileStream fs = null;
try
{
string fullPath = Constants.FILES_DIR + filePath;
fs = new FileStream(fullPath, FileMode.Open);
// Read file...
}
catch (Exception e)
{
// Handle error...
}
finally
{
fs?.Close();
}
return Ok();
}
}
public static class Constants
{
public static string FILES_DIR = "files/";
}
}