Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/middleware/accessLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export function accessLog(req: Request, res: Response, next: NextFunction): void
logName = "markets_access_log";
} else if (req.originalUrl.startsWith("/api/feature-flags")) {
logName = "feature_flags_access_log";
} else if (req.originalUrl.startsWith("/api/webhooks")) {
logName = "webhooks_access_log";
}

const durationMs = Date.now() - startMs;
Expand Down
11 changes: 11 additions & 0 deletions src/routes/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
* Rate-limit keying is based on the authenticated stellar address populated by
* `requireAuth`, so quota is tracked independently per user, not per IP.
*
* All routes are wrapped by `accessLog` which:
* - Resolves a correlation ID via the priority chain (header → req.id → UUID)
* - Echoes it back in the `X-Correlation-Id` response header
* - Emits a structured `webhooks_access_log` entry on every response finish.
*
* Endpoints:
* GET / — list webhook subscriptions
* POST / — create a new webhook subscription
Expand All @@ -24,6 +29,7 @@
import { Router } from "express";
import { logger } from "../config/logger";
import { getRequestId } from "../lib/requestContext";
import { accessLog } from "../middleware/accessLog";
import { webhookCors } from "../middleware/cors";
import { requireAdmin } from "../middleware/requireAdmin";
import { webhooksRateLimiter } from "../middleware/rateLimit";
Expand All @@ -38,6 +44,11 @@ import { webhooksRateLimiter } from "../middleware/rateLimit";

export const webhooksRouter = Router();

// Structured access log — resolves correlation ID, echoes it back, and
// emits a webhooks_access_log entry on every response finish.
// Mounted first so the correlation ID is available to all downstream handlers.
webhooksRouter.use(accessLog);

// Enforce CORS allowlist before admin auth so unapproved origins are
// rejected early without leaking auth challenge details.
webhooksRouter.use(webhookCors());
Expand Down
Loading
Loading