Skip to content

Build end-to-end dashboard inbox workflow - #7

Merged
KMKoushik merged 2 commits into
mainfrom
feat/dashboard-inbox-workbench
Mar 8, 2026
Merged

KMKoushik merged 2 commits into
mainfrom
feat/dashboard-inbox-workbench

Conversation

@KMKoushik

@KMKoushik KMKoushik commented Mar 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • replace the placeholder dashboard with an end-to-end inbox workbench for creating inboxes, managing aliases, browsing threads, reading messages, and sending or replying from the UI
  • add a small typed dashboard API client so the page can talk to inbox, thread, message, and send endpoints without duplicating fetch logic inline
  • surface delivery state, body storage metadata, and clear empty/loading states so the MVP dashboard is usable across desktop and mobile

Validation

  • pnpm test
  • pnpm exec tsc --noEmit
  • pnpm build

Summary by CodeRabbit

New Features

  • Unveiled a comprehensive inbox dashboard with full message composition, reply, and management capabilities
  • Integrated intelligent selection management for inboxes, threads, and messages with automatic defaults
  • Added comprehensive state handling including loading indicators, empty states, and inline action feedback for all operations

@coderabbitai

coderabbitai Bot commented Mar 8, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3274fb2a-5077-4d16-a4a3-71686c2725b4

📥 Commits

Reviewing files that changed from the base of the PR and between 1678bd8 and 0ea579a.

📒 Files selected for processing (2)
  • src/lib/orpc-client.ts
  • src/routes/dashboard.tsx

📝 Walkthrough

Walkthrough

A comprehensive inbox workbench UI was added to the dashboard route with full client-side data flows powered by React Query. An accompanying ORPC client module was created to establish typed RPC communication with the server backend.

Changes

Cohort / File(s) Summary
Dashboard Inbox Workbench
src/routes/dashboard.tsx
Complete inbox workbench implementation with DashboardPage component featuring selection state management for inboxes/threads/messages, useQuery/useMutation hooks for CRUD operations, ComposePanel and MessageDetailPanel for message handling, comprehensive UI components (Panel, MetricCard, StatusPill, EmptyState, etc.), loading/error/empty state handling, and mutation invalidation patterns for cache consistency.
RPC Client Setup
src/lib/orpc-client.ts
New ORPC client module establishing typed RPC communication via createORPCClient with browser-aware URL resolution and Tanstack Query utilities export for integration with React Query hooks.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 A burrow of code, where inboxes gleam,
React Queries dance through the messaging stream,
From compose to send, with mutations that flow,
A dashboard workbench where rabbit mails go! 📬✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main objective of the PR: building a complete end-to-end dashboard inbox workflow with the new API client and comprehensive UI components.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/dashboard-inbox-workbench

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
src/routes/dashboard.tsx (1)

43-45: Let the route own metadata and the first loading boundary.

This stays a bare component route, so the dashboard never declares its own head, and initial auth/data work can only begin after mount. Even if some queries must remain client-side, this route should still own head and any preloading/redirect logic it can. Based on learnings, Use route loader for data loading and head for metadata.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/routes/dashboard.tsx` around lines 43 - 45, The Route currently registers
only a bare component via createFileRoute('/dashboard') with component:
DashboardPage, so the route doesn't own metadata or a loader/first loading
boundary; change the route registration to provide a loader (e.g.,
dashboardLoader) for initial auth/data preloading and a head function (e.g.,
dashboardHead) so the route controls metadata and can perform redirects/preload
before mount, and ensure the DashboardPage component is passed as the component
or as children while the loader and head are on the Route definition
(referencing Route, createFileRoute, DashboardPage for where to apply the
changes).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/dashboard-api.ts`:
- Around line 111-116: The helpers listThreadsByInbox and listThreadMessages
currently hardcode page 1; update them to accept an optional cursor parameter
(e.g., cursor?: string) and forward it into the requestJson call so callers can
fetch subsequent pages returned in ListThreadsResult.nextCursor and
ListMessagesResult.nextCursor. Concretely, change the signatures of
listThreadsByInbox(inboxId: string, cursor?: string) and
listThreadMessages(threadId: string, cursor?: string) and build the query string
for requestJson(`/api/inboxes/${inboxId}/threads?limit=25${cursor ?
`&cursor=${encodeURIComponent(cursor)}` : ''}`) and similarly for
`/api/threads/${threadId}/messages?limit=100...`, ensuring you URL-encode the
cursor before appending.

