diff --git a/src/components/widgets/unifi_console/unifi_console.jsx b/src/components/widgets/unifi_console/unifi_console.jsx index 0031b224b..5295dbb73 100644 --- a/src/components/widgets/unifi_console/unifi_console.jsx +++ b/src/components/widgets/unifi_console/unifi_console.jsx @@ -14,8 +14,8 @@ import useWidgetAPI from "utils/proxy/use-widget-api"; export default function Widget({ options }) { const { t } = useTranslation(); - // eslint-disable-next-line no-param-reassign - options.type = "unifi_console"; + // eslint-disable-next-line no-param-reassign, no-multi-assign + options.service_group = options.service_name = "unifi_console"; const { data: statsData, error: statsError } = useWidgetAPI(options, "stat/sites", { index: options.index }); if (statsError) { diff --git a/src/pages/api/services/proxy.js b/src/pages/api/services/proxy.js index b77c5dd55..02214a637 100644 --- a/src/pages/api/services/proxy.js +++ b/src/pages/api/services/proxy.js @@ -12,8 +12,11 @@ export default async function handler(req, res) { const { service, group } = req.query; const serviceWidget = await getServiceWidget(group, service); let type = serviceWidget?.type; - // calendar is an alias for ical + + // exceptions if (type === "calendar") type = "ical"; + else if (service === "unifi_console" && group === "unifi_console") type = "unifi_console"; + const widget = widgets[type]; if (!widget) { @@ -49,15 +52,17 @@ export default async function handler(req, res) { if (req.query.segments) { const segments = JSON.parse(req.query.segments); - for (const key in segments) { + let validSegments = true; + Object.keys(segments).forEach((key) => { if (!mapping.segments.includes(key)) { logger.debug("Unsupported segment: %s", key); - return res.status(403).json({ error: "Unsupported segment" }); + validSegments = false; } else if (segments[key].includes("/") || segments[key].includes("\\") || segments[key].includes("..")) { logger.debug("Unsupported segment value: %s", segments[key]); - return res.status(403).json({ error: "Unsupported segment value" }); + validSegments = false; } - } + }); + if (!validSegments) return res.status(403).json({ error: "Unsupported segment" }); req.query.endpoint = formatApiCall(endpoint, segments); } diff --git a/src/widgets/unifi/proxy.js b/src/widgets/unifi/proxy.js index c8356c1bd..98c98f377 100644 --- a/src/widgets/unifi/proxy.js +++ b/src/widgets/unifi/proxy.js @@ -14,13 +14,13 @@ const prefixCacheKey = `${proxyName}__prefix`; const logger = createLogger(proxyName); async function getWidget(req) { - const { group, service, type } = req.query; + const { group, service } = req.query; let widget = null; - if (type === "unifi_console") { + if (group === "unifi_console" && service === "unifi_console") { // info widget const index = req.query?.query ? JSON.parse(req.query.query).index : undefined; - widget = await getPrivateWidgetOptions(type, index); + widget = await getPrivateWidgetOptions("unifi_console", index); if (!widget) { logger.debug("Error retrieving settings for this Unifi widget"); return null;