T09 · Insecure Skill Coding Practices
- Location
scripts/alarm_query.py:750- Finding
Bearer Token Forwarded to Unvalidated Snapshot URLs
- Content
View full analysis
str: """将抓拍地址规范化为可下载的绝对 URL。""" if not snapshot_url: return snapshot_url parsed = urlparse(snapshot_url) if parsed.scheme and parsed.netloc: return snapshot_url return urljoin( f"{self._build_service_base_url(self.config.media_service_port).rstrip('/')}/", snapshot_url.lstrip("/") ) ``` ```python def _materialize_snapshot_from_url(self, snapshot: Dict[str, Any]) -> Optional[str]: """将抓拍 URL 下载到本地,供上层发送图片。""" local_path = snapshot.get("local_path") if local_path not in (None, ""): return None snapshot_url = snapshot.get("url") if snapshot_url in (None, ""): return None resolved_url = self._resolve_snapshot_url(str(snapshot_url)) headers = {} if self.token: headers["Authorization"] = f"Bearer {self.token}" try: response = self.session.get( resolved_url, headers=headers, timeout=self.config.timeout ) response.raise_for_status() ``` ### Technical Analysis The media API can return a snapshot URL. When that URL is absolute, `_resolve_snapshot_url()` accepts it without validating its scheme, hostname, port, or relationship to the configured VisPatrol media service. The subsequent request attaches the decrypted VisPatrol bearer token regardless of the resolved destination. Consequently, a compromised or malicious API response can cause an authenticated request to an attacker-controlled origin. The same primitive can be used for SSRF against internal services reachable from the host. The default `requests` behavior also follows redirects. Even if the initial URL were validated, an unvalidated redirect c ...[truncated 1216 chars]- Remediation
View remediation
