Skip to content

Commit

Permalink
fix: added timeouts to the requests to fix Bandit issue
Browse files Browse the repository at this point in the history
  • Loading branch information
creyD committed Nov 25, 2024
1 parent 364e07d commit 5daddf2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions creyPY/services/auth0/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

@cached(cache)
def get_management_token() -> str:
re = requests.post(
response = requests.post(
f"https://{AUTH0_DOMAIN}/oauth/token",
json={
"client_id": AUTH0_CLIENT_ID,
"client_secret": AUTH0_CLIENT_SECRET,
"audience": f"https://{AUTH0_DOMAIN}/api/v2/", # This should be the management audience
"grant_type": "client_credentials",
},
timeout=5, # Add a timeout parameter to avoid hanging requests
).json()
return re["access_token"]
return response["access_token"]
5 changes: 5 additions & 0 deletions creyPY/services/auth0/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get_user(sub) -> dict:
re = requests.get(
f"https://{AUTH0_DOMAIN}/api/v2/users/{sub}",
headers={"Authorization": f"Bearer {get_management_token()}"},
timeout=5,
)
if re.status_code != 200:
raise HTTPException(re.status_code, re.json())
Expand All @@ -65,6 +66,7 @@ def patch_user(input_obj: dict, sub) -> dict:
f"https://{AUTH0_DOMAIN}/api/v2/users/{sub}",
headers={"Authorization": f"Bearer {get_management_token()}"},
json=input_obj,
timeout=5,
)
if re.status_code != 200:
raise HTTPException(re.status_code, re.json())
Expand Down Expand Up @@ -92,6 +94,7 @@ def request_verification_mail(sub: str) -> None:
f"https://{AUTH0_DOMAIN}/api/v2/jobs/verification-email",
headers={"Authorization": f"Bearer {get_management_token()}"},
json={"user_id": sub},
timeout=5,
)
if re.status_code != 201:
raise HTTPException(re.status_code, re.json())
Expand All @@ -109,6 +112,7 @@ def create_user_invite(email: str) -> dict:
"verify_email": False,
"app_metadata": {"invitedToMyApp": True},
},
timeout=5,
)
if re.status_code != 201:
raise HTTPException(re.status_code, re.json())
Expand All @@ -124,6 +128,7 @@ def password_change_mail(email: str) -> bool:
"email": email,
"connection": "Username-Password-Authentication",
},
timeout=5,
)

if re.status_code != 200:
Expand Down

0 comments on commit 5daddf2

Please sign in to comment.