T09 · Insecure Skill Coding Practices
- Location
scripts/common.py:227- Finding
Unbounded Memory Consumption and Indefinite Network Wait During File Upload
- Content
View full analysis
Vulnerability Details
File Location:
scripts/common.py:227andscripts/common.py:262-263
Vulnerability Type: Resource exhaustion and missing network timeout
Risk Level: MediumVulnerable Code
python chunks.append(file_path.read_bytes())python with urlopen(request) as response: result = json.loads(response.read().decode("utf-8"))Technical Analysis
The multipart encoder reads the entire selected file into memory using
Path.read_bytes(). The resulting chunks are subsequently joined into another complete in-memory byte string, potentially requiring memory substantially greater than the original file size.The upload response is also read without a maximum response-size limit. A large response from the remote service or an intermediary could therefore consume additional unbounded memory.
Furthermore,
urlopen(request)is invoked without a timeout. If the upload endpoint, network connection, proxy, or TLS session stalls, the process can remain blocked indefinitely.These operations are unnecessary expansions of the resources required for the declared object-storage functionality. Streaming the file and applying bounded network operations would satisfy the same functionality with less risk.
Attack Path
- An attacker or untrusted workflow causes the Skill to upload a very large local file.
- The script reads the entire file into memory.
- Multipart assembly duplicates that data when the chunks are joined into the final request body.
- The process exhausts available memory, becomes unresponsive, or is terminated by the operating system.
- Alternatively, a remote endpoint, proxy, or disrupted connection accepts the connection but stalls the response.
- Because no timeout is configured, the Agent workflow remains blocked indefinitely.
- A malicious or abnormal server response could also consume excessive memory because the response body has no size limit.
...[truncated 799 chars]
- Remediation
View remediation
Remediation Suggestions
- Replace the in-memory multipart construction with a streaming upload implementation that reads the file in bounded chunks.
- Enforce a documented maximum upload size before opening or reading the file.
- Configure explicit connection and read timeouts for outbound upload requests.
- Add a maximum accepted response size and stop reading once that limit is exceeded.
- Validate the response content type and JSON structure before processing it.
- Handle timeout, network, malformed-response, and resource-limit errors explicitly, returning a controlled failure rather than leaving the workflow blocked.
- Consider rejecting non-regular files to avoid unexpected behavior when the supplied path refers to a device, pipe, or other special filesystem object.
