Skip to content

Commit

Permalink
fix: security patch (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt authored Sep 23, 2024
1 parent 9a6509d commit a8d7b29
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
30 changes: 17 additions & 13 deletions packages/backend/src/api/v1/checklists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,20 @@ checklists.post(
},
);

checklists.patch("/:id", async (ctx: Context) => {
const { projectId } = ctx.state;
const paramsSchema = z.object({ id: z.string().uuid() });
const bodySchema = z.object({
slug: z.string(),
data: z.any() as z.ZodType<CheckLogic>,
});
const { slug, data } = bodySchema.parse(ctx.request.body);
const { id } = paramsSchema.parse(ctx.params);

const [updatedCheck] = await sql`
checklists.patch(
"/:id",
checkAccess("checklists", "update"),
async (ctx: Context) => {
const { projectId } = ctx.state;
const paramsSchema = z.object({ id: z.string().uuid() });
const bodySchema = z.object({
slug: z.string(),
data: z.any() as z.ZodType<CheckLogic>,
});
const { slug, data } = bodySchema.parse(ctx.request.body);
const { id } = paramsSchema.parse(ctx.params);

const [updatedCheck] = await sql`
update
checklist
set
Expand All @@ -92,8 +95,9 @@ checklists.patch("/:id", async (ctx: Context) => {
and id = ${id}
returning *
`;
ctx.body = updatedCheck;
});
ctx.body = updatedCheck;
},
);

checklists.delete(
"/:id",
Expand Down
7 changes: 7 additions & 0 deletions packages/backend/src/api/v1/data-warehouse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ dataWarehouse.post("/bigquery", async (ctx: Context) => {
apiKey: z.string().transform((apiKey) => JSON.parse(apiKey)),
});
const { apiKey } = bodySchema.parse(ctx.request.body);
const { userId } = ctx.state;

const [user] = await sql`select * from account where id = ${userId}`;

if (user.role !== "owner") {
ctx.throw(403, "Forbidden");
}

if (config.DATA_WAREHOUSE_EXPORTS_ALLOWED) {
await createNewDatastream(apiKey, process.env.DATABASE_URL!, ctx);
Expand Down
7 changes: 6 additions & 1 deletion packages/backend/src/api/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ users.post("/", checkAccess("teamMembers", "create"), async (ctx: Context) => {
projects: z.array(z.string()).min(1),
});
const { email, role, projects } = bodySchema.parse(ctx.request.body);
const { orgId } = ctx.state;
const { orgId, userId } = ctx.state;

const FIFTEEN_DAYS = 60 * 60 * 24 * 15;

Expand All @@ -207,6 +207,11 @@ users.post("/", checkAccess("teamMembers", "create"), async (ctx: Context) => {
);
}

const [currentUser] = await sql`select * from account where id = ${userId}`;
if (currentUser.role !== "owner" && role === "billing") {
ctx.throw(403, "Only owners can add billing members to the organization.");
}

const token = await signJWT({ email, orgId }, FIFTEEN_DAYS);
const userToInsert = {
email,
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/components/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export default function Sidebar() {
</Combobox.Footer>
</Combobox.Dropdown>
</Combobox>
{hasAccess(user.role, "billing", "read") && (
{hasAccess(user.role, "settings", "read") && (
<ActionIcon
variant="default"
size="sm"
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/access-control/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ export const roles: Record<
settings: {
create: true,
read: true,
update: true,
delete: true,
update: false,
delete: false,
list: true,
},
},
Expand Down

0 comments on commit a8d7b29

Please sign in to comment.