Skip to content

Commit

Permalink
added type check for apiKey as string (#133)
Browse files Browse the repository at this point in the history
* added type check for apiKey as string

* updated package version
  • Loading branch information
vignesha22 authored Sep 17, 2024
1 parent 5a65399 commit 151fc3f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arka",
"version": "1.5.1",
"version": "1.5.2",
"description": "ARKA - (Albanian for Cashier's case) is the first open source Paymaster as a service software",
"type": "module",
"directories": {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/routes/deposit-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const depositRoutes: FastifyPluginAsync = async (server) => {
const amount = body.params[0];
const chainId = query['chainId'] ?? body.params[1];
const api_key = query['apiKey'] ?? body.params[2];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
Expand Down Expand Up @@ -112,7 +112,7 @@ const depositRoutes: FastifyPluginAsync = async (server) => {
const amount = body.params[0];
const chainId = query['chainId'] ?? body.params[1];
const api_key = query['apiKey'] ?? body.params[2];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
Expand Down
3 changes: 1 addition & 2 deletions backend/src/routes/metadata-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ const metadataRoutes: FastifyPluginAsync = async (server) => {
const query: any = request.query;
const chainId = query['chainId'] ?? 1;
const api_key = query['apiKey'];

if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
if (!chainId)
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_DATA })
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/paymaster-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const paymasterRoutes: FastifyPluginAsync = async (server) => {
}
}
}
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
if (!SUPPORTED_ENTRYPOINTS.EPV_06?.includes(entryPoint) && !SUPPORTED_ENTRYPOINTS.EPV_07?.includes(entryPoint))
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_ENTRYPOINT })
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/pimlico-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const pimlicoRoutes: FastifyPluginAsync = async (server) => {
const gasToken = context ? context.token : null;
const chainId = query['chainId'] ?? body.params[2];
const api_key = query['apiKey'] ?? body.params[3];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let customPaymasters = [];
let privateKey = '';
Expand Down
20 changes: 10 additions & 10 deletions backend/src/routes/whitelist-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
const address = body.params[0];
const chainId = query['chainId'] ?? body.params[1];
const api_key = query['apiKey'] ?? body.params[2];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
Expand Down Expand Up @@ -105,7 +105,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
const address = body.params[0];
const chainId = query['chainId'] ?? body.params[1];
const api_key = query['apiKey'] ?? body.params[2];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
Expand Down Expand Up @@ -169,7 +169,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
const accountAddress = body.params[0];
const chainId = query['chainId'] ?? body.params[1];
const api_key = query['apiKey'] ?? body.params[2];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
Expand Down Expand Up @@ -232,7 +232,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
const policyId = body.params[1];
const chainId = query['chainId'] ?? body.params[2];
const api_key = query['apiKey'] ?? body.params[3];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
Expand Down Expand Up @@ -310,7 +310,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
const policyId = body.params[1];
const chainId = query['chainId'] ?? body.params[2];
const api_key = query['apiKey'] ?? body.params[3];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
Expand Down Expand Up @@ -372,7 +372,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
const address = body.params[0];
const policyId = body.params[1];
const api_key = query['apiKey'] ?? body.params[2];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
const apiKeyEntity: APIKey | null = await server.apiKeyRepository.findOneByApiKey(api_key);
Expand Down Expand Up @@ -449,7 +449,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
const policyId = body.params[0];
const chainId = query['chainId'] ?? body.params[1];
const api_key = query['apiKey'] ?? body.params[2];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
Expand Down Expand Up @@ -509,7 +509,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {

const chainId = query['chainId'];
const api_key = query['apiKey'];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
Expand Down Expand Up @@ -577,7 +577,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
const query: any = request.query;
const chainId = query['chainId'];
const api_key = query['apiKey'];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
Expand Down Expand Up @@ -648,7 +648,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
const query: any = request.query;
const chainId = query['chainId'];
const api_key = query['apiKey'];
if (!api_key)
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
Expand Down

0 comments on commit 151fc3f

Please sign in to comment.