Skip to content

Commit 2f38301

Browse files
committed
fix: 增强技能名称和描述的安全性,防止注入攻击
1 parent 999c181 commit 2f38301

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

astrbot/core/skills/skill_manager.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,16 @@ def build_skills_prompt(skills: list[SkillInfo]) -> str:
8686
example_path = ""
8787
for skill in skills:
8888
name = str(getattr(skill, "name", "") or "").strip() or "unknown-skill"
89+
# 验证 name 格式(防御性编程,防止注入)
90+
if not _SKILL_NAME_RE.match(name):
91+
name = "unknown-skill"
8992
description = str(getattr(skill, "description", "") or "").strip()
90-
description = description or "No description"
93+
# 清理换行符,防止 Indirect Prompt Injection
94+
description = (description or "No description").replace("\n", " ").replace("\r", " ")
9195
path = str(getattr(skill, "path", "") or "").strip()
9296
path = path or "<skills_root>/<skill_name>/SKILL.md"
97+
# 清理路径中的危险字符
98+
path = _SAFE_PATH_RE.sub("", path)
9399
skills_lines.append(f"- **{name}**: {description}\n File: `{path}`")
94100
if not example_path:
95101
example_path = path

0 commit comments

Comments
 (0)