Vulnerable-Web-Application CVE semgrep_id:PHPCS_SecurityAudit.BadFunctions.FilesystemFunctions.WarnFilesystem:34:34
Improper control of filename for include/require statement in PHP program ('PHP Remote File Inclusion')
Ссылка на строку:
Описание уязвимости
Название: Improper control of filename for include/require statement in PHP program ('PHP Remote File Inclusion')
Категория: SAST (Static Application Security Testing)
Описание: Обнаружено использование неконстантного имени файла в операторе include. Это может привести к локальной (LFI) или удалённой (RFI) загрузке файлов, если пользовательский ввод достигает этого оператора. LFI и RFI могут позволить злоумышленникам получить доступ к конфиденциальным файлам. Вместо этого следует явно указывать, что нужно включить, или тщательно проверять пользовательский ввод.
CVE: semgrep_id:PHPCS_SecurityAudit.BadFunctions.FilesystemFunctions.WarnFilesystem:34:34
Уровень серьёзности: Критический
Исправление уязвимости
-
Явное указание файлов для включения:
include('secure_file.php');
-
Тщательная проверка пользовательского ввода:
Если необходимо использовать пользовательский ввод, следует провести его валидацию. Например, можно проверить, что имя файла соответствует ожидаемому формату и не содержит запрещённых символов.
if (preg_match('/^[a-zA-Z0-9_]+$/', $secure3)) { include($secure3 . '.php'); } else { echo 'Ошибка: недопустимое имя файла'; }
Дополнительная информация
- CWE: CWE-98
- OWASP: A03:2021 - Injection, A1:2017 - Injection
Для более подробной информации о данной уязвимости можно ознакомиться с статьёй на сайте OWASP.
Описание:
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": "af2d611447ab39ed6a6dbb44d64a1c4de51685c58d719e4fd422a9b7ae85d110",
"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:34:34",
"severity": "Critical",
"scanner": {
"id": "semgrep",
"name": "Semgrep"
},
"location": {
"file": "FileInclusion/pages/lvl3.php",
"start_line": 34
},
"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"
}
]
}
```