mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
🌍 feat: Extend regex to support international usernames (#1918)
* 🌍 Extend regex to support international usernames
* update validators.spec.js
This commit is contained in:
parent
2f92b54787
commit
057fcf6274
2 changed files with 15 additions and 4 deletions
|
@ -1,6 +1,20 @@
|
||||||
const { z } = require('zod');
|
const { z } = require('zod');
|
||||||
|
|
||||||
const allowedCharactersRegex = /^[a-zA-Z0-9_.@#$%&*()\p{Script=Latin}\p{Script=Common}]+$/u;
|
const allowedCharactersRegex = new RegExp(
|
||||||
|
'^[' +
|
||||||
|
'a-zA-Z0-9_.@#$%&*()' + // Basic Latin characters and symbols
|
||||||
|
'\\p{Script=Latin}' + // Latin script characters
|
||||||
|
'\\p{Script=Common}' + // Characters common across scripts
|
||||||
|
'\\p{Script=Cyrillic}' + // Cyrillic script for Russian, etc.
|
||||||
|
'\\p{Script=Devanagari}' + // Devanagari script for Hindi, etc.
|
||||||
|
'\\p{Script=Han}' + // Han script for Chinese characters, etc.
|
||||||
|
'\\p{Script=Arabic}' + // Arabic script
|
||||||
|
'\\p{Script=Hiragana}' + // Hiragana script for Japanese
|
||||||
|
'\\p{Script=Katakana}' + // Katakana script for Japanese
|
||||||
|
'\\p{Script=Hangul}' + // Hangul script for Korean
|
||||||
|
']+$', // End of string
|
||||||
|
'u', // Use Unicode mode
|
||||||
|
);
|
||||||
const injectionPatternsRegex = /('|--|\$ne|\$gt|\$lt|\$or|\{|\}|\*|;|<|>|\/|=)/i;
|
const injectionPatternsRegex = /('|--|\$ne|\$gt|\$lt|\$or|\{|\}|\*|;|<|>|\/|=)/i;
|
||||||
|
|
||||||
const usernameSchema = z
|
const usernameSchema = z
|
||||||
|
|
|
@ -404,9 +404,6 @@ describe('Zod Schemas', () => {
|
||||||
|
|
||||||
it('should reject invalid usernames', () => {
|
it('should reject invalid usernames', () => {
|
||||||
const invalidUsernames = [
|
const invalidUsernames = [
|
||||||
'Дмитрий', // Cyrillic characters
|
|
||||||
'محمد', // Arabic characters
|
|
||||||
'张伟', // Chinese characters
|
|
||||||
'john{doe}', // Contains `{` and `}`
|
'john{doe}', // Contains `{` and `}`
|
||||||
'j', // Only one character
|
'j', // Only one character
|
||||||
'a'.repeat(81), // More than 80 characters
|
'a'.repeat(81), // More than 80 characters
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue