T09 · Insecure Skill Coding Practices
- Location
scripts/model_switch.py:73- Finding
Target Model Is Written Without Provider Validation
- Content
View full analysis
Vulnerability Details
File Location:
scripts/model_switch.py:73-77and duplicate implementation inmodel_switch.py:61-72
Vulnerability Type: Missing input validation and configuration integrity checks
Risk Level: MediumVulnerable Code
python new_config.setdefault('agents', {}).setdefault('defaults', {}).setdefault('model', {}) new_config['agents']['defaults']['model']['primary'] = self.new_model with open(self.config_path, 'w', encoding='utf-8') as f: json.dump(new_config, f, indent=4, ensure_ascii=False)The root-level duplicate implements the same unsafe operation:
python if 'agents' not in new_config: new_config['agents'] = {} if 'defaults' not in new_config['agents']: new_config['agents']['defaults'] = {} if 'model' not in new_config['agents']['defaults']: new_config['agents']['defaults']['model'] = {} new_config['agents']['defaults']['model']['primary'] = self.new_model with open(OPENCLAW_CONFIG_PATH, 'w', encoding='utf-8') as f: json.dump(new_config, f, indent=4, ensure_ascii=False)Technical Analysis
Both scripts take the target model directly from the positional command-line argument and assign it to
agents.defaults.model.primary. Neither implementation parsesmodels.providersor verifies that the supplied identifier corresponds to a configured model.This contradicts the validation behavior documented in
SKILL.mdandREADME.md. Validation is described only as an agent workflow instruction and is not enforced by the code. Consequently, direct standalone execution, invocation by another automation component, or an agent failure to follow the documented workflow bypasses the safeguard entirely.The post-restart health check only verifies that the gateway command succeeds and that its output contains
running. It does not verify that the newly selected model exists, can be initialized, or can successfully process a request. T ...[truncated 1630 chars]- Remediation
View remediation
Remediation Suggestions
- Load and normalize the configured model identifiers from
models.providersbefore creating a backup or modifying the configuration. - Require the supplied value to resolve to exactly one configured canonical model identifier. Reject unknown and ambiguous partial matches.
- If aliases are supported, maintain an explicit alias map and resolve aliases only to models present in the current configuration.
- Apply the same validation in both
scripts/model_switch.pyand the root-level duplicate, or remove the duplicate and maintain one authoritative implementation. - Validate the configuration schema and ensure
agents,defaults, andmodelare objects before modifying nested fields. - After restart, perform a model-level readiness or minimal inference check for the selected model instead of relying solely on the gateway's generic
runningstatus. - If model-level verification fails, restore the original configuration atomically and verify that the previous model is operational.
- Write the updated configuration to a securely created temporary file in the same directory, flush and synchronize it, preserve restrictive permissions, and atomically replace the original file.
- Load and normalize the configured model identifiers from
