From a9340371798f4eb6287edf0d9fb681b19ba57bf8 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 4 May 2022 17:43:15 +0800 Subject: [PATCH] prevent user from executing phar stub file directly --- phpstan.neon | 1 + src/ZM/script_phar_stub.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 25b6cecf..66ea6614 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,3 +11,4 @@ parameters: dynamicConstantNames: - SWOOLE_VERSION - ZM_TEST_LOG_DEBUG + - _PHAR_STUB_ID diff --git a/src/ZM/script_phar_stub.php b/src/ZM/script_phar_stub.php index d50e6a4f..3650b878 100644 --- a/src/ZM/script_phar_stub.php +++ b/src/ZM/script_phar_stub.php @@ -2,6 +2,8 @@ declare(strict_types=1); +const _PHAR_STUB_ID = '__generated_id__'; + function loader__generated_id__() { $obj = json_decode(file_get_contents(__DIR__ . '/zmplugin.json'), true); @@ -12,4 +14,8 @@ function loader__generated_id__() require_once Phar::running() . '/' . $v; } } +if ('__generate' . 'd_id__' === _PHAR_STUB_ID) { + echo 'Cannot execute this file directly!' . PHP_EOL; + exit(1); +} return json_decode(file_get_contents(__DIR__ . '/zmplugin.json'), true) ?? ['zm_module' => false];