1010from tkinterdnd2 import TkinterDnD , DND_FILES
1111from urllib .parse import urlparse
1212
13+ from urllib .parse import urlparse
14+
15+ ALLOWED_HOSTS = {"www.ebay.com" , "ebay.com" }
16+
17+ def is_allowed_ebay_url (url ):
18+ try :
19+ parsed = urlparse (url )
20+ hostname = parsed .hostname .lower () if parsed .hostname else ""
21+ return hostname in ALLOWED_HOSTS
22+ except Exception :
23+ return False
24+
1325# =================== Utility Functions ===================
1426def resource_path (file_name ):
1527 base_path = getattr (sys , '_MEIPASS' , os .path .dirname (os .path .abspath (__file__ )))
@@ -31,15 +43,17 @@ def fetch_price(url):
3143 headers = {"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" }
3244
3345 # Clean eBay URLs
34- if "ebay.com" in url :
46+ if is_allowed_ebay_url ( url ) :
3547 url = clean_ebay_url (url )
48+ else :
49+ return "Error: URL not allowed"
3650
3751 resp = requests .get (url , headers = headers , timeout = 10 )
3852 resp .raise_for_status ()
3953 soup = BeautifulSoup (resp .text , "html.parser" )
4054
4155 # ---------------- eBay ----------------
42- if "ebay.com" in url :
56+ if is_allowed_ebay_url ( url ) :
4357 selectors = [
4458 'span[itemprop="price"]' , # auction
4559 'span#prcIsum' , # buy-it-now
0 commit comments