T09 · Insecure Skill Coding Practices
- Location
assets/template/src/invoice_approval_bot/vision.py:58- Finding
Invoice-Borne Prompt Injection Can Expose Project Data and Forge Approval Fields
- Content
View full analysis
Vulnerability Details
File Location:
assets/template/src/invoice_approval_bot/vision.py:58-99
Vulnerability Type: Prompt injection through untrusted invoice images with excessive model filesystem access
Risk Level: Highpython def extract(self, image_path: Path, message_id: str) -> Dict[str, Any]: output_path = self.output_dir / f"{message_id}.json" command = [ self.codex_bin, "exec", "--ephemeral", "--skip-git-repo-check", "--sandbox", "read-only", "--cd", str(self.project_dir), "--image", str(image_path), "--output-schema", str(self.schema_path), "--output-last-message", str(output_path), "--color", "never", ] if self.model: command.extend(["--model", self.model]) command.append(VISION_PROMPT) try: completed = subprocess.run( command, capture_output=True, text=True, timeout=self.timeout_seconds, check=False, ) except (OSError, subprocess.TimeoutExpired) as exc: raise VisionError(f"Codex vision could not start or timed out: {exc}") from exc if completed.returncode != 0: detail = (completed.stderr or completed.stdout).strip()[-1500:] raise VisionError(f"Codex vision failed: {detail}") if not output_path.exists(): raise VisionError("Codex did not generate a structured extraction result") try: result = json.loads(output_path.read_text(encoding="utf-8")) except (OSError, json.JSONDecodeError) as exc: raise VisionError(f"Codex returned invalid JSON: {exc}") from exc if not isinstance(result, dict): raise VisionError("Codex extraction result must be a JSON object") return resultTechnical Analysis
The service passes an ...[truncated 4000 chars]
- Remediation
View remediation
Remediation Suggestions
-
Isolate the model working directory
- Create a fresh per-request directory containing only the invoice image and output schema.
- Run Codex from that directory instead of
project_dir. - Do not mount configuration,
.env, databases, previous images, extracted JSON, logs, or approval records into the model-visible filesystem.
-
Enforce isolation outside the prompt
- Use OS-level sandboxing, a dedicated low-privilege account, container filesystem restrictions, or an equivalent allowlisted file-access boundary.
- Treat the instruction not to follow image text as defense in depth only.
-
Validate extracted fields as untrusted data
- Apply strict maximum lengths and expected formats.
- Reject unexpected multiline text, control characters, file-like content, instruction-like prose, and anomalously long summaries.
- Independently validate invoice identifiers, dates, monetary values, tax identifiers, and arithmetic wherever possible.
-
Reduce information returned to uploaders
- Display only the minimum fields needed for confirmation.
- Do not return arbitrary free-form model output or detailed internal errors.
- Keep organization-specific configuration and prior processing data out of cards and replies.
-
Restrict production senders
- Require a non-empty
ALLOWED_SENDER_OPEN_IDSallowlist for production deployments. - Fail closed when real submission is enabled without an explicit sender allowlist.
- Require a non-empty
-
Add injection-focused tests
- Test invoice images containing instructions to read local files, disclose configuration, alter buyer fields, or forge confidence values.
- Verify that the model process cannot access any project or historical runtime file.
- Route anomalous extraction results to mandatory human review rather than automatic submission.
-
