T09 · Insecure Skill Coding Practices
- Location
report.py:120- Finding
Untrusted News Content Is Inserted Directly into the LLM Instruction Context
- Content
View full analysis
list: try: df = ak.stock_news_em(symbol=code) if df is None or df.empty: return [] news = [] for _, row in df.head(count).iterrows(): news.append({ "title": str(row.get("新闻标题", "")), "date": str(row.get("发布时间", "")), "source": str(row.get("文章来源", "")), }) return news ``` The externally sourced values are interpolated directly into the model prompt: ```python if news: lines.append("【近期新闻】") for i, n in enumerate(news, 1): lines.append(f"{i}. [{n.get('date','')}] {n.get('title','')}(来源:{n.get('source','')})") lines.append("") ``` The resulting text is placed in the same instruction context as the report-generation requirements: ```python def build_prompt(data: dict, style: str = "casual") -> str: style_text = STYLE_PROMPTS.get(style, STYLE_PROMPTS["casual"]) data_text = build_data_summary(data) stock_name = data.get("basic", {}).get("name") or data.get("stock", {}).get("name") return f"""{style_text} 请根据以下数据,为 {stock_name} 写一份个股体检报告。 {data_text} 报告格式要求(严格按照以下结构输出,不要加任何额外说明): 📊 【今日行情】 (2~3句话说明今天的价格和涨跌情况,结合近期走势给出判断) 💪 【财务健康度】 (用大白话解读毛利率、ROE、负债率等核心财务数据,给出"健康/一般/需注意"的整体评价) 🎯 【估值水位】 (解读PE和PB,判断当前估值是高还是低,对比行业给出参考) 🌊 【主力资金动向】 (解读主力净流入数据,判断主力是在买入、卖出还是观望) 📰 【近期热点】 (总结近期新闻,分析对股价可能的影响) ⚡ 【总体体检结论】 (综合各维度,用1~2句话给出整体判断,态度要明确,不要模棱两可) ⚠️ 【风险提示】 以下内容由AI根据公开数据自动生成,仅供参考学习,不构成任何投资建议。股市有风险,投资需谨慎,请结合自身情况独立决策。""" ``` ### Technical Analysis News titles, dates, and source names originate from an external se ...[truncated 2244 chars]- Remediation
View remediation
