T09 · Insecure Skill Coding Practices
- Location
scripts/query_holiday.py:236- Finding
Unrestricted URL Fetching Enables Server-Side Request Forgery
- Content
View full analysis
str: """Fetch and extract the main body text from a gov.cn notice page.""" response = requests.get( url, headers={ "User-Agent": "Mozilla/5.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", }, timeout=20, ) response.raise_for_status() response.encoding = response.apparent_encoding or response.encoding or "utf-8" html = response.text text = _extract_div_text( html, lambda attrs: "trs_editor_view" in (attrs.get("class") or "").split(), ) if not text: text = _extract_div_text(html, lambda attrs: attrs.get("id") == "UCAP-CONTENT") if not text: raise SystemExit(f"Could not extract notice body from {url}") return text ``` The URL is also exposed directly through the CLI: ```python body_parser = sub.add_parser("body", help="Fetch a notice body") body_parser.add_argument("url") ``` ```python if args.command == "body": print_body(args.url) return ``` ```python def print_body(url: str) -> None: print(fetch_notice_body(url)) ``` ### Technical Analysis The `body` command accepts an arbitrary URL and passes it directly to `requests.get()`. The implementation does not validate: - The URL scheme - The destination hostname - The resolved IP address - The destination port - Redirect destinations - Whether the target belongs to the intended `gov.cn` domain Although the documented purpose is to retrieve official government notices, this trust boundary is not enforced in code. The `requests` library also follows redirects by default, so even an initially acce ...[truncated 1761 chars]- Remediation
View remediation
