Sweetmantech/myc 3783 email pass input text html to recoup agent call#74
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThis PR introduces a complete inbound email processing system with agent-based chat routing. It adds webhook handling for Resend email events, a general agent factory that orchestrates tool setup and system prompt construction, supporting utilities for chat validation and prompt building, email client infrastructure, and updates to database queries and type definitions. Two new dependencies ( Changes
Sequence DiagramsequenceDiagram
participant Resend as Resend Webhook
participant Route as POST /api/emails/inbound
participant Validator as validateInboundEmailEvent
participant Handler as handleInboundEmail
participant EmailProc as respondToInboundEmail
participant ResendAPI as Resend API
participant DB as Account/Email DB
participant Agent as getGeneralAgent
participant MCP as MCP Tools
Resend->>Route: Email event (POST request)
Route->>Handler: Delegate to handleInboundEmail
Handler->>Validator: Validate event payload
alt Validation fails
Validator-->>Handler: NextResponse (400)
Handler-->>Resend: Return error response
else Validation succeeds
Validator-->>Handler: Validated event
Handler->>EmailProc: Process email.received event
EmailProc->>ResendAPI: Fetch email content
ResendAPI-->>EmailProc: Email text/HTML content
EmailProc->>DB: Lookup sender account by email
DB-->>EmailProc: Account details
EmailProc->>Agent: Generate response (email as chat message)
Agent->>MCP: Query available tools
MCP-->>Agent: Tool definitions (ToolSet)
Agent->>DB: Fetch account context, artist info, knowledge base
DB-->>Agent: Context & instructions
Agent-->>EmailProc: Response text & model info
EmailProc->>ResendAPI: Send reply (In-Reply-To header)
ResendAPI-->>EmailProc: Confirmation
EmailProc-->>Handler: API response
Handler-->>Resend: Return success
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45–60 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Additional Suggestion:
The response email exposes internal account_id to external email recipients, which is a security/information disclosure issue that should be removed or redacted.
View Details
📝 Patch Details
diff --git a/lib/emails/inbound/respondToInboundEmail.ts b/lib/emails/inbound/respondToInboundEmail.ts
index 866f31f..5238294 100644
--- a/lib/emails/inbound/respondToInboundEmail.ts
+++ b/lib/emails/inbound/respondToInboundEmail.ts
@@ -48,7 +48,7 @@ export async function respondToInboundEmail(
from: "hi@recoupable.com",
to: toArray,
subject,
- html: `<p>Thanks for your email!</p><p>account_id: ${accountId}</p><p>${chatResponse.text}</p>`,
+ html: `<p>Thanks for your email!</p><p>${chatResponse.text}</p>`,
headers: {
"In-Reply-To": messageId,
},
Analysis
Information Disclosure: Internal account_id exposed in email response
What fails: respondToInboundEmail() in lib/emails/inbound/respondToInboundEmail.ts exposes the internal account_id to external email recipients via the HTML email body
How to reproduce:
- Send an email to the Resend inbound email endpoint (hi@recoupable.com or similar configured address)
- The webhook handler processes the email and calls respondToInboundEmail()
- The function retrieves the account_id from the database and includes it in the HTML response:
html: '<p>Thanks for your email!</p><p>account_id: - External email recipients receive an email containing the internal account_id
Result: Email response body contains: account_id: <uuid_or_id_value> sent to external email addresses
Expected: Email response should not expose internal identifiers to external parties. Only user-facing information should be in the email body.
Security Impact:
- Information Disclosure: Exposes implementation details and internal system identifiers
- Enumeration Risk: Attackers could potentially use exposed IDs for enumeration attacks
- Violates security principle of not exposing internal identifiers in external communications
Fix: Removed the account_id from the HTML email template. The account_id is still available internally for processing and logging but is no longer exposed to external recipients.
There was a problem hiding this comment.
This PR is being reviewed by Cursor Bugbot
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| const chatResponse = await agent.generate({ | ||
| prompt: "hello world", | ||
| prompt: emailText, | ||
| }); |
There was a problem hiding this comment.
Bug: Untrusted email drives tool-enabled agent
Inbound sender-controlled content from getEmailContent() is passed directly into getGeneralAgent() and agent.generate() as the prompt/messages. Because the agent is configured with external tools, this enables prompt-injection-driven tool use and unintended data disclosure/side effects during webhook processing.
Note
Fetches inbound email body from Resend and uses it to drive agent-generated thread replies.
lib/emails/inbound/getEmailContent.tsto retrieve email body via Resend Receiving API (preferstext, falls back tohtml).respondToInboundEmailto:email_idto fetchemailTextand feed it intogetMessagesand agentgenerateprompt.In-Reply-To.Written by Cursor Bugbot for commit 987022b. This will update automatically on new commits. Configure here.
Summary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.