|
4 | 4 | import json |
5 | 5 | from datetime import datetime |
6 | 6 | from typing import Optional, Union |
| 7 | +from urllib.parse import urlparse |
7 | 8 |
|
8 | 9 | # Third-party imports |
9 | 10 | from fastapi import APIRouter, Header, HTTPException, Path, Query, Request |
@@ -62,8 +63,14 @@ async def get_xposed_breaches( |
62 | 63 | raise HTTPException(status_code=400, detail="Invalid Breach ID") |
63 | 64 | query.key_filter(client.key("xon_breaches", breach_id), "=") |
64 | 65 | elif domain: |
| 66 | + # Try to extract domain from URL if a full URL is provided |
65 | 67 | if not validate_domain(domain): |
66 | | - raise HTTPException(status_code=400, detail="Invalid Domain") |
| 68 | + parsed = urlparse(domain) |
| 69 | + extracted = parsed.netloc or parsed.path.strip("/") |
| 70 | + if extracted and validate_domain(extracted): |
| 71 | + domain = extracted |
| 72 | + else: |
| 73 | + raise HTTPException(status_code=400, detail="Invalid Domain") |
67 | 74 | query.add_filter("domain", "=", domain) |
68 | 75 | else: |
69 | 76 | query.order = ["-timestamp"] |
@@ -131,6 +138,8 @@ async def get_xposed_breaches( |
131 | 138 |
|
132 | 139 | return BreachListResponse(status="success", exposedBreaches=breach_details) |
133 | 140 |
|
| 141 | + except HTTPException: |
| 142 | + raise |
134 | 143 | except Exception as e: |
135 | 144 | await send_exception_email( |
136 | 145 | api_route="GET /v1/breaches", |
|
0 commit comments