Skip to content

Commit b59e991

Browse files
Add rate limiter and input validation to /norad/:id route
The NORAD route was missing the rate limiter middleware that all other routes (tle, json, csv) use. This allowed unlimited requests that could abuse Celestrak upstream. Also adds validation for NORAD catalog IDs — rejects NaN, negative, and out-of-range values (must be 1-999999) with a 400 response instead of forwarding garbage to Celestrak.
1 parent eb70a2c commit b59e991

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/routes/norad.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import { Elysia } from "elysia";
22

3+
import limiter from "../utils/ratelimiter";
34
import tleGetter from "../utils/tleGetter";
45

5-
const noradRoute = new Elysia({ prefix: "/norad" }).get("/:id", async ({ params }) => {
6-
const noradId = parseInt(params.id, 10);
7-
const tleData = await tleGetter(noradId);
8-
return new Response(tleData, { headers: { "Content-Type": "text/plain", "Cache-Control": "max-age=3600" } });
9-
});
6+
const noradRoute = new Elysia({ prefix: "/norad" })
7+
.use(limiter)
8+
.get("/:id", async ({ params }) => {
9+
const noradId = parseInt(params.id, 10);
10+
11+
if (isNaN(noradId) || noradId < 1 || noradId > 999999) {
12+
return new Response("Invalid NORAD ID. Must be a positive integer between 1 and 999999.", {
13+
status: 400,
14+
headers: { "Content-Type": "text/plain" },
15+
});
16+
}
17+
18+
const tleData = await tleGetter(noradId);
19+
return new Response(tleData, { headers: { "Content-Type": "text/plain", "Cache-Control": "max-age=3600" } });
20+
});
1021

1122
export default noradRoute;

0 commit comments

Comments
 (0)