Vulnerable-Web-Application CVE semgrep_id:PHPCS_SecurityAudit.BadFunctions.FilesystemFunctions.WarnFilesystem:32:32
Improper control of filename for include/require statement in PHP program ('PHP Remote File Inclusion')
Ссылка на строку:
Описание уязвимости
Тип: SAST (Static Application Security Testing)
Название: Improper control of filename for include/require statement in PHP program ('PHP Remote File Inclusion')
Описание: Обнаружено использование неконстантного имени файла в инструкции include. Это может привести к локальной (LFI) или удалённой (RFI) включению файлов, если пользовательский ввод достигает этого оператора. LFI и RFI могут позволить злоумышленникам получить доступ к конфиденциальным файлам. Вместо этого следует явно указывать, что включать, или тщательно проверять пользовательский ввод.
CVE: semgrep_id:PHPCS_SecurityAudit.BadFunctions.FilesystemFunctions.WarnFilesystem:32:32
Уровень серьёзности: Критический
Сканер: Semgrep
Местоположение уязвимости
Файл: FileInclusion/pages/lvl2.php
Строка: 32
Исходная строка с уязвимостью
@include($secure2);
Варианты исправления
-
Явное указание включаемого файла:
@include('secure_file.php');
-
Тщательная проверка пользовательского ввода:
if (isset($_GET['file']) && in_array($_GET['file'], ['file1', 'file2'])) { @include($_GET['file'] . '.php'); } else { echo 'Invalid file'; }
-
Использование безопасного метода включения файлов:
function safeInclude($file) { $allowedFiles = ['file1', 'file2']; if (in_array($file, $allowedFiles)) { @include($file . '.php'); } else { echo 'Invalid file'; } } safeInclude($_GET['file']);
Дополнительная информация
Описание:
Detected non-constant file inclusion. This can lead to local file inclusion (LFI) or remote file inclusion (RFI) if user input reaches this statement. LFI and RFI could lead to sensitive files being obtained by attackers. Instead, explicitly specify what to include. If that is not a viable solution, validate user input thoroughly.Исходный JSON:
{
"id": "1c8dadf13c09e803b88708ef7208ef61b0f05ac5ac1324f7959b648857acf94e",
"category": "sast",
"name": "Improper control of filename for include/require statement in PHP program ('PHP Remote File Inclusion')",
"description": "Detected non-constant file inclusion. This can lead to local file inclusion (LFI) or remote file inclusion (RFI) if user input reaches this statement. LFI and RFI could lead to sensitive files being obtained by attackers. Instead, explicitly specify what to include. If that is not a viable solution, validate user input thoroughly.",
"cve": "semgrep_id:PHPCS_SecurityAudit.BadFunctions.FilesystemFunctions.WarnFilesystem:32:32",
"severity": "Critical",
"scanner": {
"id": "semgrep",
"name": "Semgrep"
},
"location": {
"file": "FileInclusion/pages/lvl2.php",
"start_line": 32
},
"identifiers": [
{
"type": "semgrep_id",
"name": "PHPCS_SecurityAudit.BadFunctions.FilesystemFunctions.WarnFilesystem",
"value": "PHPCS_SecurityAudit.BadFunctions.FilesystemFunctions.WarnFilesystem"
},
{
"type": "cwe",
"name": "CWE-98",
"value": "98",
"url": "https://cwe.mitre.org/data/definitions/98.html"
},
{
"type": "owasp",
"name": "A03:2021 - Injection",
"value": "A03:2021"
},
{
"type": "owasp",
"name": "A1:2017 - Injection",
"value": "A1:2017"
},
{
"type": "phpcs_security_audit_source",
"name": "PHPCS Security Audit Test ID PHPCS_SecurityAudit.BadFunctions.FilesystemFunctions.WarnFilesystem",
"value": "PHPCS_SecurityAudit.BadFunctions.FilesystemFunctions.WarnFilesystem"
}
]
}
```