T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/doc_preview_html_url.py:244- Finding
Unrestricted Direct URL Fetch Enables SSRF and Local File Disclosure
- Content
View full analysis
str: """Fetch HTML directly from a user-provided URL (no SDK involved).""" print(f"[INFO] Fetching HTML from direct URL: {url}") req = Request(url) try: with urlopen(req) as resp: html_bytes = resp.read() except HTTPError as e: print( f"[ERROR] HTTP error when fetching direct HTML URL: " f"status={e.code}, reason={e.reason}", file=sys.stderr, ) sys.exit(1) except URLError as e: print(f"[ERROR] Failed to fetch direct HTML URL: {e.reason}", file=sys.stderr) sys.exit(1) except Exception as exc: print(f"[ERROR] Unexpected error when fetching direct HTML URL: {exc}", file=sys.stderr) sys.exit(1) return html_bytes.decode("utf-8", errors="replace") ``` ```python parser.add_argument( "--direct-url", dest="direct_url", type=str, default=None, help=( "If provided, skip SDK and use this HTML URL directly. " "Useful for debugging sample links such as the ones in official docs." ), ) ... if args.direct_url: # Direct URL mode: no SDK required. html = fetch_html_from_direct_url(args.direct_url) ``` ```python try: preview_link = extract_preview_link(html) except ValueError as exc: print(f"[ERROR] Failed to extract preview link from HTML: {exc}", file=sys.stderr) # Optionally dump a small prefix of HTML to help debugging print(html[:400], file=sys.stderr) sys.exit(1) try: token = extract_token_from_html(html) except ValueError as exc: print(f"[ERROR] Failed to extract token from HTML: {exc}", file=sys.stderr) # Optionally dump a small prefix of HTML to help ...[truncated 2571 chars]- Remediation
View remediation
