feat(security): enhance input sanitization and expand blocked domains
- Add backtick escaping to `sanitizeInput` to prevent template literal injection - Expand `BLOCKED_DOMAINS` with additional disposable email providers - Add comprehensive tests for new security rules Sentinel-Ref: 2026-02-14 Security-Priority: Low (Enhancement) Co-authored-by: ragusa-it <196988693+ragusa-it@users.noreply.github.com>
This commit is contained in:
@@ -10,6 +10,7 @@ describe('Security Utils', () => {
|
||||
expect(sanitizeInput('foo & bar')).toBe('foo & bar');
|
||||
expect(sanitizeInput('"quotes"')).toBe('"quotes"');
|
||||
expect(sanitizeInput("'single quotes'")).toBe(''single quotes'');
|
||||
expect(sanitizeInput('`backticks`')).toBe('`backticks`');
|
||||
expect(sanitizeInput('>')).toBe('>');
|
||||
});
|
||||
|
||||
@@ -25,6 +26,10 @@ describe('Security Utils', () => {
|
||||
const expected = '<script>alert("XSS")</script>';
|
||||
expect(sanitizeInput(input)).toBe(expected);
|
||||
});
|
||||
|
||||
it('escapes template literal injection vectors', () => {
|
||||
expect(sanitizeInput('`${alert(1)}`')).toBe('`${alert(1)}`');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isValidEmail', () => {
|
||||
@@ -74,6 +79,9 @@ describe('Security Utils', () => {
|
||||
expect(isValidEmail('spam@mailinator.com')).toBe(false);
|
||||
expect(isValidEmail('bot@yopmail.com')).toBe(false);
|
||||
expect(isValidEmail('temp@temp-mail.org')).toBe(false);
|
||||
expect(isValidEmail('spam@sharklasers.com')).toBe(false);
|
||||
expect(isValidEmail('spam@guerrillamail.net')).toBe(false);
|
||||
expect(isValidEmail('spam@dispostable.com')).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects blocked domains regardless of case', () => {
|
||||
|
||||
@@ -14,7 +14,8 @@ export function sanitizeInput(input: string): string {
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
.replace(/'/g, "'")
|
||||
.replace(/`/g, "`");
|
||||
}
|
||||
|
||||
// Common disposable email providers and invalid domains
|
||||
@@ -27,6 +28,12 @@ const BLOCKED_DOMAINS = new Set([
|
||||
"guerrillamail.com",
|
||||
"10minutemail.com",
|
||||
"trashmail.com",
|
||||
"sharklasers.com",
|
||||
"guerrillamail.net",
|
||||
"guerrillamail.org",
|
||||
"guerrillamail.biz",
|
||||
"dispostable.com",
|
||||
"fake-email.com",
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user