Browse Source

add filterText service method to strip HTML tags and Zalgo text

develop^2
Rob Colbert 2 years ago
parent
commit
d6bd4cc103
  1. 14
      app/services/chat.js

14
app/services/chat.js

@ -8,7 +8,8 @@ const mongoose = require('mongoose');
const ChatMessage = mongoose.model('ChatMessage');
const ioEmitter = require('socket.io-emitter');
const striptags = require('striptags');
const unzalgo = require('unzalgo');
const { SiteService } = require('../../lib/site-lib');
@ -44,6 +45,17 @@ class ChatService extends SiteService {
params: { messageId: message._id },
});
}
/**
* Filters an input string to remove "zalgo" text and to strip all HTML tags.
* This prevents cross-site scripting and the malicious destruction of text
* layouts.
* @param {String} content The text content to be filtered.
* @returns the filtered text
*/
filterText (content) {
return striptags(unzalgo.clean(content.trim()));
}
}
module.exports = {

Loading…
Cancel
Save