T09 · Insecure Skill Coding Practices
- Location
scripts/visualize_data.py:62- Finding
Unrestricted Remote Data Retrieval Enables Server-Side Request Forgery
- Content
View full analysis
Vulnerability Details
File Location:
scripts/visualize_data.py, lines 62–70
Vulnerability Type: Server-Side Request Forgery (SSRF) through unrestricted data-source handling
Risk Level: MediumVulnerable Code
python def load_data(data_source: str) -> pd.DataFrame: """Load data from various sources.""" if data_source.startswith('{') or data_source.startswith('['): # JSON string data = json.loads(data_source) return pd.DataFrame(data) elif data_source.endswith('.csv'): return pd.read_csv(data_source) elif data_source.endswith('.json'): return pd.read_json(data_source)Technical Analysis
The
data_sourceparameter is supplied directly topandas.read_json()after only verifying that the string ends with.json. This suffix check does not establish that the input identifies a local file.pandas.read_json()accepts URL-like inputs in addition to local paths. Consequently, an attacker who controlsdata_sourcecan provide an HTTP or HTTPS URL ending in.json. The process may then initiate an outbound request from the environment in which the Skill is running.This behavior conflicts with the documented interface, which describes
data_sourceas a data-file path or inline JSON string and does not disclose unrestricted network retrieval. The absence of validation for URI schemes, destination hosts, resolved IP addresses, ports, redirects, and response sizes makes the operation vulnerable to SSRF when exposed to untrusted input.Attack Path
- An attacker supplies a URL such as
http://internal-service.example/status.jsonasdata_source. - The URL is not inline JSON and passes the
.jsonsuffix check. - The application invokes
pd.read_json(data_source)without validating the destination. - Pandas retrieves the resource using the network permissions of the Skill process.
- If the response contains compati ...[truncated 1189 chars]
- An attacker supplies a URL such as
- Remediation
View remediation
Remediation Suggestions
- Treat
data_sourceas a local path unless remote retrieval is an explicit product requirement. - Parse the input as a URI and reject all non-local schemes, including
http,https,ftp, andfile. - Resolve local paths with
pathlib.Path.resolve()and require them to remain within a dedicated, approved input directory. - Reject traversal attempts, symbolic-link escapes, unsupported extensions, and non-regular files.
- If remote sources are required:
- Allowlist permitted schemes, hostnames, ports, and URL paths.
- Resolve hostnames and block loopback, private, link-local, multicast, reserved, and cloud metadata addresses.
- Repeat destination validation after DNS resolution and for every redirect.
- Disable redirects where possible.
- Enforce connection, read, and total-operation timeouts.
- Limit response size and validate the response content type before parsing.
- Route requests through a restricted outbound proxy.
- Fetch approved remote content through a hardened HTTP client and pass validated local content to Pandas rather than allowing Pandas to retrieve arbitrary URLs directly.
- Add tests covering internal addresses, alternate IP representations, DNS rebinding, redirects, malformed URLs, oversized responses, and path traversal.
- Treat
