summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjvoisin2021-04-28 09:34:42 +0200
committerjvoisin2021-04-28 10:55:53 +0200
commitfb3571de3d9dd0df9bfb38579b56dbb9746df551 (patch)
treee4ef03c633fc00cc4cbdec93255f0318c220d49d /src
parent99cab6d750e2d8e2f6dfc412394ce49ae7534bd6 (diff)
Add some logging for the XXE mitigation
Diffstat (limited to 'src')
-rw-r--r--src/sp_disable_xxe.c16
-rw-r--r--src/tests/xxe/disable_xxe_dom_disabled.phpt5
2 files changed, 18 insertions, 3 deletions
diff --git a/src/sp_disable_xxe.c b/src/sp_disable_xxe.c
index 3ef1a5d..9dea33c 100644
--- a/src/sp_disable_xxe.c
+++ b/src/sp_disable_xxe.c
@@ -1,6 +1,14 @@
1#include "php_snuffleupagus.h" 1#include "php_snuffleupagus.h"
2 2
3PHP_FUNCTION(sp_libxml_disable_entity_loader) { RETURN_TRUE; } 3PHP_FUNCTION(sp_libxml_disable_entity_loader) {
4 sp_log_warn( "xxe", "A call to libxml_disable_entity_loader was tried and nopped");
5 RETURN_TRUE;
6}
7
8PHP_FUNCTION(sp_libxml_set_external_entity_loader) {
9 sp_log_warn("xxe", "A call to libxml_set_external_entity_loader was tried and nopped");
10 RETURN_TRUE;
11}
4 12
5int hook_libxml_disable_entity_loader() { 13int hook_libxml_disable_entity_loader() {
6 TSRMLS_FETCH(); 14 TSRMLS_FETCH();
@@ -10,19 +18,21 @@ int hook_libxml_disable_entity_loader() {
10 zval params[1]; 18 zval params[1];
11 19
12#if PHP_VERSION_ID < 80000 20#if PHP_VERSION_ID < 80000
13 // This function is deprecated in PHP8, but better safe than sorry for php7. 21 // This function is deprecated in PHP8, but better safe than sorry for php7.
14 ZVAL_STRING(&func_name, "libxml_disable_entity_loader"); 22 ZVAL_STRING(&func_name, "libxml_disable_entity_loader");
15 ZVAL_STRING(&params[0], "true"); 23 ZVAL_STRING(&params[0], "true");
16 call_user_function(CG(function_table), NULL, &func_name, &retval, 1, params); 24 call_user_function(CG(function_table), NULL, &func_name, &retval, 1, params);
17#endif 25#endif
18 26
19 // This is now the recommended way to disable external entities 27 // This is now the recommended way to disable external entities
20 ZVAL_STRING(&func_name, "libxml_set_external_entity_loader"); 28 ZVAL_STRING(&func_name, "libxml_set_external_entity_loader");
21 ZVAL_NULL(&params[0]); 29 ZVAL_NULL(&params[0]);
22 call_user_function(CG(function_table), NULL, &func_name, &retval, 1, params); 30 call_user_function(CG(function_table), NULL, &func_name, &retval, 1, params);
23 31
24 HOOK_FUNCTION("libxml_disable_entity_loader", sp_internal_functions_hook, 32 HOOK_FUNCTION("libxml_disable_entity_loader", sp_internal_functions_hook,
25 PHP_FN(sp_libxml_disable_entity_loader)); 33 PHP_FN(sp_libxml_disable_entity_loader));
34 HOOK_FUNCTION("libxml_set_external_entity_loader", sp_internal_functions_hook,
35 PHP_FN(sp_libxml_set_external_entity_loader));
26 36
27 return SUCCESS; 37 return SUCCESS;
28} 38}
diff --git a/src/tests/xxe/disable_xxe_dom_disabled.phpt b/src/tests/xxe/disable_xxe_dom_disabled.phpt
index 493f5a3..a49e094 100644
--- a/src/tests/xxe/disable_xxe_dom_disabled.phpt
+++ b/src/tests/xxe/disable_xxe_dom_disabled.phpt
@@ -44,8 +44,13 @@ printf("without xxe: %s", $dom->getElementsByTagName('testing')->item(0)->nodeVa
44 44
45?> 45?>
46--EXPECTF-- 46--EXPECTF--
47Warning: [snuffleupagus][0.0.0.0][xxe][log] A call to libxml_disable_entity_loader was tried and nopped in %s/tests/xxe/disable_xxe_dom_disabled.php on line %d
47libxml_disable_entity to true: WARNING, external entity loaded! 48libxml_disable_entity to true: WARNING, external entity loaded!
49
50Warning: [snuffleupagus][0.0.0.0][xxe][log] A call to libxml_disable_entity_loader was tried and nopped in %s/tests/xxe/disable_xxe_dom_disabled.php on line %d
48libxml_disable_entity to false: WARNING, external entity loaded! 51libxml_disable_entity to false: WARNING, external entity loaded!
52
53Warning: [snuffleupagus][0.0.0.0][xxe][log] A call to libxml_disable_entity_loader was tried and nopped in %s/tests/xxe/disable_xxe_dom_disabled.php on line %d
49without xxe: foo 54without xxe: foo
50--CLEAN-- 55--CLEAN--
51<?php 56<?php