Просмотр исходного кода

Merge pull request #27860 from overleaf/lg-spam-safe

Add spam check for incident

GitOrigin-RevId: 752180f7507e32219cc5faaef5d48fdc0003e889
Christopher Hoskin 1 год назад
Родитель
Сommit
ae602208f1

+ 9 - 0
services/web/app/src/Features/Email/SpamSafe.js

@@ -11,6 +11,11 @@ const XRegExp = require('xregexp')
 const HAN_REGEX = XRegExp('\\p{Han}')
 const SAFE_REGEX = XRegExp("^[\\p{L}\\p{N}\\s\\-_!'&\\(\\)]+$")
 const EMAIL_REGEX = XRegExp('^[\\p{L}\\p{N}.+_-]+@[\\w.-]+$')
+const SPAM_TAGS_REGEX = /qun|jiaqun|jia|jnd/i
+
+function countDigits(str) {
+  return (str.match(/\d/g) || []).length
+}
 
 const SpamSafe = {
   isSafeUserName(name) {
@@ -18,6 +23,10 @@ const SpamSafe = {
   },
 
   isSafeProjectName(name) {
+    if (SPAM_TAGS_REGEX.test(name) || countDigits(name) > 5) {
+      return false
+    }
+
     if (HAN_REGEX.test(name)) {
       return SAFE_REGEX.test(name) && name.length <= 10
     }

+ 6 - 0
services/web/test/unit/src/Email/SpamSafeTests.js

@@ -60,6 +60,12 @@ describe('SpamSafe', function () {
         'A Project'
       )
     ).to.equal('A Project')
+    expect(SpamSafe.safeProjectName(`JND-123456-100s68`, 'A Project')).to.equal(
+      'A Project'
+    )
+    expect(
+      SpamSafe.safeProjectName(`JiAqun123456s100sf68`, 'A Project')
+    ).to.equal('A Project')
     expect(
       SpamSafe.safeEmail('safe-ëmail@domain.com', 'A collaborator')
     ).to.equal('safe-ëmail@domain.com')