mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: use saslprep to limit usernames
This commit is contained in:
1 parent
dbe369d0c6
commit
f5828e5cb3
4 files changed
+10
-9
No files matched your search
@@ -43,6 +43,7 @@
|
|||||||
"p-queue": "^7.3.0",
|
"p-queue": "^7.3.0",
|
||||||
"path-to-regexp": "^6.2.1",
|
"path-to-regexp": "^6.2.1",
|
||||||
"require-resolve-hook": "^1.1.0",
|
"require-resolve-hook": "^1.1.0",
|
||||||
|
"saslprep": "^1.0.3",
|
||||||
"schemastery": "^3.5.4",
|
"schemastery": "^3.5.4",
|
||||||
"semver": "^7.3.7",
|
"semver": "^7.3.7",
|
||||||
"serialize-javascript": "^6.0.0",
|
"serialize-javascript": "^6.0.0",
|
||||||
@@ -64,6 +65,7 @@
|
|||||||
"@types/mongodb": "^3.6.20",
|
"@types/mongodb": "^3.6.20",
|
||||||
"@types/nodemailer": "^6.4.5",
|
"@types/nodemailer": "^6.4.5",
|
||||||
"@types/notp": "^2.0.2",
|
"@types/notp": "^2.0.2",
|
||||||
|
"@types/saslprep": "^1.0.1",
|
||||||
"@types/semver": "^7.3.12",
|
"@types/semver": "^7.3.12",
|
||||||
"@types/serialize-javascript": "^5.0.2",
|
"@types/serialize-javascript": "^5.0.2",
|
||||||
"@types/superagent": "^4.1.15",
|
"@types/superagent": "^4.1.15",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
import { OAuthUserResponse, Udoc, User } from '../interface';
|
import { OAuthUserResponse, Udoc, User } from '../interface';
|
||||||
import avatar from '../lib/avatar';
|
import avatar from '../lib/avatar';
|
||||||
import { sendMail } from '../lib/mail';
|
import { sendMail } from '../lib/mail';
|
||||||
import { isEmail, isPassword, isUname } from '../lib/validator';
|
import { isEmail, isPassword } from '../lib/validator';
|
||||||
import BlackListModel from '../model/blacklist';
|
import BlackListModel from '../model/blacklist';
|
||||||
import { PERM, PRIV, STATUS } from '../model/builtin';
|
import { PERM, PRIV, STATUS } from '../model/builtin';
|
||||||
import domain from '../model/domain';
|
import domain from '../model/domain';
|
||||||
@@ -109,7 +109,7 @@ class UserLoginHandler extends Handler {
|
|||||||
this.response.template = 'user_login.html';
|
this.response.template = 'user_login.html';
|
||||||
}
|
}
|
||||||
|
|
||||||
@param('uname', Types.String)
|
@param('uname', Types.Username)
|
||||||
@param('password', Types.String)
|
@param('password', Types.String)
|
||||||
@param('rememberme', Types.Boolean)
|
@param('rememberme', Types.Boolean)
|
||||||
@param('redirect', Types.String, true)
|
@param('redirect', Types.String, true)
|
||||||
@@ -211,7 +211,7 @@ class UserRegisterWithCodeHandler extends Handler {
|
|||||||
|
|
||||||
@param('password', Types.String, isPassword)
|
@param('password', Types.String, isPassword)
|
||||||
@param('verifyPassword', Types.String)
|
@param('verifyPassword', Types.String)
|
||||||
@param('uname', Types.Name, isUname)
|
@param('uname', Types.Username)
|
||||||
@param('code', Types.String)
|
@param('code', Types.String)
|
||||||
async post(
|
async post(
|
||||||
domainId: string, password: string, verify: string,
|
domainId: string, password: string, verify: string,
|
||||||
|
|||||||
@@ -75,8 +75,6 @@ export const isEmail = (s) => RE_MAIL.test(s);
|
|||||||
export const checkEmail = (s) => { if (!RE_MAIL.test(s)) throw new ValidationError('mail'); else return s; };
|
export const checkEmail = (s) => { if (!RE_MAIL.test(s)) throw new ValidationError('mail'); else return s; };
|
||||||
export const isContent = (s: any) => s && s.length < 65536;
|
export const isContent = (s: any) => s && s.length < 65536;
|
||||||
export const checkContent = (s) => { if (!(s && s.length < 65536)) throw new ValidationError('content'); else return s; };
|
export const checkContent = (s) => { if (!(s && s.length < 65536)) throw new ValidationError('content'); else return s; };
|
||||||
export const isName = (s) => s && s.length < 256;
|
|
||||||
export const checkName = (s) => { if (!isName(s)) throw new ValidationError('name'); else return s; };
|
|
||||||
export const isPid = (s) => RE_PID.test(s.toString());
|
export const isPid = (s) => RE_PID.test(s.toString());
|
||||||
export const checkPid = (s) => { if (!RE_PID.test(s)) throw new ValidationError('pid'); else return s; };
|
export const checkPid = (s) => { if (!RE_PID.test(s)) throw new ValidationError('pid'); else return s; };
|
||||||
export const isIntro = () => true;
|
export const isIntro = () => true;
|
||||||
@@ -102,8 +100,6 @@ global.Hydro.lib.validator = {
|
|||||||
checkEmail,
|
checkEmail,
|
||||||
isContent,
|
isContent,
|
||||||
checkContent,
|
checkContent,
|
||||||
isName,
|
|
||||||
checkName,
|
|
||||||
isPid,
|
isPid,
|
||||||
checkPid,
|
checkPid,
|
||||||
isIntro,
|
isIntro,
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import emojiRegex from 'emoji-regex';
|
|||||||
import { isSafeInteger } from 'lodash';
|
import { isSafeInteger } from 'lodash';
|
||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
import { ObjectID } from 'mongodb';
|
import { ObjectID } from 'mongodb';
|
||||||
|
import saslprep from 'saslprep';
|
||||||
import { ValidationError } from '../error';
|
import { ValidationError } from '../error';
|
||||||
import { isContent, isName, isTitle } from '../lib/validator';
|
import { isContent, isTitle } from '../lib/validator';
|
||||||
import type { Handler } from './server';
|
import type { Handler } from './server';
|
||||||
|
|
||||||
type MethodDecorator = (target: any, name: string, obj: any) => any;
|
type MethodDecorator = (target: any, name: string, obj: any) => any;
|
||||||
@@ -23,6 +24,7 @@ type Type = [Converter, Validator, boolean?];
|
|||||||
export interface Types {
|
export interface Types {
|
||||||
Content: Type,
|
Content: Type,
|
||||||
Name: Type,
|
Name: Type,
|
||||||
|
Username: Type,
|
||||||
Title: Type,
|
Title: Type,
|
||||||
String: Type,
|
String: Type,
|
||||||
Int: Type,
|
Int: Type,
|
||||||
@@ -43,7 +45,8 @@ export interface Types {
|
|||||||
|
|
||||||
export const Types: Types = {
|
export const Types: Types = {
|
||||||
Content: [(v) => v.toString().trim(), isContent],
|
Content: [(v) => v.toString().trim(), isContent],
|
||||||
Name: [(v) => v.toString().trim(), isName],
|
Name: [(v) => saslprep(v.toString().trim()), (v) => /^.{1,255}$/.test(saslprep(v.toString().trim()))],
|
||||||
|
Username: [(v) => saslprep(v.toString().trim()), (v) => /^.{3,31}$/.test(saslprep(v.toString().trim()))],
|
||||||
Title: [(v) => v.toString().trim(), isTitle],
|
Title: [(v) => v.toString().trim(), isTitle],
|
||||||
String: [(v) => v.toString(), null],
|
String: [(v) => v.toString(), null],
|
||||||
Int: [(v) => parseInt(v, 10), (v) => isSafeInteger(parseInt(v, 10))],
|
Int: [(v) => parseInt(v, 10), (v) => isSafeInteger(parseInt(v, 10))],
|
||||||
|
|||||||
Reference in new issue
Block a user