fix: #8179, limit length of location/website/fullname, check grouptitle

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 307c72a58b
commit 14e7866745

@ -111,6 +111,9 @@ module.exports = function (User) {
if (!data.website) {
return;
}
if (data.website.length > 255) {
throw new Error('[[error:invalid-website]]');
}
await User.checkMinReputation(callerUid, data.uid, 'min:rep:website');
}
@ -136,13 +139,13 @@ module.exports = function (User) {
}
function isFullnameValid(data) {
if (data.fullname && validator.isURL(data.fullname)) {
if (data.fullname && (validator.isURL(data.fullname) || data.fullname.length > 255)) {
throw new Error('[[error:invalid-fullname]]');
}
}
function isLocationValid(data) {
if (data.location && validator.isURL(data.location)) {
if (data.location && (validator.isURL(data.location) || data.location.length > 255)) {
throw new Error('[[error:invalid-location]]');
}
}
@ -159,10 +162,29 @@ module.exports = function (User) {
}
function isGroupTitleValid(data) {
if (data.groupTitle === 'registered-users' || groups.isPrivilegeGroup(data.groupTitle)) {
function checkTitle(title) {
if (title === 'registered-users' || groups.isPrivilegeGroup(title)) {
throw new Error('[[error:invalid-group-title]]');
}
}
if (!data.groupTitle) {
return;
}
let groupTitles = [];
if (validator.isJSON(data.groupTitle)) {
groupTitles = JSON.parse(data.groupTitle);
if (!Array.isArray(groupTitles)) {
throw new Error('[[error:invalid-group-title]]');
}
groupTitles.forEach(title => checkTitle(title));
} else {
groupTitles = [data.groupTitle];
checkTitle(data.groupTitle);
}
if (!meta.config.allowMultipleBadges && groupTitles.length > 1) {
data.groupTitle = JSON.stringify(groupTitles[0]);
}
}
User.checkMinReputation = async function (callerUid, uid, setting) {
const isSelf = parseInt(callerUid, 10) === parseInt(uid, 10);

Loading…
Cancel
Save