-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: keys setting vulns * fix: check workspace ownership * fix: check workspace ownership --------- Co-authored-by: chronark <[email protected]>
- Loading branch information
1 parent
bca5871
commit c1af9a3
Showing
4 changed files
with
25 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,26 +15,29 @@ export const setDefaultApiBytes = t.procedure | |
.max(255, "Byte size cannot exceed 255") | ||
.optional(), | ||
keyAuthId: z.string(), | ||
workspaceId: z.string(), | ||
}), | ||
) | ||
.mutation(async ({ ctx, input }) => { | ||
const keyAuth = await db.query.keyAuth | ||
.findFirst({ | ||
where: (table, { eq }) => eq(table.id, input.keyAuthId), | ||
where: (table, { eq, and, isNull }) => | ||
and(eq(table.id, input.keyAuthId), isNull(table.deletedAt)), | ||
with: { | ||
workspace: true, | ||
}, | ||
}) | ||
.catch((_err) => { | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: | ||
"We were unable to find the KeyAuth. Please try again or contact [email protected].", | ||
"We were unable to update the key auth. Please try again or contact [email protected]", | ||
}); | ||
}); | ||
if (!keyAuth || keyAuth.workspaceId !== input.workspaceId) { | ||
if (!keyAuth || keyAuth.workspace.tenantId !== ctx.tenant.id) { | ||
throw new TRPCError({ | ||
code: "NOT_FOUND", | ||
message: | ||
"We are unable to find the correct keyAuth. Please try again or contact [email protected]", | ||
"We are unable to find the correct key auth. Please try again or contact [email protected].", | ||
}); | ||
} | ||
await db | ||
|
@@ -44,7 +47,7 @@ export const setDefaultApiBytes = t.procedure | |
.set({ | ||
defaultBytes: input.defaultBytes, | ||
}) | ||
.where(eq(schema.keyAuth.id, input.keyAuthId)) | ||
.where(eq(schema.keyAuth.id, keyAuth.id)) | ||
.catch((_err) => { | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
|
@@ -53,13 +56,13 @@ export const setDefaultApiBytes = t.procedure | |
}); | ||
}); | ||
await insertAuditLogs(tx, { | ||
workspaceId: keyAuth.workspaceId, | ||
workspaceId: keyAuth.workspace.id, | ||
actor: { | ||
type: "user", | ||
id: ctx.user.id, | ||
}, | ||
event: "api.update", | ||
description: `Changed ${keyAuth.workspaceId} default byte size for keys from ${keyAuth.defaultBytes} to ${input.defaultBytes}`, | ||
description: `Changed ${keyAuth.id} default byte size for keys from ${keyAuth.defaultBytes} to ${input.defaultBytes}`, | ||
resources: [ | ||
{ | ||
type: "keyAuth", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,35 +11,40 @@ export const setDefaultApiPrefix = t.procedure | |
z.object({ | ||
defaultPrefix: z.string().max(8, "Prefix can be a maximum of 8 characters"), | ||
keyAuthId: z.string(), | ||
workspaceId: z.string(), | ||
}), | ||
) | ||
.mutation(async ({ ctx, input }) => { | ||
const keyAuth = await db.query.keyAuth | ||
.findFirst({ | ||
where: (table, { eq }) => eq(table.id, input.keyAuthId), | ||
where: (table, { eq, and, isNull }) => | ||
and(eq(table.id, input.keyAuthId), isNull(table.deletedAt)), | ||
with: { | ||
workspace: true, | ||
}, | ||
}) | ||
.catch((_err) => { | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: "We were unable to find KeyAuth. Please try again or contact [email protected].", | ||
message: | ||
"We were unable to update the key auth. Please try again or contact [email protected]", | ||
}); | ||
}); | ||
if (!keyAuth || keyAuth.workspaceId !== input.workspaceId) { | ||
if (!keyAuth || keyAuth.workspace.tenantId !== ctx.tenant.id) { | ||
throw new TRPCError({ | ||
code: "NOT_FOUND", | ||
message: | ||
"We are unable to find the correct keyAuth. Please try again or contact [email protected]", | ||
"We are unable to find the correct key auth. Please try again or contact [email protected].", | ||
}); | ||
} | ||
|
||
await db | ||
.transaction(async (tx) => { | ||
await tx | ||
.update(schema.keyAuth) | ||
.set({ | ||
defaultPrefix: input.defaultPrefix, | ||
}) | ||
.where(eq(schema.keyAuth.id, input.keyAuthId)) | ||
.where(eq(schema.keyAuth.id, keyAuth.id)) | ||
.catch((_err) => { | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
|
@@ -48,13 +53,13 @@ export const setDefaultApiPrefix = t.procedure | |
}); | ||
}); | ||
await insertAuditLogs(tx, { | ||
workspaceId: keyAuth.workspaceId, | ||
workspaceId: keyAuth.workspace.id, | ||
actor: { | ||
type: "user", | ||
id: ctx.user.id, | ||
}, | ||
event: "api.update", | ||
description: `Changed ${keyAuth.workspaceId} default prefix from ${keyAuth.defaultPrefix} to ${input.defaultPrefix}`, | ||
description: `Changed ${keyAuth.id} default prefix from ${keyAuth.defaultPrefix} to ${input.defaultPrefix}`, | ||
resources: [ | ||
{ | ||
type: "keyAuth", | ||
|