summaryrefslogtreecommitdiff
path: root/src/sp_disable_xxe.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp_disable_xxe.c')
-rw-r--r--src/sp_disable_xxe.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/sp_disable_xxe.c b/src/sp_disable_xxe.c
index 113d84b..f9712b5 100644
--- a/src/sp_disable_xxe.c
+++ b/src/sp_disable_xxe.c
@@ -1,26 +1,41 @@
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",
5 "A call to libxml_disable_entity_loader was tried and nopped");
6 RETURN_TRUE;
7}
8
9PHP_FUNCTION(sp_libxml_set_external_entity_loader) {
10 sp_log_warn(
11 "xxe",
12 "A call to libxml_set_external_entity_loader was tried and nopped");
13 RETURN_TRUE;
14}
4 15
5int hook_libxml_disable_entity_loader() { 16int hook_libxml_disable_entity_loader() {
6 TSRMLS_FETCH(); 17 TSRMLS_FETCH();
7 18
8// External entities are disabled by default in PHP8+
9#if PHP_VERSION_ID < 80000
10 /* Call the php function here instead of re-implementing it is a bit
11 * ugly, but we do not want to introduce compile-time dependencies against
12 * libxml. */
13 zval func_name; 19 zval func_name;
14 zval hmac; 20 zval retval;
15 zval params[1]; 21 zval params[1];
16 22
23#if PHP_VERSION_ID < 80000
24 // This function is deprecated in PHP8, but better safe than sorry for php7.
17 ZVAL_STRING(&func_name, "libxml_disable_entity_loader"); 25 ZVAL_STRING(&func_name, "libxml_disable_entity_loader");
18 ZVAL_STRING(&params[0], "true"); 26 ZVAL_STRING(&params[0], "true");
19 call_user_function(CG(function_table), NULL, &func_name, &hmac, 1, params); 27 call_user_function(CG(function_table), NULL, &func_name, &retval, 1, params);
20#endif 28#endif
21 29
30 // This is now the recommended way to disable external entities
31 ZVAL_STRING(&func_name, "libxml_set_external_entity_loader");
32 ZVAL_NULL(&params[0]);
33 call_user_function(CG(function_table), NULL, &func_name, &retval, 1, params);
34
22 HOOK_FUNCTION("libxml_disable_entity_loader", sp_internal_functions_hook, 35 HOOK_FUNCTION("libxml_disable_entity_loader", sp_internal_functions_hook,
23 PHP_FN(sp_libxml_disable_entity_loader)); 36 PHP_FN(sp_libxml_disable_entity_loader));
37 HOOK_FUNCTION("libxml_set_external_entity_loader", sp_internal_functions_hook,
38 PHP_FN(sp_libxml_set_external_entity_loader));
24 39
25 return SUCCESS; 40 return SUCCESS;
26} 41}