T09 · Insecure Skill Coding Practices
- Location
scripts/qr_code_client.py:52- Finding
Remote API controls the type and contents of an automatically opened file
- Content
View full analysis
Tuple[bool, Optional[bytes], Optional[str]]: if not data_uri or "," not in data_uri: return False, None, None header, encoded = data_uri.split(",", 1) image_format = "png" if ";" in header and "/" in header: image_format = header.split("/")[1].split(";")[0].strip() try: return True, base64.b64decode(encoded), image_format except Exception: return False, None, image_format def save_qr_image( self, image_bytes: bytes, image_format: str = "png", output_path: Optional[str] = None ) -> Optional[str]: try: if output_path: file_path = Path(output_path) else: save_dir = Path.home() / ".westmoon-user-login" / "qr_codes" save_dir.mkdir(parents=True, exist_ok=True) file_path = save_dir / f"login_qr_{int(time.time())}.{image_format}" with file_path.open("wb") as handle: handle.write(image_bytes) return str(file_path) except Exception as exc: print(f"[QRCodeClient] 保存二维码失败: {exc}") return None def open_qr_image(self, file_path: str) -> bool: try: system = platform.system() if system == "Darwin": subprocess.run(["open", file_path], check=True) elif system == "Linux": subprocess.run(["xdg-open", file_path], check=True) elif system == "Windows": os.startfile(file_path) else: return False return True except Exception as exc: print(f"[QRCodeClient] 打开二维码失败: {exc}") return False ``` ```python # scripts/w ...[truncated 3196 chars]- Remediation
View remediation
