-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add customizable email content for partner invites #3066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
533cd47
Add customizable email content for partner invites
marcusljf 466a5d7
Add markdown support to program invite emails
marcusljf 15db264
Sanitize and limit partner invite email body
marcusljf 66d0e83
Improve partner invite email handling and markdown sanitization
marcusljf fe8ceb1
Improve email body validation and error logging
marcusljf 3551b92
Format code for readability in markdown sanitizer and email template
marcusljf 310835a
Use dynamic email subject in preview text
marcusljf 735b9eb
Merge branch 'main' into invite-email
steven-tey c2f7b60
use @react-email/markdown, refactor to RichTextArea
steven-tey 8cf68ec
finalize styles
steven-tey 8acdedd
make font slightly bigger
steven-tey 20ccb23
persist inviteEmailData to DB
steven-tey 3052dc0
simplify form submission
steven-tey d0fc3ee
limit inviteEmailData to InvitePartnerSheet
steven-tey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
435 changes: 360 additions & 75 deletions
435
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/invite-partner-sheet.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| "use server"; | ||
|
|
||
| import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw"; | ||
| import { sanitizeMarkdown } from "@/lib/partners/sanitize-markdown"; | ||
| import { prisma } from "@dub/prisma"; | ||
| import { z } from "zod"; | ||
| import { authActionClient } from "../safe-action"; | ||
|
|
||
| const saveInviteEmailDataSchema = z.object({ | ||
| workspaceId: z.string(), | ||
| subject: z.string().trim().min(1), | ||
| title: z.string().trim().min(1), | ||
| body: z.string().trim().min(1).max(3000), | ||
| }); | ||
|
|
||
| export const saveInviteEmailDataAction = authActionClient | ||
| .schema(saveInviteEmailDataSchema) | ||
| .action(async ({ parsedInput, ctx }) => { | ||
| const { workspace } = ctx; | ||
| const { subject, title, body } = parsedInput; | ||
|
|
||
| const programId = getDefaultProgramIdOrThrow(workspace); | ||
|
|
||
| // Sanitize emailBody before saving | ||
| const sanitizedBody = sanitizeMarkdown(body); | ||
|
|
||
| if (!sanitizedBody) { | ||
| throw new Error( | ||
| "Email body contains invalid content. Please remove excessively long lines or unsupported characters.", | ||
| ); | ||
| } | ||
|
|
||
| await prisma.program.update({ | ||
| where: { | ||
| id: programId, | ||
| }, | ||
| data: { | ||
| inviteEmailData: { | ||
| subject: subject.trim(), | ||
| title: title.trim(), | ||
| body: sanitizedBody, | ||
| }, | ||
| }, | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| "server-only"; | ||
|
|
||
| /** | ||
| * Sanitizes and validates markdown content for safe use in email templates. | ||
| * | ||
| * This function: | ||
| * - Trims whitespace | ||
| * - Validates the content is valid text (not binary) | ||
| * - Checks for suspicious patterns that could cause DoS issues | ||
| * - Normalizes line endings | ||
| * | ||
| * @param markdown - The markdown string to sanitize | ||
| * @returns The sanitized markdown string, or null if invalid/binary content detected | ||
| */ | ||
| export function sanitizeMarkdown( | ||
| markdown: string | null | undefined, | ||
| ): string | null { | ||
| if (!markdown || typeof markdown !== "string") { | ||
| return null; | ||
| } | ||
|
|
||
| // Trim whitespace | ||
| let sanitized = markdown.trim(); | ||
|
|
||
| // Return null if empty after trimming | ||
| if (!sanitized) { | ||
| return null; | ||
| } | ||
|
|
||
| // Check for binary content - markdown should be valid UTF-8 text | ||
| // Reject if there are null bytes (indicates binary content) | ||
| if (sanitized.includes("\0")) { | ||
| return null; | ||
| } | ||
|
|
||
| // Check for suspicious patterns that could cause DoS or rendering issues | ||
| // Reject content with excessively long lines to avoid malformed markdown | ||
| const maxLineLength = 1000; | ||
| const hasExcessivelyLongLine = sanitized | ||
| .split("\n") | ||
| .some((line) => line.length > maxLineLength); | ||
|
|
||
| if (hasExcessivelyLongLine) { | ||
| return null; | ||
| } | ||
|
|
||
| // Normalize line endings | ||
| sanitized = sanitized.replace(/\r\n/g, "\n").replace(/\r/g, "\n"); | ||
|
|
||
| return sanitized; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| export const programInviteEmailDataSchema = z | ||
| .object({ | ||
| subject: z.string(), | ||
| title: z.string(), | ||
| body: z.string(), | ||
| }) | ||
| .nullish(); | ||
steven-tey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.