🛡️ Sentinel: [Enhancement] Harden input sanitization and expand blocked domains #55
@@ -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
sanitizeInputkeeps a runtimetypeof input !== "string"guard, but the function signature isinput: string/ returnsstring. This makes the guard effectively dead code for typed callers and encourages unsound usage (tests even call it with@ts-ignore). Consider either removing the non-string branch, or widening the function’s type (e.g., acceptunknown) and returning a guaranteed string (via coercion) to keep the API contract consistent.