The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/app/file/server/functions/sanitizeFileName.ts

19 lines
411 B

import path from 'path';
export function sanitizeFileName(fileName: string) {
const base = path.basename(fileName);
if (base !== fileName) {
throw new Error('error-invalid-file-name');
}
if (base === '.' || base.startsWith('..')) {
throw new Error('error-invalid-file-name');
}
if (!/^[a-zA-Z0-9._-]+$/.test(base)) {
throw new Error('error-invalid-characters-in-file-name');
}
return base;
}