fix: Fix potential XSS risk in plugin README content
This commit is contained in:
@@ -13,6 +13,7 @@ import traceback
|
|||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
import nh3
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from astrbot.core import logger, pip_installer, sp
|
from astrbot.core import logger, pip_installer, sp
|
||||||
@@ -638,12 +639,13 @@ class PluginManager:
|
|||||||
try:
|
try:
|
||||||
with open(readme_path, "r", encoding="utf-8") as f:
|
with open(readme_path, "r", encoding="utf-8") as f:
|
||||||
readme_content = f.read()
|
readme_content = f.read()
|
||||||
|
cleaned_content = nh3.clean(readme_content)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"读取插件 {dir_name} 的 README.md 文件失败: {str(e)}")
|
logger.warning(f"读取插件 {dir_name} 的 README.md 文件失败: {str(e)}")
|
||||||
|
|
||||||
plugin_info = None
|
plugin_info = None
|
||||||
if plugin:
|
if plugin:
|
||||||
plugin_info = {"repo": plugin.repo, "readme": readme_content}
|
plugin_info = {"repo": plugin.repo, "readme": cleaned_content}
|
||||||
|
|
||||||
return plugin_info
|
return plugin_info
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import os
|
|||||||
|
|
||||||
import ssl
|
import ssl
|
||||||
import certifi
|
import certifi
|
||||||
|
import nh3
|
||||||
|
|
||||||
from .route import Route, Response, RouteContext
|
from .route import Route, Response, RouteContext
|
||||||
from astrbot.core import logger
|
from astrbot.core import logger
|
||||||
@@ -148,9 +149,7 @@ class PluginRoute(Route):
|
|||||||
if handler.event_type == EventType.AdapterMessageEvent:
|
if handler.event_type == EventType.AdapterMessageEvent:
|
||||||
# 处理平台适配器消息事件
|
# 处理平台适配器消息事件
|
||||||
has_admin = False
|
has_admin = False
|
||||||
for (
|
for filter in (
|
||||||
filter
|
|
||||||
) in (
|
|
||||||
handler.event_filters
|
handler.event_filters
|
||||||
): # 正常handler就只有 1~2 个 filter,因此这里时间复杂度不会太高
|
): # 正常handler就只有 1~2 个 filter,因此这里时间复杂度不会太高
|
||||||
if isinstance(filter, CommandFilter):
|
if isinstance(filter, CommandFilter):
|
||||||
@@ -363,9 +362,11 @@ class PluginRoute(Route):
|
|||||||
with open(readme_path, "r", encoding="utf-8") as f:
|
with open(readme_path, "r", encoding="utf-8") as f:
|
||||||
readme_content = f.read()
|
readme_content = f.read()
|
||||||
|
|
||||||
|
cleaned_content = nh3.clean(readme_content)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
Response()
|
Response()
|
||||||
.ok({"content": readme_content}, "成功获取README内容")
|
.ok({"content": cleaned_content}, "成功获取README内容")
|
||||||
.__dict__
|
.__dict__
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -386,14 +387,12 @@ class PluginRoute(Route):
|
|||||||
platform_type = platform.get("type", "")
|
platform_type = platform.get("type", "")
|
||||||
platform_id = platform.get("id", "")
|
platform_id = platform.get("id", "")
|
||||||
|
|
||||||
platforms.append(
|
platforms.append({
|
||||||
{
|
"name": platform_id, # 使用type作为name,这是系统内部使用的平台名称
|
||||||
"name": platform_id, # 使用type作为name,这是系统内部使用的平台名称
|
"id": platform_id, # 保留id字段以便前端可以显示
|
||||||
"id": platform_id, # 保留id字段以便前端可以显示
|
"type": platform_type,
|
||||||
"type": platform_type,
|
"display_name": f"{platform_type}({platform_id})",
|
||||||
"display_name": f"{platform_type}({platform_id})",
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
adjusted_platform_enable = {}
|
adjusted_platform_enable = {}
|
||||||
for platform_id, plugins in platform_enable.items():
|
for platform_id, plugins in platform_enable.items():
|
||||||
@@ -402,13 +401,11 @@ class PluginRoute(Route):
|
|||||||
# 获取所有插件,包括系统内部插件
|
# 获取所有插件,包括系统内部插件
|
||||||
plugins = []
|
plugins = []
|
||||||
for plugin in self.plugin_manager.context.get_all_stars():
|
for plugin in self.plugin_manager.context.get_all_stars():
|
||||||
plugins.append(
|
plugins.append({
|
||||||
{
|
"name": plugin.name,
|
||||||
"name": plugin.name,
|
"desc": plugin.desc,
|
||||||
"desc": plugin.desc,
|
"reserved": plugin.reserved, # 添加reserved标志
|
||||||
"reserved": plugin.reserved, # 添加reserved标志
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"获取插件平台配置: 原始配置={platform_enable}, 调整后={adjusted_platform_enable}"
|
f"获取插件平台配置: 原始配置={platform_enable}, 调整后={adjusted_platform_enable}"
|
||||||
@@ -416,13 +413,11 @@ class PluginRoute(Route):
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
Response()
|
Response()
|
||||||
.ok(
|
.ok({
|
||||||
{
|
"platforms": platforms,
|
||||||
"platforms": platforms,
|
"plugins": plugins,
|
||||||
"plugins": plugins,
|
"platform_enable": adjusted_platform_enable,
|
||||||
"platform_enable": adjusted_platform_enable,
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
.__dict__
|
.__dict__
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ dependencies = [
|
|||||||
"lark-oapi>=1.4.15",
|
"lark-oapi>=1.4.15",
|
||||||
"lxml-html-clean>=0.4.2",
|
"lxml-html-clean>=0.4.2",
|
||||||
"mcp>=1.8.0",
|
"mcp>=1.8.0",
|
||||||
|
"nh3>=0.2.21",
|
||||||
"openai>=1.78.0",
|
"openai>=1.78.0",
|
||||||
"ormsgpack>=1.9.1",
|
"ormsgpack>=1.9.1",
|
||||||
"pillow>=11.2.1",
|
"pillow>=11.2.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user