T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/shield-guard.py:145
- Finding
- Credential-access checks and block mode are not connected to enforceable operations<![CDATA[ ## Vulnerability Details **File Location**: `scripts/shield-guard.py:145-159`, `scripts/shield-guard.py:238-258`, and `scripts/shield-guard.py:264-268` **Vulnerability Type**: Non-enforcing security control **Risk Level**: Medium ### Evidence ```python def check_file_access(self, filepath: str) -> dict: """检查文件访问是否安全""" filepath_lower = filepath.lower() # 凭证文件黑名单 for pattern in self.CREDENTIAL_PATTERNS: if re.search(pattern, filepath_lower): return { "safe": False, "reason": f"凭证文件禁止访问: {filepath}", "type": "credential_access_denied" } return {"safe": True} ``` ```python def run(self): """运行防护""" print(f"{GREEN}🛡️ 安全卫士启动中...{RESET}") print(f"模式: {self.mode}") print(f"日志级别: {self.log_level}") print(f"告警渠道: {', '.join(self.alert_channels)}") print("\n输入文本进行安全检测(Ctrl+C 退出):\n") try: while True: user_input = input(f"{GREEN}> {RESET}") if not user_input.strip(): continue result = self.check_input(user_input) if not result["safe"]: self.log_threat(result, user_input[:50]) if self.mode == "block": print(f"\n{RED}⚠️ 检测到威胁,操作已阻断{RESET}") print("如需继续执行,请确认...") else: print(f"{GREEN}✓ 安全{RESET}") ``` ```python guard = ShieldGuard(args.config) if args.mode: guard.config["mode"] = args.mode ``` ### Technical Analysis `check_file_access()` can return a denial result, but no code invokes it before opening a file or performing an Agent tool operation. It therefore operates only as an unused classification helper and cannot prevent access to `.env`, private-key, SSH-key, or credential paths. Likewise, block mode only prints a message. It does not terminate an operation, return an enforceable authorizatio ...[truncated 1655 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Integrate `check_file_access()` into the actual Agent tool-authorization layer before any file read, write, upload, or attachment operation. 2. Return a machine-enforceable denial result rather than only printing a warning. 3. In block mode, abort the pending operation unless a separately authenticated and explicit approval is received. 4. Update the active mode correctly: ```python if args.mode: guard.mode = args.mode guard.config["mode"] = args.mode ``` 5. Normalize and resolve paths before matching, including symlink handling and checks that the resolved path remains within an approved root. 6. Add integration tests proving that protected-file reads are denied and that monitor, audit, and block modes behave differently. 7. Describe the current utility as a standalone classifier until runtime enforcement is implemented. ]]>
