Skip to content

Commit bffd5a7

Browse files
authored
Merge pull request #1418 from cisagov/AL-crasm-3561-catch-CTIPS-blocks
CRASM-3561: Make sure telemetrySchema is defined and zod installed
2 parents c5201e7 + caf1305 commit bffd5a7

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

frontend/package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"react-select": "^5.5.9",
4949
"react-table": "^7.8.0",
5050
"serverless-http": "^3.2.0",
51-
"universal-cookie": "^7.2.2"
51+
"universal-cookie": "^7.2.2",
52+
"zod": "^4.2.1"
5253
},
5354
"devDependencies": {
5455
"@testing-library/jest-dom": "^6.6.3",

frontend/scripts/api.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ import cors from 'cors';
99
import helmet from 'helmet';
1010
import express from 'express';
1111
import path from 'path';
12+
import { z } from 'zod';
1213

1314
export const app = express();
1415

15-
// JSON body parsing needed for telemetry POST
16-
app.use(express.json({ limit: '10kb' }));
16+
const telemetrySchema = z.object({
17+
type: z.string(),
18+
path: z.string().optional(),
19+
status: z.number().nullable().optional(),
20+
server: z.string().nullable().optional(),
21+
via: z.string().nullable().optional(),
22+
cfRay: z.string().nullable().optional(),
23+
cfCacheStatus: z.string().nullable().optional(),
24+
ts: z.number().optional()
25+
});
1726

1827
// Rate limiting middleware (per IP, ~1 req/sec over 5 min)
1928
const telemetryLimiter = rateLimit({
@@ -47,6 +56,9 @@ function getErrorMessage(err) {
4756
}
4857
}
4958

59+
// JSON body parsing needed for telemetry POST
60+
app.use(express.json({ limit: '10kb' }));
61+
5062
// These CORS origins work in all Crossfeed environments
5163
app.use(
5264
cors({

0 commit comments

Comments
 (0)