T09 · Insecure Skill Coding Practices
- Location
scripts/deploy_model.py:20- Finding
Unsafe Deserialization of Untrusted Model Artifacts
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
The skill is a coherent electricity forecasting package, but its deployment guidance and scripts include unsafe production patterns that deserve careful review before use.
Install only if you are comfortable reviewing and hardening the deployment pieces. Do not load untrusted .joblib or PyTorch model files, avoid generated source from untrusted feature configs, run scheduled jobs under a dedicated non-root account, add authentication and request limits before exposing the API, and pin dependencies for production builds.
scripts/deploy_model.py:20Unsafe Deserialization of Untrusted Model Artifacts
scripts/deploy_model.py:85Python Code Injection in Generated Inference Wrapper
scripts/deploy_model.py:235Unpinned Dependencies Produce Mutable and Non-Reproducible Deployment Builds
references/deployment.md:646Forecasting Jobs Are Scheduled for Persistent Execution as Root
scripts/deploy_model.py:287Generated Forecast API Is Exposed Without Authentication or Resource Limits
The supplied code is clearly related to electricity/load forecasting evaluation, so it is not unrelated or malicious. However, the declared description presents a broad, comprehensive forecasting framework with statistical, ML, and deep learning support plus deployment and uncertainty features. This code chunk actually implements a narrower capability: backtesting/evaluation for three tree-based ML models only (LightGBM, XGBoost, Random Forest). It does not show ARIMA/SARIMA, neural models, uncertainty quantification, or deployment behavior. Because the description materially overstates the capabilities represented by this chunk, the description does not accurately represent what this specific supplied code actually does.
The description claims a comprehensive electricity load and demand forecasting framework with multiple model families, evaluation, and uncertainty quantification. The supplied code chunk only performs preprocessing: loading/validating time series data, imputing missing values, engineering features, optionally merging weather data, adding holiday features, and saving processed outputs. Weather integration is present and relevant, but the core declared capabilities around forecasting methods, model training/inference, evaluation, and deployment are absent from this code. This is therefore a material description-behavior mismatch, with the actual code representing a preprocessing component rather than the full declared framework.
The code is clearly aligned with the general domain of electricity load forecasting, so the primary purpose matches at a high level. However, the declared description materially overstates the implemented capabilities in this code chunk. The script only trains and evaluates a subset of models and saves artifacts locally. It does not implement several specifically claimed model families (ARIMA, GRU, Transformer, TFT), nor uncertainty quantification. It provides generic feature usage and metric calculation, but not explicit weather integration or deployment/production pipeline features. Therefore this is a description-behavior mismatch due to significant missing claimed capabilities, even though the overall forecasting purpose is consistent.
Referenced artifact was not completely inspected
python scripts/train_model.py --model xgboost --data processed/ --horizon 24
Referenced artifact was not completely inspected
python scripts/train_model.py --model xgboost --data processed/ --horizon 24
Referenced artifact was not completely inspected
python scripts/train_model.py --model xgboost --data processed/ --horizon 24
Without declared permissions the skill's intent is opaque and cannot be validated.
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
# API access example
import requests
url = "https://api.pjm.com/api/v1/inst_load"
params = {
'startDate': '20240101',
'endDate': '20240131',
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
**Description**: UK electricity system operator data.
**Source**: https://data.nationalgrideso.com/
**Details**:
- Great Britain grid
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
**Description**: UK electricity system operator data.
**Source**: https://data.nationalgrideso.com/
**Details**:
- Great Britain grid
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
import requests
url = "https://api.openweathermap.org/data/2.5/onecall/timemachine"
params = {
'lat': 39.9042,
'lon': 116.4074,
The holiday feature example defaults to country='CN' and adds China-specific logic such as Chinese New Year and northern China heating season. In a general-purpose feature engineering guide, this forces a specific locale and regional assumptions rather than offering a user choice or clearly restricting the guide to China-focused forecasting.
The script deserializes an attacker-controlled or untrusted model file using joblib.load(), which relies on Python pickle semantics and can execute arbitrary code during loading. In a deployment utility that accepts a model path from the command line, this creates a direct code execution path if a malicious model artifact is supplied from a compromised registry, shared filesystem, or download source.
"""Load trained model."""
print(f"Loading model from {model_path}")
package = joblib.load(model_path)
if isinstance(package, dict):
model = package.get('model', package)
The manifest describes an electricity forecasting framework for building and evaluating forecasting systems, but this script also generates a FastAPI server with public endpoints and later packages it into a deployable service. While deployment pipelines are mentioned in the manifest, exposing an HTTP API is a broader operational capability than core forecasting logic and is not reflected in the file's own stated purpose of merely exporting a model for production use.
Docker image references without a specific tag (:latest is implicit) or digest (@sha256:...) can be silently replaced by a malicious image.
The top-level documentation frames the script narrowly as a model export utility. In practice, the implementation writes multiple deployment artifacts including a web API server, container definition, dependency manifest, and documentation, which is materially broader than simple model export.
The code hard-codes a China-specific holiday locale in create_holiday_features(..., country='CN') and also sets the CLI default for --country to CN. This imposes a specific locale by default rather than prompting for or clearly requiring user selection, which can violate language/locale policy expectations when used in broader contexts.
The module docstring claims support for GRU, Transformer, and Prophet models, but the CLI only accepts lightgbm, xgboost, random_forest, lstm, and sarima. This creates a manifest/code behavior mismatch because the file presents broader forecasting capabilities than it actually implements.
This code performs multiple file-write operations, including creating the output directory and saving model, metrics, and config artifacts. Although it logs the saved paths after writing, there is no prior disclosure or warning that running the script will modify the local filesystem under the selected output directory.
The inline comments distinguish LSTM sequence handling from tree-model flattening, but both branches call the same create_sequences and split functions without any flattening at that stage. The actual flattening for tree models happens later inside individual training functions, so the comment actively misdescribes what this code block does.