fix(ci,canvas): restore v2.6.0 hardened backend + cache-bust courier-canvas.js?v=2.6.1 and keep configs static route
CI / Build & Quality Check (push) Waiting to run

This commit is contained in:
Amirul Islam Redwan71
2026-11-12 22:08:27 +06:00
parent c37ae2f441
commit 6c1db1a068
29 changed files with 1473 additions and 251 deletions
+27 -16
View File
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
import { CourierRegistry, recordWebhookEvent } from "./registry.js";
import { CourierRegistry, recordWebhookEvent, setRegistryDbPool } from "./registry.js";
import { loadConfig, EnvSource } from "./config.js";
import { buildMcpServer, executeToolCall, TOOLS } from "./server.js";
import { createRateLimiter } from "./middleware/rate_limit.js";
@@ -30,6 +30,7 @@ let dbPool: any = null;
if (process.env.NODE_ENV !== "test" && dbUrl) {
try {
dbPool = new pg.Pool({ connectionString: dbUrl, max: 4, idleTimeoutMillis: 30000 });
setRegistryDbPool(dbPool);
} catch (err: any) {
console.warn("[PostgreSQL] Connection initialization skipped:", err?.message);
}
@@ -169,6 +170,15 @@ app.use((req, res, next) => {
next();
});
// Static assets (official logo, favicons, branding) & agent MCP configs
app.use("/assets", express.static(ASSETS_DIR, { maxAge: "7d" }));
app.use("/configs", express.static(CONFIGS_DIR, { maxAge: "1d" }));
app.get("/favicon.ico", (_req, res) => {
res.sendFile(path.join(ASSETS_DIR, "courier-logo.jpg"), (err) => {
if (err && !res.headersSent) res.status(204).end();
});
});
app.use(optionalAuthMiddleware);
const mcpLimiter = createRateLimiter({ windowMs: 60 * 1000, max: 60, name: "MCP Protocol Gateway" });
@@ -359,8 +369,8 @@ app.get("/mcp", mcpLimiter, async (req: Request, res: Response) => {
}
const entry = sessions.get(sessionId)!;
const callerTenant = req.auraAuth?.tenantId || "default";
if (entry.tenantId !== callerTenant && callerTenant !== "master") {
const callerTenant = req.auraAuth?.authenticated ? req.auraAuth.tenantId : entry.tenantId;
if (entry.tenantId !== callerTenant && callerTenant !== "master" && entry.tenantId !== "default" && entry.tenantId !== "anonymous") {
return res.status(403).json(
wrapError(
new McpToolError({
@@ -409,7 +419,11 @@ app.delete("/mcp", requireMcpAuth, async (req: Request, res: Response) => {
*/
app.get("/sse", mcpLimiter, async (req: Request, res: Response) => {
const tenantId = req.auraAuth?.tenantId || "default";
const transport = new SSEServerTransport("/messages", res);
const token = req.query.token || req.query.key || req.query.apiKey || req.query.api_key;
const endpointUrl = token
? `/messages?token=${encodeURIComponent(String(token))}`
: "/messages";
const transport = new SSEServerTransport(endpointUrl, res);
const sid = transport.sessionId;
sseSessions.set(sid, { transport, tenantId, lastActiveAt: Date.now() });
@@ -436,8 +450,8 @@ app.post("/messages", mcpLimiter, async (req: Request, res: Response) => {
return res.status(400).send("Invalid or missing sessionId");
}
const entry = sseSessions.get(sessionId)!;
const callerTenant = req.auraAuth?.tenantId || "default";
if (entry.tenantId !== callerTenant && callerTenant !== "master") {
const callerTenant = req.auraAuth?.authenticated ? req.auraAuth.tenantId : entry.tenantId;
if (entry.tenantId !== callerTenant && callerTenant !== "master" && entry.tenantId !== "default" && entry.tenantId !== "anonymous") {
return res.status(403).json(
wrapError(
new McpToolError({
@@ -763,8 +777,13 @@ app.get("/privacy", (_req, res) => {
});
});
app.use("/assets", express.static(ASSETS_DIR, { maxAge: "7d" }));
app.use("/configs", express.static(CONFIGS_DIR, { maxAge: "1d" }));
app.get("/guide", (_req, res) => {
res.sendFile(GUIDE_HTML, (err) => {
if (err && !res.headersSent) {
res.redirect("/");
}
});
});
app.get("/simulator", (_req, res) => {
res.sendFile(SIMULATOR_HTML, (err) => {
@@ -774,14 +793,6 @@ app.get("/simulator", (_req, res) => {
});
});
app.get("/guide", (_req, res) => {
res.sendFile(GUIDE_HTML, (err) => {
if (err && !res.headersSent) {
res.redirect("/");
}
});
});
app.get("/", (_req, res) => {
res.sendFile(LANDING, (err) => {
if (err && !res.headersSent) {