diff --git a/docs/emoji.md b/docs/emoji.md index abfd13632..143563f86 100644 --- a/docs/emoji.md +++ b/docs/emoji.md @@ -74,6 +74,9 @@ The fields of `Meta` are currently not used or checked when importing emoji, exc For each `Emoji`: - `downloaded`: should always be true. If the field is missing or not truthy, the emoji will not be imported. - `fileName`: name of the image file inside the packed file. + The filename has to match the following ECMAScript RegExp: `/^[a-zA-Z0-9_]+?([a-zA-Z0-9\.]+)?$/` + (i.e. composed of latin letters, digits, underscores or dots, not starting with a dot and not ending with an underscore) + If the file does not match this RegExp, the respective emoji will not be imported! - `emoji`: data associated with the emoji as it was stored in the database. Currently most of these fields are not even checked for existence. The following are currently used: - `name`: name of the emoji for the user, e.g. `blobfox` if a user should type in `:blobfox:` to get the emoji. diff --git a/packages/backend/src/queue/processors/db/export-custom-emojis.ts b/packages/backend/src/queue/processors/db/export-custom-emojis.ts index 9aa503e43..f526b90dc 100644 --- a/packages/backend/src/queue/processors/db/export-custom-emojis.ts +++ b/packages/backend/src/queue/processors/db/export-custom-emojis.ts @@ -58,12 +58,10 @@ export async function exportCustomEmojis(job: Bull.Job, done: () => void): Promi }); for (const emoji of customEmojis) { - if (!/^[a-zA-Z0-9_]+$/.test(emoji.name)) { - this.logger.error(`invalid emoji name: ${emoji.name}, skipping in emoji export`); - continue; - } const ext = mime.extension(emoji.type); - const fileName = emoji.name + (ext ? '.' + ext : ''); + // there are some restrictions on file names, so to be safe the files are + // named after their database id instead of the actual emoji name + const fileName = emoji.id + (ext ? '.' + ext : ''); const emojiPath = path + '/' + fileName; fs.writeFileSync(emojiPath, '', 'binary'); let downloaded = false;