@@ -115,17 +115,68 @@ def secure_delete(self, file_path):
115115 pass
116116
117117 def validate_email (self , email ):
118- """Validate email format with comprehensive regex."""
119- email_regex = r'^[a-zA-Z0-9]([-._a-zA-Z0-9]*[a-zA-Z0-9])*@[a-zA-Z0-9]([-._a-zA-Z0-9]*[a-zA-Z0-9])*\.[a-zA-Z]{2,}$'
118+ """
119+ Validate email format using a non-vulnerable approach.
120+
121+ This implementation uses a simpler regex without overlapping quantifiers
122+ to avoid ReDoS (Regular Expression Denial of Service) attacks.
123+ It also includes length validation to prevent excessively long inputs.
124+ """
125+ # Reject emails that are too long (reasonable max is ~254 chars per RFC 5321)
126+ if len (email ) > 254 :
127+ messagebox .showerror (
128+ "Invalid Email" ,
129+ "Email address is too long. Maximum 254 characters allowed."
130+ )
131+ return False
132+
133+ # Use a simpler, non-vulnerable regex pattern
134+ # This pattern avoids nested quantifiers and overlapping alternatives
135+ email_regex = r'^[a-zA-Z0-9]([a-zA-Z0-9._-]{0,251}[a-zA-Z0-9])?@[a-zA-Z0-9]([a-zA-Z0-9.-]{0,251}[a-zA-Z0-9])?(\.[a-zA-Z]{2,})?$'
136+
120137 if not re .match (email_regex , email ):
121138 messagebox .showerror (
122139 "Invalid Email" ,
123140 "Invalid email format. Please ensure:\n "
124- "- No special characters except . - _\n "
125- "- Valid domain format\n "
126- "- At least 2 character domain extension"
141+ "- Starts and ends with alphanumeric characters\n "
142+ "- Contains valid domain format\n "
143+ "- Uses only . - _ special characters"
144+ )
145+ return False
146+
147+ # Additional validation: check for at least one @ and valid domain
148+ if email .count ('@' ) != 1 :
149+ messagebox .showerror (
150+ "Invalid Email" ,
151+ "Email must contain exactly one '@' symbol."
152+ )
153+ return False
154+
155+ local_part , domain = email .rsplit ('@' , 1 )
156+
157+ # Validate local part (before @)
158+ if not local_part or len (local_part ) > 64 :
159+ messagebox .showerror (
160+ "Invalid Email" ,
161+ "Local part (before @) must be 1-64 characters."
162+ )
163+ return False
164+
165+ # Validate domain part (after @)
166+ if not domain or len (domain ) < 3 :
167+ messagebox .showerror (
168+ "Invalid Email" ,
169+ "Domain must be at least 3 characters long."
127170 )
128171 return False
172+
173+ if not re .match (r'^[a-zA-Z0-9]([a-zA-Z0-9.-]*[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+$' , domain ):
174+ messagebox .showerror (
175+ "Invalid Email" ,
176+ "Invalid domain format."
177+ )
178+ return False
179+
129180 return True
130181
131182 def validate_password_strength (self , password ):
@@ -764,4 +815,9 @@ def run(self):
764815# version: 1.0.0
765816# modified: 2025-05-20 - 10:30:00
766817# comments: Initial Python conversion from bash script
767- # -------------------------------------------------------------------------- #
818+ # -------------------------------------------------------------------------- #
819+ # version: 1.0.1
820+ # modified: 2025-10-31 - 21:00:00
821+ # comments: Fixed GitHub Error: Inefficient regular expression
822+ # Fixed Weknesses: CWE-1333, CWE-400, CWE-730
823+ # -------------------------------------------------------------------------- #
0 commit comments