In `@src/routes/dashboard.tsx`:
- Around line 93-132: The UI currently hides query failures by treating
query.data fallback to empty arrays; update the render logic for the inboxes,
threads, messages and message detail panels to check each query's isError
(inboxesQuery.isError, threadsQuery.isError, messagesQuery.isError,
messageDetailQuery.isError) and render an error state (message + retry control
or error details) instead of the empty-state UI when true; implement this by
branching before using the normalized data (inboxes, threads, threadMessages,
selectedMessage) so that on isError you display an error panel (and optionally a
retry trigger like refetch) and only fall back to the empty-state when there is
no error and the data is empty.
- Around line 945-949: The dashboard currently injects unsanitized HTML via
dangerouslySetInnerHTML when hasHtml is true using message.htmlBody; update this
to sanitize the inbound HTML before rendering (or render in a sandboxed iframe).
Import and use a trusted sanitizer (e.g., DOMPurify) and replace direct usage of
message.htmlBody with a sanitized variable (e.g., const sanitizedHtml =
DOMPurify.sanitize(message.htmlBody || '', {ALLOWED_TAGS: ..., ALLOWED_ATTR:
...})) then pass sanitizedHtml to dangerouslySetInnerHTML; alternatively, render
the content inside a sandboxed iframe component if isolation is preferred.
Ensure the sanitization happens in the component that renders the HTML (the code
path using hasHtml / message.htmlBody) so no raw HTML is injected into the DOM.
- Around line 134-165: The reconciliation effects are overwriting freshly
selected IDs because they run before refetch completes; introduce and use
“pending” selection markers set by your mutation success handlers (e.g.
createInboxMutation, createThreadMutation, sendMessageMutation) — e.g.
pendingInboxId, pendingThreadId, pendingMessageId — and update
selectedInboxId/selectedThreadId/selectedMessageId immediately in those
handlers; then change each effect (the ones referencing inboxes +
selectedInboxId, threads + selectedThreadId, threadMessages + selectedMessageId)
to skip resetting the selection when the current selected ID equals a pending*Id
or a pending*Id exists (i.e. only auto-select when selected... is null or not
found AND no pending*Id is present), and clear the corresponding pending*Id once
the refetch/invalidateQueries completes or when the item appears in the list.

---

Nitpick comments:
In `@src/routes/dashboard.tsx`:
- Around line 43-45: The Route currently registers only a bare component via
createFileRoute('/dashboard') with component: DashboardPage, so the route
doesn't own metadata or a loader/first loading boundary; change the route
registration to provide a loader (e.g., dashboardLoader) for initial auth/data
preloading and a head function (e.g., dashboardHead) so the route controls
metadata and can perform redirects/preload before mount, and ensure the
DashboardPage component is passed as the component or as children while the
loader and head are on the Route definition (referencing Route, createFileRoute,
DashboardPage for where to apply the changes).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 485ba990-58ed-42b1-ae8b-b9c68377dec3

📥 Commits

Reviewing files that changed from the base of the PR and between afe114a and 1678bd8.

📒 Files selected for processing (2)
  • src/lib/dashboard-api.ts
  • src/routes/dashboard.tsx

Comment thread src/lib/dashboard-api.ts Outdated
Comment on lines +111 to +116
export async function listThreadsByInbox(inboxId: string) {
return requestJson<ListThreadsResult>(`/api/inboxes/${inboxId}/threads?limit=25`)
}

