Skip to content

Commit

Permalink
Hacker1 Recommendations (#316)
Browse files Browse the repository at this point in the history
* fixes as per hacker1 recommendations

* added relayer updated

* updates

* Fix

* Update relayer auth

---------

Co-authored-by: Adam Majmudar <[email protected]>
  • Loading branch information
farhanW3 and adam-maj authored Dec 1, 2023
1 parent 989ac6b commit 4f599c9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
25 changes: 14 additions & 11 deletions src/server/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,26 @@ export const withAuth = async (server: FastifyInstance) => {
req.url === "/favicon.ico" ||
req.url === "/" ||
req.url === "/health" ||
req.url.startsWith("/static") ||
req.url.startsWith("/json") ||
req.url.includes("/auth/payload") ||
req.url.includes("/auth/login") ||
req.url.includes("/auth/user") ||
req.url.includes("/auth/switch-account") ||
req.url.includes("/auth/logout") ||
req.url.includes("/transaction/status")
req.url === "/static" ||
req.url === "/json" ||
req.url === "/auth/payload" ||
req.url === "/auth/login" ||
req.url === "/auth/user" ||
req.url === "/auth/switch-account" ||
req.url === "/auth/logout" ||
req.url === "/transaction/status"
) {
// We skip auth check for static endpoints and auth routes
return;
}

if (
req.url.includes("/relayer") &&
!req.url.includes("/create") &&
!req.url.includes("/revoke")
req.url.startsWith("/relayer/") &&
req.method === "POST" &&
req.url.split("/").length === 2 &&
req.url !== "/relayer/create" &&
req.url !== "/relayer/revoke" &&
req.url !== "/relayer/update"
) {
// Relayer endpoints can handle their own authentication
return;
Expand Down
27 changes: 25 additions & 2 deletions src/server/routes/relayer/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,33 @@ const BodySchema = Type.Object({
description:
"The address of the backend wallet to use for relaying transactions.",
}),
allowedContracts: Type.Optional(Type.Array(Type.String())),
allowedForwarders: Type.Optional(Type.Array(Type.String())),
allowedContracts: Type.Array(
Type.String({
minLength: 42,
maxLength: 42,
}),
),

allowedForwarders: Type.Optional(
Type.Array(
Type.String({
minLength: 42,
maxLength: 42,
}),
),
),
});

BodySchema.examples = [
{
name: "My relayer",
chain: "mainnet",
backendWalletAddress: "0",
allowedContracts: ["0x1234...."],
allowedForwarders: ["0x1234..."],
},
];

const ReplySchema = Type.Object({
result: Type.Object({
relayerId: Type.String(),
Expand Down
2 changes: 2 additions & 0 deletions src/server/routes/relayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export async function relayTransaction(fastify: FastifyInstance) {
const { request, signature } = req.body;
const { v, r, s } = utils.splitSignature(signature);

// TODO: Remaining for backwards compatibility, but should enforce in the future
if (
relayer.allowedContracts &&
!relayer.allowedContracts.includes(request.to.toLowerCase())
Expand Down Expand Up @@ -213,6 +214,7 @@ export async function relayTransaction(fastify: FastifyInstance) {
});
}

// TODO: Remaining for backwards compatibility, but should enforce in the future
if (
relayer.allowedContracts &&
!relayer.allowedContracts.includes(request.to.toLowerCase())
Expand Down

0 comments on commit 4f599c9

Please sign in to comment.