T09 · Insecure Skill Coding Practices
- Location
scripts/emr_qc_impl.py:117- Finding
Untrusted Medical Record Content Can Manipulate LLM Quality-Control Results
- Content
View full analysis
str: """既往史缺血压血糖控制情况""" pmh = fields["pmh"] if not pmh: return "无缺陷" # LLM1:既往史中是否已包含用药/控制相关关键词(快速判断) has_keywords = llm([user_msg( f"""给定门诊病历中既往史字段,请判断其中是否包含"降糖药","降压药","控制血糖","控制血压"或者相关的描述,请直接回答"是"或者"否" 既往史:{pmh}""" )]) # 若已包含控制信息关键词,则跳过完整质控 if "是" in has_keywords and "否" not in has_keywords: return "无缺陷" # 完整质控 return llm([user_msg( f"""你是一位病历质控专家,请对门诊病历进行质控,如果没有缺陷请直接回答"无缺陷",不要进行任何分析;如果有缺陷请先回答"有缺陷"再另起一行分析原因 缺陷描述: 1.既往史中记录高血压,但是没有记录血压控制情况 2.既往史中描述糖尿病,但是没有记录血糖控制情况 请注意,控制情况包含但不限于以下几种 - 血糖有具体数值mmol/L,血压有具体数值和mmgh - 控制尚可 - 控制可 - 未监测 - 控制良好 - 控制不佳 - 轻度异常 - 波动明显 - 稳定 - 有记录 - 有症状 - 治疗效果不佳 - 随访中 以下是一些示例,用标记,请参考 【病历】 既往史:高血压病史10年,长期口服缬沙坦。 【质控结果】 有缺陷 有高血压病史,但是没有记录血压情况 【病历】 既往史:高血压病史10年,长期口服吲达帕胺,近期血压140/90mmgh 【质控结果】 无缺陷 【病历】 既往史:高血压病史年,口服药物治疗,控制良好;糖尿病病史年,口服药物/注射胰岛素治疗,控制良好 【质控结果】 无缺陷 【病历】 既往史:糖尿病史:10年,药物控制,控制不佳 【质控结果】 无缺陷 现在请对下面的门诊病历进行质控 【病历】 既往史:{pmh} 【质控结果】""" )]) ``` ### Technical Analysis The `pmh` value originates from the supplied medical record and is therefore untrusted. It is interpolated directly into the same user-role message that contains the operational quality-control instructions. No structural separation or explicit trust boundary prevents instructions embedded in the medical record from being interpreted as model directives. An attacker can place text in the past-medical-history field instructing the model to ignore the preceding rule and return a chosen result. Both LLM calls are affected: 1. The preliminary response is interpreted using a weak substring test: ```python if "是" in ...[truncated 1825 chars]- Remediation
View remediation
