diff --git a/package-lock.json b/package-lock.json index 5973c0a88..7a8c2da87 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10712,8 +10712,11 @@ "resolved": "https://registry.npmjs.org/fluent-intl-polyfill/-/fluent-intl-polyfill-0.1.0.tgz", "integrity": "sha1-ETOUSrJHeINHOZVZaIPg05z4hc8=", "dev": true, - "requires": { - "intl-pluralrules": "github:projectfluent/IntlPluralRules#94cb0fa1c23ad943bc5aafef43cea132fa51d68b" + "dependencies": { + "intl-pluralrules": { + "version": "github:projectfluent/IntlPluralRules#94cb0fa1c23ad943bc5aafef43cea132fa51d68b", + "from": "github:projectfluent/IntlPluralRules#94cb0fa1c23ad943bc5aafef43cea132fa51d68b" + } } }, "fluent-langneg": { @@ -13381,11 +13384,6 @@ "integrity": "sha1-ftGxQQxqDg94z5XTuEQMY/eLhhQ=", "dev": true }, - "intl-pluralrules": { - "version": "github:projectfluent/IntlPluralRules#94cb0fa1c23ad943bc5aafef43cea132fa51d68b", - "from": "github:projectfluent/IntlPluralRules#module", - "dev": true - }, "invariant": { "version": "2.2.4", "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", diff --git a/src/core/server/app/middleware/csp/tenant.ts b/src/core/server/app/middleware/csp/tenant.ts index 840955fae..a4cc92619 100644 --- a/src/core/server/app/middleware/csp/tenant.ts +++ b/src/core/server/app/middleware/csp/tenant.ts @@ -14,12 +14,13 @@ import { Request, RequestHandler } from "talk-server/types/express"; * cspMiddleware handles adding the CSP middleware to each outgoing request. */ export const cspTenantMiddleware: RequestHandler = (req, res, next) => { - const tenant = req.talk!.tenant; - if (!tenant) { + if (!req.talk || !req.talk.tenant) { // There is no tenant for the request, don't add any headers. return next(); } + const tenant = req.talk.tenant; + res.setHeader( "Content-Security-Policy", generateContentSecurityPolicy(req, tenant) diff --git a/src/core/server/app/middleware/tenant.ts b/src/core/server/app/middleware/tenant.ts index 4acc6fba0..df08e3bf3 100644 --- a/src/core/server/app/middleware/tenant.ts +++ b/src/core/server/app/middleware/tenant.ts @@ -3,15 +3,21 @@ import { RequestHandler } from "talk-server/types/express"; export interface MiddlewareOptions { cache: TenantCache; + passNoTenant?: boolean; } export const tenantMiddleware = ({ cache, + passNoTenant = false, }: MiddlewareOptions): RequestHandler => async (req, res, next) => { try { // Attach the tenant to the request. const tenant = await cache.retrieveByDomain(req.hostname); if (!tenant) { + if (passNoTenant) { + return next(); + } + // TODO: send a http.StatusNotFound? return next(new Error("tenant not found")); } diff --git a/src/core/server/app/router/index.ts b/src/core/server/app/router/index.ts index 3814ada32..1442e27dc 100644 --- a/src/core/server/app/router/index.ts +++ b/src/core/server/app/router/index.ts @@ -23,7 +23,7 @@ export async function createRouter(app: AppOptions, options: RouterOptions) { attachGraphiQL(router, app); } - router.use(tenantMiddleware({ cache: app.tenantCache })); + router.use(tenantMiddleware({ cache: app.tenantCache, passNoTenant: true })); router.use(cspTenantMiddleware); const staticURI = app.config.get("static_uri");