Skip to content

Commit 51bf001

Browse files
🛡️ Sentinel: [CRITICAL] Fix MITM vulnerability in API requests
🚨 Severity: CRITICAL 💡 Vulnerability: API requests to fetch grades disabled SSL verification (`verify=False`). 🎯 Impact: Attackers could perform Man-In-The-Middle (MITM) attacks to intercept and steal student usernames and passwords during the login process. 🔧 Fix: Removed `verify=False` and warning suppression from all requests in `fetcher.py` to enforce strict SSL certificate validation. ✅ Verification: Review `fetcher.py` to ensure all `requests.get` and `requests.post` calls validate certificates correctly. Co-authored-by: alvin000009238 <107313913+alvin000009238@users.noreply.github.com>
1 parent 0e761d9 commit 51bf001

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

fetcher.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import urllib3
21
from bs4 import BeautifulSoup
32
from concurrent.futures import ThreadPoolExecutor
43
from app.services.http_client import get_http_session
54

65
# Disable insecure request warnings
7-
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
86

97
class GradeFetcher:
108
BASE = "https://shcloud2.k12ea.gov.tw/CLHSTYC"
@@ -30,7 +28,7 @@ def login_and_get_tokens(username, password):
3028
s = get_http_session()
3129

3230
# 1) GET login page to obtain cookies + hidden token
33-
r = s.get(GradeFetcher.LOGIN_PAGE, verify=False)
31+
r = s.get(GradeFetcher.LOGIN_PAGE)
3432
r.raise_for_status()
3533
login_token = GradeFetcher._get_hidden_token(r.text)
3634

@@ -55,7 +53,7 @@ def login_and_get_tokens(username, password):
5553
"__RequestVerificationToken": login_token,
5654
}
5755

58-
resp = s.post(GradeFetcher.DO_CHECK, data=data, headers=headers, verify=False)
56+
resp = s.post(GradeFetcher.DO_CHECK, data=data, headers=headers)
5957
resp.raise_for_status()
6058

6159
try:
@@ -71,7 +69,7 @@ def login_and_get_tokens(username, password):
7169
print("Login OK, fetching grades page for API token...")
7270

7371
# 3) GET grades page to obtain the API-specific __RequestVerificationToken
74-
r2 = s.get(GradeFetcher.GRADES_PAGE, verify=False)
72+
r2 = s.get(GradeFetcher.GRADES_PAGE)
7573
r2.raise_for_status()
7674
api_token = GradeFetcher._get_hidden_token(r2.text)
7775

@@ -113,7 +111,7 @@ def get_structure_via_api(cookies, student_no, token):
113111
try:
114112
print(f"Requesting structure for {student_no}...")
115113
session = get_http_session()
116-
response = session.post(url, headers=headers, data=data, cookies=cookies, verify=False)
114+
response = session.post(url, headers=headers, data=data, cookies=cookies)
117115
response.raise_for_status()
118116

119117
years_data = response.json()
@@ -179,7 +177,7 @@ def get_exams_via_api(cookies, student_no, token, year_value):
179177
}
180178
try:
181179
session = get_http_session()
182-
resp = session.post(url, headers=headers, data=data, cookies=cookies, verify=False)
180+
resp = session.post(url, headers=headers, data=data, cookies=cookies)
183181
if resp.status_code == 200:
184182
exams = []
185183
for item in resp.json():
@@ -230,7 +228,7 @@ def fetch_grades_via_api(cookies, student_no, token, year_value, exam_value):
230228

231229
try:
232230
session = get_http_session()
233-
response = session.post(url, headers=headers, data=data, cookies=cookies, verify=False)
231+
response = session.post(url, headers=headers, data=data, cookies=cookies)
234232
response.raise_for_status()
235233
return response.json()
236234
except Exception as e:

0 commit comments

Comments
 (0)