Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Validate bounty submission URLs and file paths (#3842)

Kiran Kdbaf44acef99
diff --git a/apps/web/app/(ee)/api/embed/referrals/submissions/route.ts b/apps/web/app/(ee)/api/embed/referrals/submissions/route.ts
index 1ba4bd3606..1256f6f016 100644
--- a/apps/web/app/(ee)/api/embed/referrals/submissions/route.ts
+++ b/apps/web/app/(ee)/api/embed/referrals/submissions/route.ts
@@ -10,26 +10,6 @@ export const POST = withReferralsEmbedToken(
async ({ req, programEnrollment }) => {
const parsedInput = createBountySubmissionInputSchema
.omit({ programId: true })
- .superRefine((data, ctx) => {
- data.urls.forEach((value, index) => {
- try {
- const protocol = new URL(value).protocol;
- if (protocol !== "http:" && protocol !== "https:") {
- ctx.addIssue({
- code: "custom",
- path: ["urls", index],
- message: "URL must use http or https.",
- });
- }
- } catch {
- ctx.addIssue({
- code: "custom",
- path: ["urls", index],
- message: "Invalid URL.",
- });
- }
- });
- })
.parse(await parseRequestBody(req));
const partner = await prisma.partner.findUniqueOrThrow({
diff --git a/apps/web/lib/bounty/api/create-bounty-submission.ts b/apps/web/lib/bounty/api/create-bounty-submission.ts
index 879f28c371..5ce8119889 100644
--- a/apps/web/lib/bounty/api/create-bounty-submission.ts
+++ b/apps/web/lib/bounty/api/create-bounty-submission.ts
@@ -21,7 +21,7 @@ import {
Prisma,
WorkspaceRole,
} from "@dub/prisma/client";
-import { getDomainWithoutWWW, isValidUrl } from "@dub/utils";
+import { getDomainWithoutWWW, isValidUrl, R2_URL } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { formatDistanceToNow, isBefore } from "date-fns";
import * as z from "zod/v4";
@@ -80,6 +80,8 @@ export class BountySubmissionHandler {
this.validateRequirements();
+ this.validateFiles();
+
await this.validateSocialContent();
this.mergeSubmissionData();
@@ -411,6 +413,30 @@ export class BountySubmissionHandler {
}
}
+ private validateFiles() {
+ if (this.files.length === 0) {
+ return;
+ }
+
+ // Validate the URL to the partner's own upload location in R2
+ const r2 = new URL(R2_URL);
+ const expectedPath = `/programs/${this.programId}/bounties/${this.bountyId}/submissions/${this.partner.id}/`;
+
+ for (const file of this.files) {
+ const parsed = new URL(file.url);
+
+ if (
+ parsed.origin !== r2.origin ||
+ !parsed.pathname.startsWith(expectedPath)
+ ) {
+ throw new DubApiError({
+ code: "unprocessable_entity",
+ message: "Invalid file URL.",
+ });
+ }
+ }
+ }
+
// Validate the social content of the submission
private async validateSocialContent() {
const bountyInfo = resolveBountyDetails(this.bounty);
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index fff633f196..dd5e8b759e 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -137,7 +137,7 @@ export const updateBountySchema = createBountySchema
.partial();
export const BountySubmissionFileSchema = z.object({
- url: z.string().describe("The URL of the uploaded file."),
+ url: z.httpUrl().describe("The URL of the uploaded file."),
fileName: z.string().describe("The original file name."),
size: z.number().describe("The file size in bytes."),
});
@@ -326,7 +326,7 @@ export const createBountySubmissionInputSchema = z.object({
.array(BountySubmissionFileSchema)
.max(BOUNTY_MAX_SUBMISSION_FILES)
.default([]),
- urls: z.array(z.url()).max(BOUNTY_MAX_SUBMISSION_URLS).default([]),
+ urls: z.array(z.httpUrl()).max(BOUNTY_MAX_SUBMISSION_URLS).default([]),
description: z
.string()
.trim()
diff --git a/apps/web/ui/links/link-builder/use-link-builder-submit.tsx b/apps/web/ui/links/link-builder/use-link-builder-submit.tsx
index d61ea6d890..4de73af445 100644
--- a/apps/web/ui/links/link-builder/use-link-builder-submit.tsx
+++ b/apps/web/ui/links/link-builder/use-link-builder-submit.tsx
@@ -66,7 +66,6 @@ export function useLinkBuilderSubmit({
onSuccess?.(data);
// for editing links, if domain / key is changed, push to new url
- console.log({ props, data });
if (
props &&
(props.domain !== data.domain || props.key !== data.key)