Skip to content

Commit

Permalink
fix: add parameter validation for address deployments endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed Sep 24, 2024
1 parent baa36d3 commit 2875fdd
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion apps/api/src/routes/v1/addresses/deployments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";

import { getAddressDeployments } from "@src/services/external/apiNodeService";
import { isValidBech32Address } from "@src/utils/addresses";
import { openApiExampleAddress } from "@src/utils/constants";

const maxLimit = 100;
Expand Down Expand Up @@ -59,15 +60,28 @@ const route = createRoute({
})
}
}
},
400: {
description: "Invalid address"
}
}
});

export default new OpenAPIHono().openapi(route, async c => {
if (!isValidBech32Address(c.req.valid("param").address, "akash")) {
return c.text("Invalid address", 400);
}

const skip = parseInt(c.req.valid("param").skip);
const limit = Math.min(maxLimit, parseInt(c.req.valid("param").limit));

// TODO Add param validation
if (isNaN(skip)) {
return c.text("Invalid skip.", 400);
}

if (isNaN(limit)) {
return c.text("Invalid limit.", 400);
}

const deployments = await getAddressDeployments(c.req.valid("param").address, skip, limit, c.req.valid("query").reverseSorting === "true", {
status: c.req.valid("query").status
Expand Down

0 comments on commit 2875fdd

Please sign in to comment.