export async function listThreadMessages(threadId: string) {
return requestJson<ListMessagesResult>(`/api/threads/${threadId}/messages?limit=100`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Expose cursor arguments in these list helpers.

ListThreadsResult and ListMessagesResult already carry nextCursor, but these helpers hardcode the first page and give the route no way to ask for older results. Once an inbox exceeds 25 threads or a thread exceeds 100 messages, the workbench will silently truncate what users can browse.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/dashboard-api.ts` around lines 111 - 116, The helpers
listThreadsByInbox and listThreadMessages currently hardcode page 1; update them
to accept an optional cursor parameter (e.g., cursor?: string) and forward it
into the requestJson call so callers can fetch subsequent pages returned in
ListThreadsResult.nextCursor and ListMessagesResult.nextCursor. Concretely,
change the signatures of listThreadsByInbox(inboxId: string, cursor?: string)
and listThreadMessages(threadId: string, cursor?: string) and build the query
string for requestJson(`/api/inboxes/${inboxId}/threads?limit=25${cursor ?
`&cursor=${encodeURIComponent(cursor)}` : ''}`) and similarly for
`/api/threads/${threadId}/messages?limit=100...`, ensuring you URL-encode the
cursor before appending.

Comment thread src/routes/dashboard.tsx Outdated
Comment on lines +93 to +132
const inboxes = inboxesQuery.data ?? []
const selectedInbox = useMemo(
() => inboxes.find((inbox) => inbox.id === selectedInboxId) ?? null,
[inboxes, selectedInboxId],
)

const threadsQuery = useQuery({
enabled: isReady && Boolean(selectedInboxId),
queryFn: () => listThreadsByInbox(selectedInboxId!),
queryKey: [...DASHBOARD_QUERY_KEY, 'threads', selectedInboxId],
staleTime: 3_000,
})

const threads = threadsQuery.data?.items ?? []
const selectedThread = useMemo(
() => threads.find((thread) => thread.id === selectedThreadId) ?? null,
[threads, selectedThreadId],
)

const messagesQuery = useQuery({
enabled: isReady && Boolean(selectedThreadId),
queryFn: () => listThreadMessages(selectedThreadId!),
queryKey: [...DASHBOARD_QUERY_KEY, 'messages', selectedThreadId],
staleTime: 3_000,
})

const threadMessages = messagesQuery.data?.items ?? []
const selectedMessageSummary = useMemo(
() => threadMessages.find((message) => message.id === selectedMessageId) ?? null,
[threadMessages, selectedMessageId],
)

const messageDetailQuery = useQuery({
enabled: isReady && Boolean(selectedMessageId),
queryFn: () => getMessage(selectedMessageId!),
queryKey: [...DASHBOARD_QUERY_KEY, 'message', selectedMessageId],
staleTime: 3_000,
})

const selectedMessage = messageDetailQuery.data ?? null

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n src/routes/dashboard.tsx | head -150

Repository: KMKoushik/clankr-email

Length of output: 5207


🏁 Script executed:

cat -n src/routes/dashboard.tsx | sed -n '160,250p'

Repository: KMKoushik/clankr-email

Length of output: 3549


🏁 Script executed:

cat -n src/routes/dashboard.tsx | sed -n '250,350p'

Repository: KMKoushik/clankr-email

Length of output: 5876


🏁 Script executed:

cat -n src/routes/dashboard.tsx | sed -n '335,385p'

Repository: KMKoushik/clankr-email

Length of output: 2750


🏁 Script executed:

cat -n src/routes/dashboard.tsx | sed -n '500,570p'

Repository: KMKoushik/clankr-email

Length of output: 3812


🏁 Script executed:

cat -n src/routes/dashboard.tsx | sed -n '655,730p'

Repository: KMKoushik/clankr-email

Length of output: 4691


Add error state rendering to query panels.

These four query handlers normalize failed requests to empty data without checking isError, so network failures silently display empty state messages ("No inboxes yet", "No threads yet", etc.) instead of error feedback. Users cannot distinguish between truly empty results and actual failures.

Add error branches for inboxesQuery.isError, threadsQuery.isError, messagesQuery.isError, and messageDetailQuery.isError at lines 335, 504, 659, and 714 respectively.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/routes/dashboard.tsx` around lines 93 - 132, The UI currently hides query
failures by treating query.data fallback to empty arrays; update the render
logic for the inboxes, threads, messages and message detail panels to check each
query's isError (inboxesQuery.isError, threadsQuery.isError,
messagesQuery.isError, messageDetailQuery.isError) and render an error state
(message + retry control or error details) instead of the empty-state UI when
true; implement this by branching before using the normalized data (inboxes,
threads, threadMessages, selectedMessage) so that on isError you display an
error panel (and optionally a retry trigger like refetch) and only fall back to
the empty-state when there is no error and the data is empty.

Comment thread src/routes/dashboard.tsx
Comment on lines +134 to +165
useEffect(() => {
if (inboxes.length === 0) {
setSelectedInboxId(null)
return
}

if (!selectedInboxId || !inboxes.some((inbox) => inbox.id === selectedInboxId)) {
setSelectedInboxId(inboxes[0]!.id)
}
}, [inboxes, selectedInboxId])

useEffect(() => {
if (threads.length === 0) {
setSelectedThreadId(null)
return
}

if (!selectedThreadId || !threads.some((thread) => thread.id === selectedThreadId)) {
setSelectedThreadId(threads[0]!.id)
}
}, [selectedThreadId, threads])

useEffect(() => {
if (threadMessages.length === 0) {
setSelectedMessageId(null)
return
}

if (!selectedMessageId || !threadMessages.some((message) => message.id === selectedMessageId)) {
setSelectedMessageId(threadMessages.at(-1)?.id ?? null)
}
}, [selectedMessageId, threadMessages])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's examine the file and understand its structure
wc -l src/routes/dashboard.tsx

Repository: KMKoushik/clankr-email

Length of output: 95


🏁 Script executed:

# Read the specific lines mentioned in the review (134-165 and 173-230)
sed -n '130,240p' src/routes/dashboard.tsx | cat -n

Repository: KMKoushik/clankr-email

Length of output: 4264


🏁 Script executed:

# Search for the mutation definitions mentioned
rg -n "createInboxMutation|sendMessageMutation" src/routes/dashboard.tsx -A 5

Repository: KMKoushik/clankr-email

Length of output: 2102


🏁 Script executed:

# Look for cache invalidation logic
rg -n "invalidateQueries|refetch" src/routes/dashboard.tsx -B 2 -A 2

Repository: KMKoushik/clankr-email

Length of output: 1052


🏁 Script executed:

# Search for queryClient initialization/configuration
rg -n "new QueryClient|createQueryClient|queryClient.*=" src/routes/dashboard.tsx -B 3 -A 5

Repository: KMKoushik/clankr-email

Length of output: 482


🏁 Script executed:

# Check for any refetch synchronization patterns or options
rg -n "refetchType|await.*refetch|queryClient\." src/routes/dashboard.tsx | head -30

Repository: KMKoushik/clankr-email

Length of output: 293


🏁 Script executed:

# Look for the query definitions and how inboxes/threads/messages are queried
rg -n "useQuery.*inboxes|useQuery.*threads|useQuery.*messages" src/ -A 8

Repository: KMKoushik/clankr-email

Length of output: 48


🏁 Script executed:

# Check if invalidateQueries has any specific options being passed
rg -n "invalidateQueries" src/routes/dashboard.tsx -B 2 -A 3

Repository: KMKoushik/clankr-email

Length of output: 890


🏁 Script executed:

# Let's get the exact line numbers for the full context of mutations and effects
sed -n '130,235p' src/routes/dashboard.tsx | head -110 | cat -n

Repository: KMKoushik/clankr-email

Length of output: 3926


🏁 Script executed:

# Check TanStack Query version to understand invalidateQueries behavior
cat package.json | grep -A 2 -B 2 "@tanstack/react-query"

Repository: KMKoushik/clankr-email

Length of output: 327


🏁 Script executed:

# Look for any awaited refetch patterns or synchronization mechanisms
rg -n "refetch()" src/routes/dashboard.tsx -B 2 -A 2

Repository: KMKoushik/clankr-email

Length of output: 259


🏁 Script executed:

# Let's understand what happens after invalidateQueries by checking query setup
# First, find where inboxesQuery is defined
rg -n "inboxesQuery|const.*inboxes.*useQuery" src/routes/dashboard.tsx -B 2 -A 8

Repository: KMKoushik/clankr-email

Length of output: 1142


🏁 Script executed:

# Check the actual query key structure and any refetch settings
rg -n "DASHBOARD_QUERY_KEY\|queryKey:" src/routes/dashboard.tsx | head -20

Repository: KMKoushik/clankr-email

Length of output: 48


🏁 Script executed:

# Let's verify the exact line numbers for the "Also applies to: 173-230" section
sed -n '173,230p' src/routes/dashboard.tsx | cat -n

Repository: KMKoushik/clankr-email

Length of output: 2401


🏁 Script executed:

# Check if there are any utility functions or patterns for handling optimistic updates
rg -n "optimistic|onMutate|setQueryData" src/routes/dashboard.tsx -B 2 -A 3

Repository: KMKoushik/clankr-email

Length of output: 48


🏁 Script executed:

# Let's verify the full query definitions including threadsQuery and messagesQuery
sed -n '86,125p' src/routes/dashboard.tsx | cat -n

Repository: KMKoushik/clankr-email

Length of output: 1638


🏁 Script executed:

# Check what happens during the actual data refetch - search for any success handlers on queries
rg -n "threadsQuery|messagesQuery" src/routes/dashboard.tsx | head -15

Repository: KMKoushik/clankr-email

Length of output: 730


Fix reconciliation effects to avoid overwriting freshly selected IDs.

After mutations (createInboxMutation, sendMessageMutation) set a new inbox/thread/message ID, the reconciliation effects immediately overwrite it because the new item isn't in the cache yet. The effects run with stale lists before invalidateQueries() completes the refetch, causing the selected ID to fail validation and reset to inboxes[0], threads[0], or the last cached message. Newly created or sent items do not stay selected.

Affected code
  useEffect(() => {
    if (inboxes.length === 0) {
      setSelectedInboxId(null)
      return
    }

    if (!selectedInboxId || !inboxes.some((inbox) => inbox.id === selectedInboxId)) {
      setSelectedInboxId(inboxes[0]!.id)
    }
  }, [inboxes, selectedInboxId])

  useEffect(() => {
    if (threads.length === 0) {
      setSelectedThreadId(null)
      return
    }

    if (!selectedThreadId || !threads.some((thread) => thread.id === selectedThreadId)) {
      setSelectedThreadId(threads[0]!.id)
    }
  }, [selectedThreadId, threads])

  useEffect(() => {
    if (threadMessages.length === 0) {
      setSelectedMessageId(null)
      return
    }

    if (!selectedMessageId || !threadMessages.some((message) => message.id === selectedMessageId)) {
      setSelectedMessageId(threadMessages.at(-1)?.id ?? null)
    }
  }, [selectedMessageId, threadMessages])
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/routes/dashboard.tsx` around lines 134 - 165, The reconciliation effects
are overwriting freshly selected IDs because they run before refetch completes;
introduce and use “pending” selection markers set by your mutation success
handlers (e.g. createInboxMutation, createThreadMutation, sendMessageMutation) —
e.g. pendingInboxId, pendingThreadId, pendingMessageId — and update
selectedInboxId/selectedThreadId/selectedMessageId immediately in those
handlers; then change each effect (the ones referencing inboxes +
selectedInboxId, threads + selectedThreadId, threadMessages + selectedMessageId)
to skip resetting the selection when the current selected ID equals a pending*Id
or a pending*Id exists (i.e. only auto-select when selected... is null or not
found AND no pending*Id is present), and clear the corresponding pending*Id once
the refetch/invalidateQueries completes or when the item appears in the list.

Comment thread src/routes/dashboard.tsx
Comment on lines +945 to +949
{hasHtml ? (
<div
className="prose prose-neutral dark:prose-invert max-w-none break-words prose-pre:overflow-x-auto"
dangerouslySetInnerHTML={{ __html: message.htmlBody ?? '' }}
/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

wc -l src/routes/dashboard.tsx

Repository: KMKoushik/clankr-email

Length of output: 95


🏁 Script executed:

# Read around the flagged lines to understand context
sed -n '900,1000p' src/routes/dashboard.tsx

Repository: KMKoushik/clankr-email

Length of output: 4693


🏁 Script executed:

# Search for where message comes from and any sanitization imports
rg -i "sanitize|purify|htmlBody" src/routes/dashboard.tsx -B 5 -A 5

Repository: KMKoushik/clankr-email

Length of output: 878


🏁 Script executed:

# Check what dependencies are available for HTML sanitization
cat package.json | grep -i "dompurify\|sanitize"

Repository: KMKoushik/clankr-email

Length of output: 48


🏁 Script executed:

# Find MessageDetail type definition
rg "type MessageDetail|interface MessageDetail" src/ -A 20

Repository: KMKoushik/clankr-email

Length of output: 1984


🏁 Script executed:

# Look for the route loader and how message data is fetched
sed -n '1,100p' src/routes/dashboard.tsx

Repository: KMKoushik/clankr-email

Length of output: 2660


🏁 Script executed:

# Check if there are any API utilities that might sanitize HTML
rg -i "sanitize|htmlbody" src/ --type ts --type tsx

Repository: KMKoushik/clankr-email

Length of output: 93


🏁 Script executed:

# Look at the dashboard-api to see where htmlBody comes from
cat src/lib/dashboard-api.ts

Repository: KMKoushik/clankr-email

Length of output: 4416


🏁 Script executed:

# Search for getMessage function to see how the API response is processed
rg "function getMessage|const getMessage" src/

Repository: KMKoushik/clankr-email

Length of output: 313


🏁 Script executed:

# Look at the backend read.ts file
cat src/lib/email/read.ts

Repository: KMKoushik/clankr-email

Length of output: 11489


🏁 Script executed:

# Search for the API route handler
rg "/api/messages" src/ -A 5

Repository: KMKoushik/clankr-email

Length of output: 1973


🏁 Script executed:

# Look for server-side code
find src -name "*.server.ts" -o -name "*.api.ts" | head -20

Repository: KMKoushik/clankr-email

Length of output: 48


🏁 Script executed:

# Search for email parsing and htmlBody population
rg "htmlBody|parseEmail|extractBody" src/ --type ts -B 3 -A 3

Repository: KMKoushik/clankr-email

Length of output: 16793


🏁 Script executed:

# Look for mail provider integration or MIME parsing
rg "mime|mail|email.*parse|parseMessage" src/ -i --type ts | head -30

Repository: KMKoushik/clankr-email

Length of output: 2162


🏁 Script executed:

# Verify where parsedEmail comes from - look for email parsing library
rg "parsedEmail|parse.*email" src/lib/email/inbound.ts -B 5 -A 5

Repository: KMKoushik/clankr-email

Length of output: 2840


Sanitize inbound HTML before rendering it.

Email HTML from arbitrary senders is parsed by PostalMime and stored directly without sanitization. When rendered via dangerouslySetInnerHTML in the dashboard, this creates an authenticated XSS surface where a malicious email sender can execute JavaScript in the context of the dashboard application. Sanitize the HTML (e.g., with DOMPurify) before storing or rendering it, or isolate it in a sandboxed iframe.

🧰 Tools
🪛 ast-grep (0.41.0)

[warning] 947-947: Usage of dangerouslySetInnerHTML detected. This bypasses React's built-in XSS protection. Always sanitize HTML content using libraries like DOMPurify before injecting it into the DOM to prevent XSS attacks.
Context: dangerouslySetInnerHTML
Note: [CWE-79] Improper Neutralization of Input During Web Page Generation [REFERENCES]
- https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml
- https://cwe.mitre.org/data/definitions/79.html

(react-unsafe-html-injection)

🪛 Biome (2.4.4)

[error] 948-948: Avoid passing content using the dangerouslySetInnerHTML prop.

(lint/security/noDangerouslySetInnerHtml)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/routes/dashboard.tsx` around lines 945 - 949, The dashboard currently
injects unsanitized HTML via dangerouslySetInnerHTML when hasHtml is true using
message.htmlBody; update this to sanitize the inbound HTML before rendering (or
render in a sandboxed iframe). Import and use a trusted sanitizer (e.g.,
DOMPurify) and replace direct usage of message.htmlBody with a sanitized
variable (e.g., const sanitizedHtml = DOMPurify.sanitize(message.htmlBody || '',
{ALLOWED_TAGS: ..., ALLOWED_ATTR: ...})) then pass sanitizedHtml to
dangerouslySetInnerHTML; alternatively, render the content inside a sandboxed
iframe component if isolation is preferred. Ensure the sanitization happens in
the component that renders the HTML (the code path using hasHtml /
message.htmlBody) so no raw HTML is injected into the DOM.

@KMKoushik
KMKoushik merged commit 715a268 into main Mar 8, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant