Fix: enforce MCP token length too

This commit is contained in:
shamoon
2026-08-07 15:09:57 -07:00
parent 2fae37b004
commit 7904d4adc9
5 changed files with 95 additions and 19 deletions
+8 -1
View File
@@ -2,7 +2,8 @@ import { getServerSession } from "next-auth/next";
import { authOptions } from "pages/api/auth/[...nextauth]";
import { isAuthEnabled } from "utils/env";
import { handleMcpRequest, mcpEnabled, mcpTokenAuthorized } from "utils/mcp/homepage-mcp";
import createLogger from "utils/logger";
import { handleMcpRequest, mcpEnabled, mcpTokenAuthorized, mcpTokenConfigError } from "utils/mcp/homepage-mcp";
async function hasHomepageSession(req, res) {
if (!isAuthEnabled()) return false;
@@ -14,6 +15,12 @@ export default async function handler(req, res) {
return res.status(404).end("Not Found");
}
const tokenError = mcpTokenConfigError();
if (tokenError) {
createLogger("mcp").error(tokenError);
return res.status(500).json({ error: "MCP token is misconfigured. See logs for details." });
}
if (!mcpTokenAuthorized(req) && !(await hasHomepageSession(req, res))) {
return res.status(401).json({ error: "Unauthorized" });
}