Skip to content

Commit 8e807eb

Browse files
committed
Fix: Allow single-character email prefixes
- Updated email validation regex to accept single-char prefixes (e.g., a@domain.com) - Added Claude Code files to .gitignore
1 parent d21bca9 commit 8e807eb

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ docker/.env
4141
docker/*.env.local
4242
docker/*.env.production
4343
docker/build.log
44+
45+
# Claude Code
46+
.claude/
47+
CLAUDE.md

api-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ app.post('/api/inbox/create', strictLimiter, async (req, res) => {
437437
}
438438

439439
// Validate email format with enhanced checks
440-
const emailRegex = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,48}[a-zA-Z0-9]@[a-zA-Z0-9][a-zA-Z0-9.-]*\.[a-zA-Z]{2,}$/;
440+
const emailRegex = /^[a-zA-Z0-9]([a-zA-Z0-9._-]{0,48}[a-zA-Z0-9])?@[a-zA-Z0-9][a-zA-Z0-9.-]*\.[a-zA-Z]{2,}$/;
441441

442442
if (!email || !emailRegex.test(email) || email.length > 100 || email.includes('..')) {
443443
await logSecurityEvent('invalid_input', {

frontend/app.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class SpamEater {
244244

245245
// Security: Enhanced email validation
246246
isValidEmail(email) {
247-
const emailRegex = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,48}[a-zA-Z0-9]@[a-zA-Z0-9][a-zA-Z0-9.-]*\.[a-zA-Z]{2,}$/;
247+
const emailRegex = /^[a-zA-Z0-9]([a-zA-Z0-9._-]{0,48}[a-zA-Z0-9])?@[a-zA-Z0-9][a-zA-Z0-9.-]*\.[a-zA-Z]{2,}$/;
248248

249249
// Basic regex check
250250
if (!emailRegex.test(email.toLowerCase()) || email.length > 100) {
@@ -338,20 +338,20 @@ class SpamEater {
338338
async createEmail() {
339339
const input = document.getElementById('emailPrefix');
340340
const prefix = input?.value?.trim();
341-
341+
342342
if (!prefix) {
343343
this.showToast('Please enter an email prefix', 'error');
344344
input?.focus();
345345
return;
346346
}
347-
347+
348348
// Security: Enhanced validation
349-
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,48}[a-zA-Z0-9]$/.test(prefix)) {
349+
if (!/^[a-zA-Z0-9]([a-zA-Z0-9._-]{0,48}[a-zA-Z0-9])?$/.test(prefix)) {
350350
this.showToast('Invalid email prefix format', 'error');
351351
input?.focus();
352352
return;
353353
}
354-
354+
355355
if (prefix.includes('..')) {
356356
this.showToast('Consecutive dots not allowed', 'error');
357357
input?.focus();
@@ -422,27 +422,27 @@ class SpamEater {
422422
}
423423

424424
// Security: Enhanced validation
425-
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,48}[a-zA-Z0-9]$/.test(prefix)) {
425+
if (!/^[a-zA-Z0-9]([a-zA-Z0-9._-]{0,48}[a-zA-Z0-9])?$/.test(prefix)) {
426426
this.showToast('Invalid email prefix format', 'error');
427427
input?.focus();
428428
return;
429429
}
430-
430+
431431
if (prefix.includes('..')) {
432432
this.showToast('Consecutive dots not allowed', 'error');
433433
input?.focus();
434434
return;
435435
}
436-
436+
437437
// Normalize email to lowercase
438438
const email = `${prefix}@${this.domain}`.toLowerCase();
439-
439+
440440
// Verify it's a valid email
441441
if (!this.isValidEmail(email)) {
442442
this.showToast('Invalid email format', 'error');
443443
return;
444444
}
445-
445+
446446
// Check if it's the same email (case-insensitive)
447447
if (email === this.currentEmail?.toLowerCase()) {
448448
this.showToast('Already viewing this inbox', 'error');

haraka/plugins/save_email.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ function generateHash(text) {
8585

8686
// Security: Validate email address format with stricter rules
8787
function isValidEmail(email) {
88-
// More strict email validation
89-
const emailRegex = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,48}[a-zA-Z0-9]@[a-zA-Z0-9][a-zA-Z0-9.-]*\.[a-zA-Z]{2,}$/;
88+
// More strict email validation (allows single-char prefixes like "a@domain.com")
89+
const emailRegex = /^[a-zA-Z0-9]([a-zA-Z0-9._-]{0,48}[a-zA-Z0-9])?@[a-zA-Z0-9][a-zA-Z0-9.-]*\.[a-zA-Z]{2,}$/;
9090

9191
// Additional validation
9292
if (!emailRegex.test(email) || email.length > 100) return false;

0 commit comments

Comments
 (0)