From 39f85fd001bedf0e4dc3fb641936af48cc97df39 Mon Sep 17 00:00:00 2001
From: xiaomlove <1939737565@qq.com>
Date: Fri, 17 Oct 2025 22:00:39 +0700
Subject: [PATCH] format_comment() add filter_src()
---
include/constants.php | 2 +-
include/functions.php | 30 ++++++++++++++++++++++++++----
include/globalfunctions.php | 29 ++++++++++++++++++++++++++++-
3 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/include/constants.php b/include/constants.php
index 47185bf5..93cf3442 100644
--- a/include/constants.php
+++ b/include/constants.php
@@ -1,6 +1,6 @@
");
}
function formatFlash($src, $width, $height) {
+ $src = filter_src($src);
+ if (empty($src)) {
+ return "";
+ }
if (!$width) {
$width = 500;
}
@@ -253,6 +259,10 @@ function formatFlash($src, $width, $height) {
return addTempCode("");
}
function formatFlv($src, $width, $height) {
+ $src = filter_src($src);
+ if (empty($src)) {
+ return "";
+ }
if (!$width) {
$width = 320;
}
@@ -263,6 +273,10 @@ function formatFlv($src, $width, $height) {
}
function formatYoutube($src, $width = '', $height = ''): string
{
+ $src = filter_src($src);
+ if (empty($src)) {
+ return "";
+ }
if (!$width) {
$width = 560;
}
@@ -283,6 +297,10 @@ function formatYoutube($src, $width = '', $height = ''): string
}
function formatVideo($src, $width, $height) {
+ $src = filter_src($src);
+ if (empty($src)) {
+ return "";
+ }
if (!$width) {
$width = 560;
}
@@ -293,6 +311,10 @@ function formatVideo($src, $width, $height) {
}
function formatAudio($src) {
+ $src = filter_src($src);
+ if (empty($src)) {
+ return "";
+ }
return addTempCode("");
}
diff --git a/include/globalfunctions.php b/include/globalfunctions.php
index c0a0e89d..603b9f1d 100644
--- a/include/globalfunctions.php
+++ b/include/globalfunctions.php
@@ -1368,9 +1368,36 @@ function has_role_work_seeding($uid)
return $result;
}
+function filter_src($src)
+{
+ $path = parse_url($src, PHP_URL_PATH);
+ if (empty($path)) {
+ return $src;
+ }
+ $guessScriptFilename = sprintf("%s/%s", $_SERVER['DOCUMENT_ROOT'], trim($path, '/'));
+ if (!file_exists($guessScriptFilename)) {
+ return $src;
+ }
+ //log danger, deny directly
+ if (is_danger_url($src)) {
+ $msg = "[DANGER_URL]: $src";
+ do_log($msg, "alert");
+ write_log($msg, "mod");
+ return "";
+ }
+ //only allow these
+ $allowScriptPattern = "/(forums|details|offers)\.php/i";
+ $match = preg_match($allowScriptPattern, $src);
+ if ($match <= 0) {
+ do_log("[NOT_ALLOW_SRC]: $src");
+ return "";
+ }
+ return $src;
+}
+
function is_danger_url($url): bool
{
- $dangerScriptsPattern = "/(logout|login|ajax|announce|scrape|adduser|modtask|take.*)\.php/i";
+ $dangerScriptsPattern = "/(logout|login|ajax|announce|scrape|adduser|modtask|docleanup|freeleech|take.*)\.php/i";
$match = preg_match($dangerScriptsPattern, $url);
if ($match > 0) {
return true;