mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-11 01:10:11 +01:00
security: patch footer icon self-xss from privledged user
This commit is contained in:
parent
bfedfebfab
commit
49f30e051c
@ -2,6 +2,7 @@ process.env.NODE_ENV === "development"
|
|||||||
? require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` })
|
? require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` })
|
||||||
: require("dotenv").config();
|
: require("dotenv").config();
|
||||||
|
|
||||||
|
const { isValidUrl } = require("../utils/http");
|
||||||
const prisma = require("../utils/prisma");
|
const prisma = require("../utils/prisma");
|
||||||
|
|
||||||
const SystemSettings = {
|
const SystemSettings = {
|
||||||
@ -18,8 +19,10 @@ const SystemSettings = {
|
|||||||
validations: {
|
validations: {
|
||||||
footer_data: (updates) => {
|
footer_data: (updates) => {
|
||||||
try {
|
try {
|
||||||
const array = JSON.parse(updates);
|
const array = JSON.parse(updates)
|
||||||
return JSON.stringify(array.slice(0, 3)); // max of 3 items in footer.
|
.filter((setting) => isValidUrl(setting.url))
|
||||||
|
.slice(0, 3); // max of 3 items in footer.
|
||||||
|
return JSON.stringify(array);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Failed to run validation function on footer_data`);
|
console.error(`Failed to run validation function on footer_data`);
|
||||||
return JSON.stringify([]);
|
return JSON.stringify([]);
|
||||||
|
@ -68,6 +68,15 @@ function safeJsonParse(jsonString, fallback = null) {
|
|||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isValidUrl(urlString = "") {
|
||||||
|
try {
|
||||||
|
const url = new URL(urlString);
|
||||||
|
if (!["http:", "https:"].includes(url.protocol)) return false;
|
||||||
|
return true;
|
||||||
|
} catch (e) {}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
reqBody,
|
reqBody,
|
||||||
multiUserMode,
|
multiUserMode,
|
||||||
@ -77,4 +86,5 @@ module.exports = {
|
|||||||
userFromSession,
|
userFromSession,
|
||||||
parseAuthHeader,
|
parseAuthHeader,
|
||||||
safeJsonParse,
|
safeJsonParse,
|
||||||
|
isValidUrl,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user