Skip to content

Commit

Permalink
Merge pull request #1882 from dubinc/verify-qstash-update
Browse files Browse the repository at this point in the history
Update verify QStash
  • Loading branch information
steven-tey authored Jan 12, 2025
2 parents 5871429 + 66d49db commit 780d4af
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/domains/configure-dns/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const dynamic = "force-dynamic";
export async function POST(req: Request) {
try {
const body = await req.json();
await verifyQstashSignature(req, body);
await verifyQstashSignature({ req, body });
const { domain } = body;

const res = await configureDNS({ domain });
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/domains/delete/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function POST(req: Request) {
try {
const body = await req.json();

await verifyQstashSignature(req, body);
await verifyQstashSignature({ req, body });

const { domain, workspaceId } = schema.parse(body);

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/domains/transfer/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function POST(req: Request) {
try {
const body = await req.json();

await verifyQstashSignature(req, body);
await verifyQstashSignature({ req, body });

const { currentWorkspaceId, newWorkspaceId, domain } = schema.parse(body);

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/domains/update/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function POST(req: Request) {
try {
const body = await req.json();

await verifyQstashSignature(req, body);
await verifyQstashSignature({ req, body });

const { newDomain, oldDomain, workspaceId, page } = schema.parse(body);

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/import/bitly/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const dynamic = "force-dynamic";
export async function POST(req: Request) {
try {
const body = await req.json();
await verifyQstashSignature(req, body);
await verifyQstashSignature({ req, body });
const { workspaceId, bitlyGroup, importTags } = body;

try {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/import/csv/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type MapperResult =
export async function POST(req: Request) {
try {
const body = await req.json();
await verifyQstashSignature(req, body);
await verifyQstashSignature({ req, body });
const { workspaceId, userId, id, url } = body;
const mapping = linkMappingSchema.parse(body.mapping);

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/import/rebrandly/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const dynamic = "force-dynamic";
export async function POST(req: Request) {
try {
const body = await req.json();
await verifyQstashSignature(req, body);
await verifyQstashSignature({ req, body });
const { workspaceId, importTags } = body;

try {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/import/short/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const dynamic = "force-dynamic";
export async function POST(req: Request) {
try {
const body = await req.json();
await verifyQstashSignature(req, body);
await verifyQstashSignature({ req, body });
const {
workspaceId,
userId,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/links/delete/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const dynamic = "force-dynamic";
export async function POST(req: Request) {
try {
const body = await req.json();
await verifyQstashSignature(req, body);
await verifyQstashSignature({ req, body });
const { linkId } = body;

const link = await prisma.link.findUnique({
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/shopify/order-paid/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const schema = z.object({
export async function POST(req: Request) {
try {
const body = await req.json();
await verifyQstashSignature(req, body);
await verifyQstashSignature({ req, body });

const { workspaceId, checkoutToken } = schema.parse(body);

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/usage/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function handler(req: Request) {
if (req.method === "GET") {
await verifyVercelSignature(req);
} else if (req.method === "POST") {
await verifyQstashSignature(req);
await verifyQstashSignature({ req });
}

await updateUsage();
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/cron/workspaces/delete/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function POST(req: Request) {
try {
const body = await req.json();

await verifyQstashSignature(req, body);
await verifyQstashSignature({ req, body });

const { workspaceId } = schema.parse(body);

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/webhooks/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const searchParamsSchema = z.object({
export const POST = async (req: Request) => {
const rawBody = await req.text();

await verifyQstashSignature(req, rawBody, "text");
await verifyQstashSignature({ req, body: rawBody, bodyType: "text" });

const { url, status, body, sourceBody, sourceMessageId } =
webhookCallbackSchema.parse(JSON.parse(rawBody));
Expand Down
16 changes: 11 additions & 5 deletions apps/web/lib/cron/verify-qstash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ const receiver = new Receiver({
nextSigningKey: process.env.QSTASH_NEXT_SIGNING_KEY || "",
});

export const verifyQstashSignature = async (
req: Request,
body?: any,
bodyType: "json" | "text" = "json",
) => {
export const verifyQstashSignature = async ({
req,
body,
bodyType = "json",
}: {
req: Request;
body?: any;
// due to a weird QStash bug, webhook URLs that have query params
// need to be verified with the text body type (instead of JSON)
bodyType?: "json" | "text";
}) => {
body = body || (bodyType === "json" ? await req.json() : await req.text());

const isValid = await receiver.verify({
Expand Down

0 comments on commit 780d4af

Please sign in to comment.