T09 · Insecure Skill Coding Practices
- Location
scripts/main.py:70- Finding
Image size validation occurs after an unbounded file read
- Content
View full analysis
MAX_IMAGE_SIZE_BYTES: print(f"Error: Image exceeds the {MAX_IMAGE_SIZE_BYTES // (1024 * 1024)} MB limit", file=sys.stderr) sys.exit(1) encoded = base64.b64encode(raw).decode("utf-8") ``` The comments and error message above are translated into English for presentation; the executable behavior matches the audited source. ### Technical Analysis The code calls `f.read()` without a size argument, loading the complete user-selected file into memory before checking whether it exceeds `MAX_IMAGE_SIZE_BYTES`. The nominal 10 MB restriction therefore does not protect the process from memory exhaustion. The Base64-text branch also returns immediately after validating the encoding syntax. It does not enforce the decoded-size limit before returning, so an oversized Base64 document can bypass the intended input-size validation. This is an insecure resource-handling issue rather than evidence of covert exfiltration. The Base64 conversion itself is necessary for the declared Tencent Cloud OCR API and is not malicious. ### Attack Path 1. An attacker creates or identifies a file substantially larger than available process memory. 2. The attacker causes the Skill to be invoked with that path through `--image-base64`. 3. `os.path.isfile()` accepts the path. 4. `f.read()` attempts to load the entire file before the size check is reached. 5. The Python proc ...[truncated 899 chars]- Remediation
View remediation
MAX_ENCODED_INPUT_SIZE: raise ValueError("Input file is too large") with open(value, "rb") as file: raw = file.read(MAX_ENCODED_INPUT_SIZE + 1) if len(raw) > MAX_ENCODED_INPUT_SIZE: raise ValueError("Input file is too large") try: raw_str = raw.decode("ascii").strip() decoded = base64.b64decode(raw_str, validate=True) if len(decoded) > MAX_IMAGE_SIZE_BYTES: raise ValueError("Decoded image is too large") return raw_str except (UnicodeDecodeError, ValueError): pass ``` ]]>
