Skip to content

Commit

Permalink
bookmarkmgr: Prevent IP addresses in canonical URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
lubo committed Jan 12, 2025
1 parent a8d2974 commit 1cde7e8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bookmarkmgr/bookmarkmgr/checks/duplicate_link.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from asyncio import Event
from datetime import datetime
from ipaddress import ip_address
from urllib.parse import parse_qsl, urlencode, urlparse

from bookmarkmgr import scraper
Expand All @@ -17,6 +18,15 @@ def __lt__(self, other: "_Link") -> bool:
)


def _is_ip_address(string: str) -> bool:
try:
ip_address(string)
except ValueError:
return False

return True


def _remove_query_from_url(url: str) -> str:
parsed_url = urlparse(url)

Expand Down Expand Up @@ -116,6 +126,7 @@ def get_canonical_url(page: scraper.Page, url: str) -> str | None:
or parsed_canonical_url.hostname.endswith(
f".{parsed_url.hostname}",
)
or _is_ip_address(parsed_canonical_url.hostname)
else parsed_canonical_url.netloc
),
query=urlencode(
Expand Down

0 comments on commit 1cde7e8

Please sign in to comment.