T09 · Insecure Skill Coding Practices
- Location
- skills/persian_x_radar/search.py:119
- Finding
- Fabricated fallback data can trigger operational intelligence alerts<![CDATA[ ## Vulnerability Details **File Location**: `skills/persian_x_radar/search.py:119-160`; downstream alert processing occurs at `skills/persian_x_radar/agent.py:156-160` and `skills/persian_x_radar/agent.py:205-211` **Vulnerability Type**: Failure handling with unsafe production mock data **Risk Level**: High ### Vulnerable Code ```python def search_with_fallback( req: SearchRequest, x_keyword_search: Optional[ToolFn] = None, x_semantic_search: Optional[ToolFn] = None, web_search: Optional[ToolFn] = None, ) -> List[RawTweet]: query = build_x_query(req) tool_order = [ ("x_keyword_search", x_keyword_search), ("x_semantic_search", x_semantic_search), ("web_search", web_search), ] for _, tool_fn in tool_order: if tool_fn is None: continue try: rows = tool_fn(query=query) if rows: return _normalize_tool_rows(rows) except Exception: continue now = datetime.now(timezone.utc) # Deterministic local mock data to keep the skill runnable without external tools. mock = [ RawTweet( id="m1", author="@analyst_fa", timestamp=now - timedelta(hours=2), text="بحث درباره حمله و موشک در حال افزایش است", likes=420, retweets=130, replies=12, url="https://x.com/analyst_fa/status/1", ), RawTweet( id="m2", author="@iran_watch", timestamp=now - timedelta(hours=3), text="گزارش هایی از اعتراض در چند شهر منتشر شده است", likes=170, retweets=42, replies=9, url="https://x.com/iran_watch/status/2", ), ] return mock ``` The returned rows are subsequently processed and dispatched as ordinary intelligence: ```python tweets = search_with_fallback( req=req, x_keyword_search=self.tools.x_keyword_sea ...[truncated 2397 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove implicit mock records from the production search path. 2. Return an explicit status such as `search_unavailable`, including sanitized provider failure information. 3. Distinguish between: - A successful search with zero results. - Missing search tools. - Provider errors or timeouts. 4. Permit mock data only when an explicit test or development flag is enabled. 5. Add an immutable `is_mock` or `source_type` attribute to simulated records. 6. Block alert dispatch, billing, trend-state updates, escalation history, and daily-history writes whenever results are simulated. 7. Replace broad `except Exception` handling with specific exception handling and structured logging. 8. Add integration tests confirming that provider failure cannot produce a successful live-intelligence report or external alert. ]]>
