File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments