Skip to content

Commit 4f599c9

Browse files
farhanW3adam-maj
andauthored
Hacker1 Recommendations (#316)
* fixes as per hacker1 recommendations * added relayer updated * updates * Fix * Update relayer auth --------- Co-authored-by: Adam Majmudar <mr.adam.maj@gmail.com>
1 parent 989ac6b commit 4f599c9

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

src/server/middleware/auth.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,23 +165,26 @@ export const withAuth = async (server: FastifyInstance) => {
165165
req.url === "/favicon.ico" ||
166166
req.url === "/" ||
167167
req.url === "/health" ||
168-
req.url.startsWith("/static") ||
169-
req.url.startsWith("/json") ||
170-
req.url.includes("/auth/payload") ||
171-
req.url.includes("/auth/login") ||
172-
req.url.includes("/auth/user") ||
173-
req.url.includes("/auth/switch-account") ||
174-
req.url.includes("/auth/logout") ||
175-
req.url.includes("/transaction/status")
168+
req.url === "/static" ||
169+
req.url === "/json" ||
170+
req.url === "/auth/payload" ||
171+
req.url === "/auth/login" ||
172+
req.url === "/auth/user" ||
173+
req.url === "/auth/switch-account" ||
174+
req.url === "/auth/logout" ||
175+
req.url === "/transaction/status"
176176
) {
177177
// We skip auth check for static endpoints and auth routes
178178
return;
179179
}
180180

181181
if (
182-
req.url.includes("/relayer") &&
183-
!req.url.includes("/create") &&
184-
!req.url.includes("/revoke")
182+
req.url.startsWith("/relayer/") &&
183+
req.method === "POST" &&
184+
req.url.split("/").length === 2 &&
185+
req.url !== "/relayer/create" &&
186+
req.url !== "/relayer/revoke" &&
187+
req.url !== "/relayer/update"
185188
) {
186189
// Relayer endpoints can handle their own authentication
187190
return;

src/server/routes/relayer/create.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,33 @@ const BodySchema = Type.Object({
1111
description:
1212
"The address of the backend wallet to use for relaying transactions.",
1313
}),
14-
allowedContracts: Type.Optional(Type.Array(Type.String())),
15-
allowedForwarders: Type.Optional(Type.Array(Type.String())),
14+
allowedContracts: Type.Array(
15+
Type.String({
16+
minLength: 42,
17+
maxLength: 42,
18+
}),
19+
),
20+
21+
allowedForwarders: Type.Optional(
22+
Type.Array(
23+
Type.String({
24+
minLength: 42,
25+
maxLength: 42,
26+
}),
27+
),
28+
),
1629
});
1730

31+
BodySchema.examples = [
32+
{
33+
name: "My relayer",
34+
chain: "mainnet",
35+
backendWalletAddress: "0",
36+
allowedContracts: ["0x1234...."],
37+
allowedForwarders: ["0x1234..."],
38+
},
39+
];
40+
1841
const ReplySchema = Type.Object({
1942
result: Type.Object({
2043
relayerId: Type.String(),

src/server/routes/relayer/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export async function relayTransaction(fastify: FastifyInstance) {
159159
const { request, signature } = req.body;
160160
const { v, r, s } = utils.splitSignature(signature);
161161

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

217+
// TODO: Remaining for backwards compatibility, but should enforce in the future
216218
if (
217219
relayer.allowedContracts &&
218220
!relayer.allowedContracts.includes(request.to.toLowerCase())

0 commit comments

Comments
 (0)