T09 · Insecure Skill Coding Practices
- Location
scripts/internalize.py:67- Finding
Arbitrary Code Execution Through Unsafe PyTorch Checkpoint Deserialization
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
The skill has a coherent Doc-to-LoRA purpose, but setup and checkpoint loading create review-worthy code-execution risk unless users tightly control the repository, dependencies, and model files.
Install only in a trusted Doc-to-LoRA repository clone, inspect the repository's install_mac.sh before setup, prefer pinned/locked dependencies, and load only official or hash-verified checkpoints. Protect HF_TOKEN and avoid the unpinned npx install path unless you trust the installer and source revision.
scripts/internalize.py:67Arbitrary Code Execution Through Unsafe PyTorch Checkpoint Deserialization
scripts/setup.sh:44Execution of an Unverified Setup Script From the Enclosing Repository
scripts/setup.sh:62Unpinned Python Dependencies Installed From a Mutable Package Source
README.md:39Documentation Recommends Unpinned npx Installer Execution
Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.
if [ -z "$HF_TOKEN" ]; then
echo "ERROR: HF_TOKEN is not set."
echo "Gemma 2 2B is a gated model requiring a HuggingFace access token."
echo "1. Get a token at: https://huggingface.co/settings/tokens"
echo "2. Accept Gemma license at: https://huggingface.co/google/gemma-2-2b-it"
echo "3. Run: export HF_TOKEN=hf_your_token_here"
The README instructs users to run npx skills add <owner>/doc-to-lora-skill without pinning an exact package version or commit, which can cause execution of whatever package version is current at install time. If the referenced package or one of its transitive dependencies is compromised, users may execute unintended code during installation.
The skill describes use of environment secrets (HF_TOKEN) and file read/write operations, but it does not declare any explicit tool scope or allowed-tools restrictions. That creates an authorization gap: an agent may execute the skill with broader capabilities than intended, increasing the chance that sensitive files or environment variables are accessed or written without clear policy boundaries.
The code explicitly calls torch.load(..., weights_only=False), which uses Python pickle-style deserialization and can execute attacker-controlled code during checkpoint loading. Although the script warns to use only trusted checkpoints, the --checkpoint argument is user-controllable and the safety relies entirely on operator discipline rather than technical enforcement.
# weights_only=False is needed: checkpoint contains config dataclasses
# (AggregatorConfig, LoraConfig, HypernetConfig) not just tensors.
# Only load from trusted sources.
state_dict = torch.load(checkpoint_path, map_location="cpu", weights_only=False)
if device_map != "cuda":
state_dict["ctx_encoder_args"].quantize_ctx_encoder = False
else:
This code loads a model by name using load(args.model, ...), which commonly fetches model artifacts from a remote repository if not already cached. Although the script prints the model name, it does not explicitly warn users that running it may initiate network access or remote downloads.
Detected: suspicious.dynamic_code_execution