-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fraud improvements #3159
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
Fraud improvements #3159
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughRemoved customer data from grouped fraud event schema and its query/mapping; gated fraud detection calls on webhookPartner truthiness; added a retry helper and replaced static waits in tests; adjusted identity-hash environment gating and added an error log in fraud recording. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Event Source
participant Guard as webhookPartner check
participant Fraud as detectAndRecordFraudEvent
participant DB as grouped fraud query
rect rgb(240,240,240)
note right of Caller: New flow (high level)
Caller->>Guard: provides webhookPartner
alt webhookPartner truthy
Guard->>Fraud: invoke detectAndRecordFraudEvent(...)
Fraud->>DB: record / query grouped events (customer fields removed)
DB-->>Fraud: grouped event(s)
Fraud-->>Caller: success
else webhookPartner falsy
Guard-->>Caller: skip fraud detection
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/web/lib/api/fraud/get-grouped-fraud-events.ts(3 hunks)apps/web/lib/types.ts(2 hunks)apps/web/lib/zod/schemas/fraud.ts(1 hunks)apps/web/tests/fraud/index.test.ts(5 hunks)apps/web/tests/utils/helpers.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: devkiran
Repo: dubinc/dub PR: 3089
File: apps/web/lib/api/fraud/fraud-rules-registry.ts:17-25
Timestamp: 2025-11-24T09:10:12.494Z
Learning: In apps/web/lib/api/fraud/fraud-rules-registry.ts, the fraud rules `partnerCrossProgramBan` and `partnerDuplicatePayoutMethod` intentionally have stub implementations that return `{ triggered: false }` because they are partner-scoped rules handled separately during partner application/onboarding flows (e.g., in detect-record-fraud-application.ts), rather than being evaluated per conversion event like other rules in the registry. The stubs exist only to satisfy the `Record<FraudRuleType, ...>` type constraint.
📚 Learning: 2025-11-24T09:10:12.494Z
Learnt from: devkiran
Repo: dubinc/dub PR: 3089
File: apps/web/lib/api/fraud/fraud-rules-registry.ts:17-25
Timestamp: 2025-11-24T09:10:12.494Z
Learning: In apps/web/lib/api/fraud/fraud-rules-registry.ts, the fraud rules `partnerCrossProgramBan` and `partnerDuplicatePayoutMethod` intentionally have stub implementations that return `{ triggered: false }` because they are partner-scoped rules handled separately during partner application/onboarding flows (e.g., in detect-record-fraud-application.ts), rather than being evaluated per conversion event like other rules in the registry. The stubs exist only to satisfy the `Record<FraudRuleType, ...>` type constraint.
Applied to files:
apps/web/lib/types.tsapps/web/tests/fraud/index.test.tsapps/web/lib/zod/schemas/fraud.ts
🧬 Code graph analysis (3)
apps/web/lib/api/fraud/get-grouped-fraud-events.ts (1)
apps/web/lib/zod/schemas/fraud.ts (1)
groupedFraudEventSchema(12-32)
apps/web/lib/types.ts (1)
apps/web/lib/zod/schemas/fraud.ts (1)
groupedFraudEventSchema(12-32)
apps/web/tests/fraud/index.test.ts (3)
apps/web/lib/types.ts (2)
Customer(424-424)fraudEventGroupProps(676-676)apps/web/tests/utils/resource.ts (1)
E2E_FRAUD_PARTNER(220-227)apps/web/tests/utils/helpers.ts (1)
retry(37-58)
🪛 GitHub Actions: Public API Tests
apps/web/tests/fraud/index.test.ts
[error] 252-252: Fraud event not ready.
[error] 252-252: Fraud event not ready.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (6)
apps/web/lib/api/fraud/get-grouped-fraud-events.ts (1)
2-2: LGTM! Schema rename is consistent.The import and usage of
groupedFraudEventSchemaaligns with the schema changes across the codebase.Also applies to: 131-131
apps/web/tests/utils/helpers.ts (1)
37-58: LGTM! Clean retry utility implementation.The retry utility is well-implemented with sensible defaults and proper error handling. This provides a reusable pattern for polling operations in tests.
apps/web/lib/types.ts (1)
62-62: LGTM! Type definition updated consistently.The import and type inference changes align with the schema rename in
apps/web/lib/zod/schemas/fraud.ts.Also applies to: 676-676
apps/web/lib/zod/schemas/fraud.ts (1)
12-32: LGTM! Schema refactored to remove customer data.The schema rename and customer field removal align with the PR objectives for fraud improvements. The schema shape is consistent with the query results in
get-grouped-fraud-events.ts.apps/web/tests/fraud/index.test.ts (2)
190-227: LGTM! Simplified verification signature.The updated
verifyFraudEventfunction now only requiresexternalId, which aligns with the removal of customer data from the grouped fraud event schema.
14-14: Concurrent test execution requires database-level transaction isolation.The fraud tests share the same
E2E_FRAUD_PARTNERacross all concurrent tests. While customer isolation viarandomCustomer()prevents direct conflicts, the fraud event creation logic indetectAndRecordFraudEvent()(apps/web/lib/api/fraud/detect-record-fraud-event.ts, lines 63–92) contains a Time-of-Check-Time-of-Use (TOCTOU) race condition: events are read (line 63) and checked for duplicates, but new events are created later (line 92) without atomic transactional protection. Concurrent test execution could cause:
- Duplicate fraud events for the same partner/customer/type combination
- Test flakiness if fraud event queries return unexpected duplicates
- Unpredictable results when multiple tests trigger fraud rules simultaneously
Either wrap fraud event creation in a database transaction to ensure atomicity, or convert this suite to sequential execution (remove
.concurrent).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/web/lib/middleware/utils/get-identity-hash.ts (1)
9-16: Gate identity-hash debug logging to non‑productionLogging
"getIdentityHash", process.env.NODE_ENVon every request will be noisy in production and adds avoidable overhead on a hot path, with limited diagnostic value once issues are resolved.Recommend either removing this or gating it to non‑production and downgrading to
console.debug, e.g.:-export async function getIdentityHash(req: Request) { - console.log("getIdentityHash", process.env.NODE_ENV) +export async function getIdentityHash(req: Request) { + if (process.env.NODE_ENV !== "production") { + console.debug("getIdentityHash", process.env.NODE_ENV); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/web/lib/api/fraud/detect-record-fraud-event.ts(1 hunks)apps/web/lib/middleware/utils/get-identity-hash.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: devkiran
Repo: dubinc/dub PR: 3089
File: apps/web/lib/api/fraud/fraud-rules-registry.ts:17-25
Timestamp: 2025-11-24T09:10:12.494Z
Learning: In apps/web/lib/api/fraud/fraud-rules-registry.ts, the fraud rules `partnerCrossProgramBan` and `partnerDuplicatePayoutMethod` intentionally have stub implementations that return `{ triggered: false }` because they are partner-scoped rules handled separately during partner application/onboarding flows (e.g., in detect-record-fraud-application.ts), rather than being evaluated per conversion event like other rules in the registry. The stubs exist only to satisfy the `Record<FraudRuleType, ...>` type constraint.
📚 Learning: 2025-11-24T09:10:12.494Z
Learnt from: devkiran
Repo: dubinc/dub PR: 3089
File: apps/web/lib/api/fraud/fraud-rules-registry.ts:17-25
Timestamp: 2025-11-24T09:10:12.494Z
Learning: In apps/web/lib/api/fraud/fraud-rules-registry.ts, the fraud rules `partnerCrossProgramBan` and `partnerDuplicatePayoutMethod` intentionally have stub implementations that return `{ triggered: false }` because they are partner-scoped rules handled separately during partner application/onboarding flows (e.g., in detect-record-fraud-application.ts), rather than being evaluated per conversion event like other rules in the registry. The stubs exist only to satisfy the `Record<FraudRuleType, ...>` type constraint.
Applied to files:
apps/web/lib/api/fraud/detect-record-fraud-event.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
Summary by CodeRabbit
Bug Fixes
Changes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.