- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: php-security/unsafe-entity-loader
Language: PHP
Severity: Error
Category: Security
CWE: 611
The ability to load external entities while parsing XML data should be disabled. This helps prevent XML External Entity (XXE) attacks, which can lead to disclosure of internal files, denial of service, server side request forgery, port scanning from the perspective of the machine where the parser is located, and other system impacts.
In PHP versions before 8.0, libxml_disable_entity_loader()
is set to true
by default, which means that loading of external entities is disabled. However, if you explicitly set this function to false
, as seen in the non-compliant code sample, you are enabling the loading of external entities, thereby opening up potential security vulnerabilities.
To adhere to this rule and ensure the security of your PHP applications, you should avoid enabling the entity loader. This means that you should not use libxml_disable_entity_loader(false)
. Instead, let the function retain its default value of true
. If you need to parse XML data, use secure functions such as simplexml_load_string()
or DOMDocument::loadXML()
, as seen in the compliant code sample. These functions are designed to safely parse XML data without exposing your application to XXE attacks.
<?php
class Foo extends Controller {
public function test($input) {
libxml_disable_entity_loader(false);
$doc = new DOMDocument();
$doc->loadXML($input);
return view('user.index', []);
}
}
<?php
class Foo extends Controller {
public function test($id) {
libxml_disable_entity_loader(true);
$data = simplexml_load_string($xml_input);
return view('user.index', ['data' => $data]);
}
}
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products