mirror of
https://github.com/fosrl/pangolin.git
synced 2026-12-03 03:37:19 +00:00
Access middlewares cache the caller's org link on req.userOrg and req.apiKeyOrg and skip their membership query when it is already set. A value inherited from a polluted Object.prototype passed that check. - Give every request its own undefined copy of the cached auth fields (userOrg, apiKeyOrg, userOrgRoleIds, userOrgId, userOrgIds, orgPolicyAllowed) before any route runs, on the API, integration, internal and AI gateway servers. - Add ownUserOrg/ownApiKeyOrg, which return a cached value only if it is an own property for the signed-in user or calling key. - Every user and API key access middleware now uses them and refuses when the cached org does not match the org of the object being accessed. verifyApiKeySiteAccess and verifyApiKeySiteResourceAccess had no org comparison at all once req.apiKeyOrg was set. Defence in depth for PAN-1814 / GHSA-5fhj.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import express from "express";
|
|
import { initRequestAuthStateMiddleware } from "@server/middlewares/initRequestAuthState";
|
|
import helmet from "helmet";
|
|
import cors from "cors";
|
|
import cookieParser from "cookie-parser";
|
|
import config from "@server/lib/config";
|
|
import logger from "@server/logger";
|
|
import {
|
|
errorHandlerMiddleware,
|
|
notFoundMiddleware
|
|
} from "@server/middlewares";
|
|
import { internalRouter } from "#dynamic/routers/internal";
|
|
import { stripDuplicateSesions } from "./middlewares/stripDuplicateSessions";
|
|
|
|
const internalPort = config.getRawConfig().server.internal_port;
|
|
|
|
export function createInternalServer() {
|
|
const internalServer = express();
|
|
internalServer.use(initRequestAuthStateMiddleware);
|
|
|
|
const trustProxy = config.getRawConfig().server.trust_proxy;
|
|
if (trustProxy) {
|
|
internalServer.set("trust proxy", trustProxy);
|
|
}
|
|
|
|
internalServer.use(helmet());
|
|
internalServer.use(cors());
|
|
internalServer.use(stripDuplicateSesions);
|
|
internalServer.use(cookieParser());
|
|
internalServer.use(express.json());
|
|
|
|
const prefix = `/api/v1`;
|
|
internalServer.use(prefix, internalRouter);
|
|
|
|
internalServer.use(notFoundMiddleware);
|
|
internalServer.use(errorHandlerMiddleware);
|
|
|
|
internalServer.listen(internalPort, (err?: any) => {
|
|
if (err) throw err;
|
|
logger.info(
|
|
`Internal API server is running on http://localhost:${internalPort}`
|
|
);
|
|
});
|
|
|
|
return internalServer;
|
|
}
|