- Description: An attacker crafts a malicious pickle file containing embedded code. If the application uses
pd.read_pickle()
to load this file from an untrusted source, the embedded code is executed on the server, leading to arbitrary code execution and full server compromise. This is because pickle is not designed to be secure against malicious data. - Impact: Critical server compromise, data breach, denial of service, complete application takeover.
- Pandas Component Affected:
pd.read_pickle()
function. - Risk Severity: Critical
- Mitigation Strategies:
- Never use
pd.read_pickle()
to load data from untrusted sources. - Use safer serialization formats like CSV, JSON, or Parquet for data exchange with external entities.
- If pickle is absolutely necessary for internal use, ensure the data source is completely trusted and implement cryptographic signing and verification of pickle files.
- Never use
- Description: An attacker uploads or provides a very large or deeply nested file (CSV, Excel, JSON, etc.) specifically crafted to consume excessive memory and CPU resources when parsed by pandas file reading functions. This can lead to application slowdown, crashes, or complete denial of service, impacting availability and potentially other services on the same infrastructure.
- Impact: Application downtime, service disruption, resource exhaustion, potential financial loss due to unavailability.
- Pandas Component Affected: File reading functions like
pd.read_csv()
,pd.read_excel()
,pd.read_json()
. - Risk Severity: High
- Mitigation Strategies:
- Implement strict file size limits for uploads.
- Validate file structure and complexity before parsing (e.g., limit CSV columns, JSON nesting depth).
- Use resource limits (memory and CPU) for the application or processing containers.
- Consider using streaming or chunking techniques for processing large datasets to limit memory usage.
- Implement rate limiting for file uploads or data ingestion to prevent abuse.
- Description: An attacker manipulates user input that is used to construct file paths for pandas file reading functions (e.g.,
pd.read_csv(filepath)
). By injecting path traversal sequences like../../
, they can bypass intended directory restrictions and access or read files outside the intended directory. This could allow access to sensitive system files or application configuration files. - Impact: Information disclosure, unauthorized access to sensitive files, potential escalation of privileges if sensitive configuration files are accessed.
- Pandas Component Affected: File reading functions like
pd.read_csv()
,pd.read_excel()
,pd.read_json()
when used with user-controlled file paths. - Risk Severity: High
- Mitigation Strategies:
- Never directly use user input to construct file paths.
- Use secure file handling practices and abstract file access.
- Validate and sanitize user input intended for file paths.
- Use allowlists of permitted file paths or filenames instead of blocklists.
- Ensure the application runs with minimal necessary file system permissions (principle of least privilege).
- Description: If user input is directly used to construct expressions for
df.eval()
ordf.query()
without proper sanitization, an attacker can inject malicious Python code within the string expression. When these functions execute, the injected code is executed within the pandas context, potentially leading to arbitrary code execution on the server. This allows for complete control over the application and server. - Impact: Critical server compromise, data breach, denial of service, complete application takeover.
- Pandas Component Affected:
DataFrame.eval()
andDataFrame.query()
functions. - Risk Severity: Critical
- Mitigation Strategies:
- Avoid using
eval()
andquery()
with user-provided input. - If absolutely necessary, implement extremely strict input validation and sanitization to prevent code injection. This is highly complex and error-prone, so avoidance is strongly recommended.
- Consider safer alternatives for data filtering and manipulation that do not involve dynamic code execution, such as using boolean indexing or explicit filtering logic.
- Avoid using