Basic widget data validation

This commit is contained in:
Michael Shamoon 2022-10-22 22:48:25 -07:00
parent 5b7d2eaf07
commit 7b7740563e
6 changed files with 88 additions and 2 deletions

View file

@ -1,5 +1,6 @@
import getServiceWidget from "utils/config/service-helpers";
import { formatApiCall } from "utils/proxy/api-helpers";
import validateWidgetData from "utils/proxy/validate-widget-data";
import { httpProxy } from "utils/proxy/http";
import createLogger from "utils/logger";
import widgets from "widgets/widgets";
@ -54,6 +55,10 @@ export default async function credentialedProxyHandler(req, res) {
logger.debug("HTTP Error %d calling %s//%s%s...", status, url.protocol, url.hostname, url.pathname);
}
if (!validateWidgetData(widget, endpoint, data)) {
return res.status(500).json({error: {message: "Invalid data", url, data}});
}
if (contentType) res.setHeader("Content-Type", contentType);
return res.status(status).send(data);
}