Last active
December 15, 2025 16:04
-
-
Save mcsee/f9a92cb792212c40b0a3e2c503ab95df to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
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
| def reset_password(email_from_ui): | |
| # email_from_ui = "victim@gmàil.com" | |
| # (attacker's Unicode address from UI) | |
| # Database with utf8mb4_unicode_ci collation | |
| # treats 'à' = 'a', so this query finds: | |
| # [email protected] stored in the database | |
| cursor.execute( | |
| "SELECT * FROM users WHERE email = %s", | |
| (email_from_ui,) | |
| ) | |
| user = cursor.fetchone() | |
| if user: | |
| # CRITICAL MISTAKE: Trusting UI data | |
| # Sends email to the attacker's Unicode address | |
| # instead of using user['email'] from DB | |
| send_reset_email(email_from_ui) | |
| # Should use: send_reset_email(user['email']) | |
| return True | |
| return False | |
| # Attack scenario: | |
| # DB stores: [email protected] (ASCII, legitimate) | |
| # Attacker controls: attacker@gmàil.com (Unicode) | |
| # Attacker requests reset with: victim@gmàil.com | |
| # Collation matches the victim's account | |
| # Email sent to: victim@gmàil.com (attacker's address!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment