T09 · Insecure Skill Coding Practices
- Location
scripts/safety_review.py:324- Finding
Implicit Demo Mode Returns Simulated Results for Real Medication Input
- Content
View full analysis
Vulnerability Details
File Location:
scripts/safety_review.py:324-326,scripts/safety_review.py:481-482, andscripts/safety_review.py:529-535
Vulnerability Type: Unsafe fail-open behavior and clinical output integrity failure
Risk Level: HighVulnerable 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_KEYpython 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_KEYvalue 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 callsDemoDataGenerator.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
View remediation
Remediation Suggestions
- Require explicit activation of demo mode. Replace implicit fallback behavior with logic equivalent to:
python self.demo_mode = demo_mode - When credentials are unavailable outside explicit demo mode, either perform the advertised local free-trial analysis or return a clear configuration error.
- Never return
"success": Truefor a simulated review submitted through a normal patient-review workflow. - Reject real medication or patient input in demo mode, or require an explicit acknowledgement that the output is simulated and unrelated to the input.
- Add a prominent machine-readable result type, such as
"result_type": "simulated_demo", in addition to human-readable warnings. - Add automated tests confirming that changing medication, allergy, condition, and renal-function inputs changes real review output.
- Add integration tests covering missing credentials, explicit demo mode, free-trial mode, and paid mode.
- Correct the documented database and interaction coverage so it accurately reflects the implemented data.
- Subject clinical rules and recommendations to qualified clinical validation before production use.
- Require explicit activation of demo mode. Replace implicit fallback behavior with logic equivalent to:
