T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/safety_review.py:324
- Finding
- Implicit Demo Mode Returns Simulated Results for Real Medication Input## Vulnerability Details **File Location**: `scripts/safety_review.py:324-326`, `scripts/safety_review.py:481-482`, and `scripts/safety_review.py:529-535` **Vulnerability Type**: Unsafe fail-open behavior and clinical output integrity failure **Risk Level**: High ### Vulnerable Code ```python def __init__(self, demo_mode: bool = False): self.billing = SkillPayBilling() self.trial = TrialManager("drug-safety-review") self.demo_mode = demo_mode or not API_KEY ``` ```python def review(self, medications: List[Dict], allergies: List[Dict] = None, patient_data: Dict = None) -> Dict[str, Any]: if self.demo_mode: return DemoDataGenerator.generate_demo_review() ``` ```python def process(self, medications: List[Dict], allergies: List[Dict] = None, patient_data: Dict = None, user_id: str = "") -> Dict[str, Any]: if self.demo_mode: print(self.get_message('demo_mode_active'), file=sys.stderr) return { 'success': True, 'demo_mode': True, 'trial_mode': False, 'trial_remaining': 0, 'balance': None, 'review': self.review(medications, allergies, patient_data) } ``` ### Technical Analysis The reviewer automatically enables demo mode whenever the module-level `SKILLPAY_API_KEY` value is absent. Demo mode is therefore not restricted to an explicit user request such as `--demo`. Once enabled, `review()` ignores the supplied medication, allergy, and patient data and calls `DemoDataGenerator.generate_demo_review()`. The result is nevertheless returned with `"success": True`. This is a fail-open design: missing billing configuration changes the semantic meaning of the operation from a patient-specific review to a simulated review rather than stopping execution with a clear error. The behavior conflicts with documentation that advertises real free-trial reviews without an API key. A caller following that documentation can r ...[truncated 2233 chars]
- Remediation
- ## Remediation Suggestions 1. Require explicit activation of demo mode. Replace implicit fallback behavior with logic equivalent to: ```python self.demo_mode = demo_mode ``` 2. When credentials are unavailable outside explicit demo mode, either perform the advertised local free-trial analysis or return a clear configuration error. 3. Never return `"success": True` for a simulated review submitted through a normal patient-review workflow. 4. Reject real medication or patient input in demo mode, or require an explicit acknowledgement that the output is simulated and unrelated to the input. 5. Add a prominent machine-readable result type, such as `"result_type": "simulated_demo"`, in addition to human-readable warnings. 6. Add automated tests confirming that changing medication, allergy, condition, and renal-function inputs changes real review output. 7. Add integration tests covering missing credentials, explicit demo mode, free-trial mode, and paid mode. 8. Correct the documented database and interaction coverage so it accurately reflects the implemented data. 9. Subject clinical rules and recommendations to qualified clinical validation before production use.
