diff --git a/apps/home/controller/ParserController.php b/apps/home/controller/ParserController.php index e539c60..73fb995 100644 --- a/apps/home/controller/ParserController.php +++ b/apps/home/controller/ParserController.php @@ -252,13 +252,15 @@ public function parserSiteLabel($content) break; case 'statistical': if (isset($data->statistical)) { - $content = str_replace($matches[0][$i], filter_html(decode_string($data->statistical)), $content); + $statistical = filter_html(decode_string($data->statistical)); + $content = str_replace($matches[0][$i], $this->sanitizePhpOpenTag($statistical), $content); } else { $content = str_replace($matches[0][$i], '', $content); } case 'copyright': if (isset($data->copyright)) { - $content = str_replace($matches[0][$i], $this->adjustLabelData($params, decode_string($data->copyright)), $content); + $copyright = $this->adjustLabelData($params, decode_string($data->copyright)); + $content = str_replace($matches[0][$i], $this->sanitizePhpOpenTag($copyright), $content); } else { $content = str_replace($matches[0][$i], '', $content); } @@ -276,6 +278,15 @@ public function parserSiteLabel($content) return $content; } + // 转义 PHP 开标签,防止站点信息被还原为可执行 PHP 代码 + protected function sanitizePhpOpenTag($content) + { + if (! is_string($content) || $content === '') { + return $content; + } + return preg_replace('/<\?(?:php|=)?/i', '<?', $content); + } + // 解析公司标签 public function parserCompanyLabel($content) { @@ -4083,4 +4094,4 @@ protected function checkLabelLevel($params) } return true; } -} \ No newline at end of file +}