Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/silver-tires-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@prosopo/provider": patch
---

Adding maintenance mode check at start of domain middleware

10 changes: 10 additions & 0 deletions packages/provider/src/api/domainMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ import type { NextFunction, Request, Response } from "express";
import type { TFunction } from "i18next";
import { ZodError } from "zod";
import { Tasks } from "../tasks/index.js";
import { getMaintenanceMode } from "./admin/apiToggleMaintenanceModeEndpoint.js";

export const domainMiddleware = (env: ProviderEnvironment) => {
const tasks = new Tasks(env);

return async (req: Request, res: Response, next: NextFunction) => {
try {
// If maintenance mode is active, skip domain validation
if (getMaintenanceMode()) {
req.logger.info(() => ({
msg: "Maintenance mode active - skipping domain validation",
}));
next();
Comment on lines +30 to +35
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When maintenance mode is active, the middleware skips domain validation entirely but still processes requests. This could allow unauthorized requests to bypass critical security checks. Consider either: (1) returning a 503 Service Unavailable response instead of proceeding, or (2) ensuring that subsequent middleware/handlers properly validate that maintenance mode requests are authorized.

Suggested change
// If maintenance mode is active, skip domain validation
if (getMaintenanceMode()) {
req.logger.info(() => ({
msg: "Maintenance mode active - skipping domain validation",
}));
next();
// If maintenance mode is active, return 503 Service Unavailable
if (getMaintenanceMode()) {
req.logger.info(() => ({
msg: "Maintenance mode active - rejecting request with 503",
}));
res.status(503).json({
error: "ServiceUnavailable",
message: "Service is temporarily unavailable due to maintenance",
});

Copilot uses AI. Check for mistakes.
return;
}

const siteKey = req.headers["prosopo-site-key"] as string;
if (!siteKey)
throw siteKeyNotRegisteredError(
Expand Down
Loading