Skip to content

Commit fa2b693

Browse files
committed
Simplify domain check hardening
1 parent b3f2104 commit fa2b693

1 file changed

Lines changed: 8 additions & 53 deletions

File tree

.github/workflows/check_domains.yml

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ on:
1616
jobs:
1717
Test:
1818
runs-on: ubuntu-latest
19-
timeout-minutes: 10
2019
strategy:
2120
fail-fast: false
2221
max-parallel: 10
@@ -72,82 +71,38 @@ jobs:
7271
- name: Check domain redirections
7372
shell: python
7473
run: |
75-
import time
76-
from urllib.parse import urlparse
77-
7874
import requests
79-
from requests.adapters import HTTPAdapter
80-
from urllib3.util.retry import Retry
81-
82-
VALID_DESTINATIONS = {"ultralytics.com", "www.ultralytics.com", "yolo11.com", "www.yolo11.com"}
83-
REQUEST_TIMEOUT = (10, 20)
84-
BASE_DELAY = 5
85-
MAX_DELAY = 120
86-
USER_AGENT = (
87-
"Mozilla/5.0 (compatible; UltralyticsDomainCheck/1.0; +https://github.com/ultralytics/docs)"
88-
)
89-
90-
def build_session():
91-
"""Create a session with lightweight retries for transient HTTP errors."""
92-
retry = Retry(
93-
total=2,
94-
connect=2,
95-
read=2,
96-
status=2,
97-
backoff_factor=1,
98-
status_forcelist=(429, 500, 502, 503, 504),
99-
allowed_methods=frozenset(["GET"]),
100-
raise_on_status=False,
101-
)
102-
adapter = HTTPAdapter(max_retries=retry)
103-
session = requests.Session()
104-
session.headers.update({"User-Agent": USER_AGENT})
105-
session.mount("https://", adapter)
106-
session.mount("http://", adapter)
107-
return session
108-
109-
def is_valid_destination(url):
110-
"""Check the final redirect hostname against approved destinations."""
111-
hostname = (urlparse(url).hostname or "").lower()
112-
return hostname in VALID_DESTINATIONS
75+
import time
11376
114-
def check_domain_redirection(domain, prefix, session, max_attempts=5):
77+
def check_domain_redirection(domain, prefix, max_attempts=5):
11578
"""Check if the given domain redirects correctly, with exponential delays between retries."""
79+
valid_destinations = ["ultralytics.com", "yolo11.com"]
11680
url = f"https://{prefix}{domain}"
11781
print(f"\nChecking {url}")
11882
11983
for attempt in range(max_attempts):
120-
response = None
12184
try:
12285
if attempt > 0:
123-
delay = min(BASE_DELAY * (2 ** attempt), MAX_DELAY) # 10, 20, 40, 80...
86+
delay = min(5 * (2 ** attempt), 120) # 10, 20, 40, 80...
12487
print(f"Retrying in {delay}s (attempt {attempt + 1}/{max_attempts})")
12588
time.sleep(delay)
12689
127-
response = session.get(url, allow_redirects=True, timeout=REQUEST_TIMEOUT, stream=True)
90+
response = requests.get(url, allow_redirects=True, timeout=10)
12891
response.raise_for_status()
12992
130-
if is_valid_destination(response.url) and response.status_code == 200:
131-
print(f"Success ✅ -> {response.url}")
93+
if any(dest in response.url for dest in valid_destinations) and response.status_code == 200:
94+
print("Success ✅")
13295
return True
13396
134-
print(f"Unexpected final URL: {response.url} (status {response.status_code}) ❌")
135-
return False
136-
13797
except requests.RequestException as e:
13898
print(f"Error: {e}")
13999
if attempt == max_attempts - 1:
140100
print(f"Failed after {max_attempts} attempts ❌")
141101
return False
142-
finally:
143-
if response is not None:
144-
response.close()
145102
146103
return False
147104
148-
session = build_session()
149-
success = check_domain_redirection('${{ matrix.domain }}', '${{ matrix.prefix }}', session)
150-
session.close()
105+
success = check_domain_redirection('${{ matrix.domain }}', '${{ matrix.prefix }}')
151106
if not success:
152107
raise Exception(f"Domain check failed for ${{ matrix.domain }} with prefix '${{ matrix.prefix }}'")
153108

0 commit comments

Comments
 (0)