T09 · Insecure Skill Coding Practices
- Location
scripts/common.py:202- Finding
Unbounded and Unvalidated Decoding of Remote Attachment Data
- Content
View full analysis
Vulnerability Details
File Location:
scripts/common.py, lines 202-208
Vulnerability Type: Unrestricted base64 decoding and unsafe attachment handling
Risk Level: MediumVulnerable Code:
python if isinstance(payload.get("base64"), str): b64 = payload["base64"].strip() if not b64: return None raw = base64.b64decode(b64) path.write_bytes(raw) return str(path)The decoded data originates from the remote performance-comment API. In
scripts/call_review_api.py, API fields are assigned trusted-looking document names such asreview.pdf,review.doc, andreview_data.xlsxbefore being passed to this function.Technical Analysis
The implementation decodes the complete remote base64 value into memory without enforcing a maximum encoded or decoded size. Python's default
base64.b64decodebehavior is also used withoutvalidate=True, so malformed or noncanonical input is not rejected strictly.After decoding, the bytes are written under a document extension without checking file signatures, expected MIME types, or the actual file format. Consequently, a compromised or malfunctioning upstream API could provide an arbitrarily large payload or content that is not a genuine PDF, Word document, or spreadsheet.
HTTP response processing also calls
resp.json()before attachment limits are applied, meaning an excessively large JSON response can consume substantial memory even before base64 decoding begins.Attack Path
- An attacker compromises, impersonates through a trusted upstream path, or otherwise controls the performance-comment API response.
- The response includes an oversized or disguised value in
pdfBase64,wordBase64, or a supported data-sheet field. call_review_api.pyloads the response and forwards the base64 value tosave_attachment_payload.- The complete payload is decoded into memory without a size limit.
- The resulting byt ...[truncated 878 chars]
- Remediation
View remediation
Remediation Suggestions
-
Enforce a strict maximum HTTP response size before parsing the complete response body.
-
Reject encoded attachment values above a configured limit and calculate the maximum possible decoded size before decoding.
-
Use strict decoding:
python raw = base64.b64decode(b64, validate=True) -
Stream large attachments where the API permits it rather than materializing the entire decoded file in memory.
-
Validate file signatures and structure against the expected output type:
- PDF:
%PDF- - Modern Office documents: ZIP container signature plus expected internal entries
- Legacy Word documents: expected Compound File Binary signature
- PDF:
-
Reject content whose detected type does not match the intended extension.
-
Write through a temporary file in the destination directory and atomically rename it only after validation succeeds.
-
Set restrictive file permissions and enforce per-run storage quotas.
-
Handle decoding, validation, and disk-space errors explicitly without leaving partial files behind.
-
