- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: php-security/laravel-path-traversal-storage
Language: PHP
Severity: Error
Category: Security
CWE: 22
This rule is about avoiding the construction of file paths from unsanitized user inputs. It is important for the security of your application because it prevents path traversal attacks, where an attacker can gain access to restricted directories and execute files outside of your application’s root directory.
In PHP, you can avoid this issue by using built-in functions to sanitize user inputs before using them to construct file paths. Functions like basename()
or realpath()
can be used to ensure that the user input does not contain any directory traversal characters. Alternatively, you can also use the filter_var()
function with the FILTER_SANITIZE_URL
flag to sanitize a URL input.
<?php
class Foo extends Controller{
function foo($path) {
Storage::download($path);
return view('user.index', []);
}
function bar($col, $user) {
$path = Storage::disk($disk)->path(storage_path('path/').$col);
return view('user.index', ['path' => $path]);
}
}
class Bar extends FormRequest {
function rules() {
$name = $this->input('name');
$items = Storage::get($name);
$rule = process($items);
return [
'items' => [
'required',
$rule,
]
];
}
}
<?php
class Foo extends Controller {
function foo(Request $request) {
$image = $request->file('image');
$url = Storage::disk('dir')->url($image->store($folder, 'dir'));
return view('user.index', ['data' => $url]);
}
}
class Bar extends FormRequest {
function rules() {
$name = $this->input('name');
$items = Storage::get('name');
$rule = process($orders);
return [
'items' => [
'required',
$rule,
]
];
}
}