Skip to content

fix(emails): BCC scrape-alert recipients — never a shared cross-tenant To: line#758

Merged
sweetmantech merged 2 commits into
mainfrom
fix/scrape-alert-bcc
Jul 9, 2026
Merged

fix(emails): BCC scrape-alert recipients — never a shared cross-tenant To: line#758
sweetmantech merged 2 commits into
mainfrom
fix/scrape-alert-bcc

Conversation

@sweetmantech

@sweetmantech sweetmantech commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

The "{artist} has new posts on Instagram" alert resolved every watcher of a social across all customer accounts into a single visible To: line — live evidence on the tracking issue shows a customer manager, an internal account, and a label contact (sam.palm@wmg.com) all mutually visible on one send. This PR hard-codes the privacy boundary: to is always our own from-address (Resend requires non-empty to), all recipients ride bcc.

Tracking issue: recoupable/chat#1855 (PR #1 of 6 — ships first and alone; nothing gates it).

What changed

  • lib/apify/sendApifyWebhookEmail.ts: to: [RECOUP_FROM_EMAIL] + bcc: emails (the Resend wrapper already passes bcc through natively — no wrapper change).
  • lib/apify/__tests__/sendApifyWebhookEmail.test.ts (new): asserts recipients land in bcc, and a guard-rail test that to/cc never contain more than our own address regardless of recipient count — so a future platform copy-paste can't reintroduce the leak.

Tests

RED→GREEN: 2 new assertions failed against the old implementation (to: emails), pass after (3/3). eslint clean.

🤖 Generated with Claude Code


Summary by cubic

Fixes a privacy leak in Instagram scrape-alert emails by moving all recipients to BCC and setting To to our own sender address. Prevents cross-tenant addresses from being visible to each other (recoupable/chat#1855).

  • Bug Fixes
    • Update sendApifyWebhookEmail to use to: [RECOUP_FROM_EMAIL] and bcc: emails.
    • Add tests enforcing BCC-only recipients, to/cc limited to our address, and no send when recipient list is empty.

Written for commit 4f04c68. Summary will update on new commits.

Review in cubic

…t To: line

sendApifyWebhookEmail put every watcher of a social (resolved across all
customer accounts) into one visible To: header, disclosing customer
identities and monitoring relationships to each other (observed live:
a manager, an internal account, and a label contact in one To: line).
Hard-coded: to is always ourselves, recipients ride bcc; a unit test
asserts to/cc never carry more than our own address (recoupable/chat#1855
PR #1 of 6).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api Ready Ready Preview Jul 9, 2026 4:08pm

Request Review

@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@sweetmantech, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 95c9bb23-c1be-42ff-8603-ac70887f80ef

📥 Commits

Reviewing files that changed from the base of the PR and between 1b8012b and 4f04c68.

⛔ Files ignored due to path filters (1)
  • lib/apify/__tests__/sendApifyWebhookEmail.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
📒 Files selected for processing (1)
  • lib/apify/sendApifyWebhookEmail.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/scrape-alert-bcc

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.

❤️ Share

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

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant Caller as Apify Webhook
    participant Handler as sendApifyWebhookEmail
    participant Wrapper as sendEmailWithResend
    participant Resend as Resend API

    Note over Caller,Handler: Privacy boundary: watchers from different tenants

    Caller->>Handler: sendApifyWebhookEmail(profile, emails)

    alt emails is empty
        Handler-->>Caller: return null (no email sent)
    else emails non-empty
        Handler->>Handler: generate email body from profile

        Note over Handler: To: always our own address<br/>BCC: all recipients (cross-tenant safe)

        Handler->>Wrapper: sendEmailWithResend({ to: [RECOUP_FROM_EMAIL], bcc: emails, ... })

        Wrapper->>Resend: POST /emails (to=bcc set)
        Resend-->>Wrapper: success response
        Wrapper-->>Handler: result (e.g., { id })

        Handler-->>Caller: return result
    end
Loading

Auto-approved: Fixes email privacy by moving all recipients to BCC; adds tests for the new behavior. Small, isolated change with low risk.

Re-trigger cubic

@sweetmantech

Copy link
Copy Markdown
Contributor Author

Preview verification — 2026-07-09

Preview: https://api-o0lgjbsm6-recoup.vercel.app (confirmed built from PR head f178c94, deployment Ready 2026-07-06T21:54:03Z).

Method: created an isolated [TEST] artist under my own account watching instagram.com/natgeo (a social watched by no other tenant — fan-out audited via account_socials → account_artist_ids → account_emails before sending: exactly ['sweetmantech@gmail.com']), then ran the real chain: POST /api/socials/{id}/scrape on the preview → Apify run → ACTOR.RUN.SUCCEEDED webhook dispatched to the preview's /api/apify → alert email sent by the PR code. Send verified against Resend's stored record via GET /api/admins/emails?email_id=….

# Check Expected Actual on preview Result
1 E2E chain fires the PR code scrape → webhook → email run TuV7U7TXngr6uEFmD SUCCEEDED; Apify dispatch 2026-07-09T15:38:15Z → preview /api/apify HTTP 200; 12 posts + social persisted; sentEmails.id returned
2 to is only our own address to: [RECOUP_FROM_EMAIL] Resend record 1a2769e9-224a-49d1-a324-5e474e7078f5: to: ["Agent by Recoup <agent@recoupable.dev>"]
3 recipients ride bcc bcc: emails bcc: ["sweetmantech@gmail.com"], cc: [], last_event: delivered (2026-07-09 15:42:13 UTC)
4 No customer address in visible headers to/cc never carry more than our own address visible headers contain only agent@recoupable.dev; recipient appears in bcc only
5 Webhook rejects malformed JSON 200 + error body (Apify contract) POST /api/apify body not json → HTTP 200 {"status":"error","error":"Invalid JSON"}
6 Webhook rejects missing fields 200 + error body {"eventData":{}} → HTTP 200 {"status":"error","missing_fields":["eventData","actorId"]}
7 Scrape trigger auth 401 without credentials POST /api/socials/{id}/scrape no auth → HTTP 401
8 Scrape unknown social 404 id 00000000-… → HTTP 404 Social profile not found
9 Unit suite 3/3 green CI test check SUCCESS on f178c94

Notes:

  • The live send exercised a single-recipient fan-out (the only safely isolatable one — every pre-existing social's watcher set includes external customers). The multi-recipient guard-rail (25 recipients, to/cc still only our address) is covered by the new unit test in this PR and is green in CI.
  • Replaying the identical webhook payload produced a second identical email: the no-newness-gate defect is intact as expected — that is api#759's scope, not this PR's.
  • The delivered body is still LLM-generated and contains "Apify" — unchanged here as expected; deterministic template is api#761's scope.
  • Test fixture fully cleaned after verification: [TEST] artist deleted via DELETE /api/artists/{id}, plus the 2 test socials rows, 12 posts, 12 social_posts, and their post_comments removed; no account_socials links remain.

Verdict: the privacy invariant this PR ships is live and correct on the preview. LGTM to ship first and alone per the chat#1855 sequencing.

@cursor

cursor Bot commented Jul 9, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@sweetmantech sweetmantech merged commit aba6835 into main Jul 9, 2026
4 of 6 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