T09 · Insecure Skill Coding Practices
- Location
scripts/main.py:64- Finding
Arbitrary Local File Content Can Be Uploaded to the OCR Service
- Content
View full analysis
MAX_IMAGE_SIZE_BYTES: print(f"Error: image file exceeds the {MAX_IMAGE_SIZE_BYTES // (1024 * 1024)}MB limit", file=sys.stderr) sys.exit(1) encoded = base64.b64encode(raw).decode("utf-8") return encoded ``` The resulting content is assigned directly to the outbound Tencent Cloud OCR request: ```python if args.image_url: req.ImageUrl = args.image_url elif args.image_base64: req.ImageBase64 = load_image_base64(args.image_base64) ``` ### Technical Analysis The `--image-base64` argument is documented as accepting an image, Base64 data, or a path to an image or Base64 text file. However, `load_image_base64()` accepts any path for which `os.path.isfile()` returns true. It reads the file without validating its type, magic bytes, MIME type, or ability to decode as a supported image. For non-Base64 files, the function Base64-encodes the raw bytes. Base64 is only a transport encoding and does not provide confidentiality. The encoded content is subsequently assigned to `req.ImageBase64` and sent through the Tencent Cloud SDK to `ocr.tencentcloudapi.com`. Consequently, the program's effective file-access capability is broader than the minimum privilege required for vehicle-license OCR. Any readable file of up to 7 MB can enter the external upload path, including configuration files, environment files, SSH private keys, clou ...[truncated 1654 chars]- Remediation
View remediation
