-
Notifications
You must be signed in to change notification settings - Fork 43
Br/add referral get route #697
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
Conversation
|
🚅 Deployed to the echo-pr-697 environment in echo
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
| return false; | ||
| } | ||
|
|
||
| // Validate the referral code exists |
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.
The setAppMembershipReferrer function doesn't validate whether a referral code has expired, allowing expired codes to be applied to memberships.
View Details
📝 Patch Details
diff --git a/packages/app/control/src/services/db/apps/membership.ts b/packages/app/control/src/services/db/apps/membership.ts
index 192c1992..2db42c68 100644
--- a/packages/app/control/src/services/db/apps/membership.ts
+++ b/packages/app/control/src/services/db/apps/membership.ts
@@ -186,14 +186,14 @@ export async function setAppMembershipReferrer(
return false;
}
- // Validate the referral code exists
+ // Validate the referral code exists and hasn't expired
const referralCode = await db.referralCode.findUnique({
where: {
code,
},
});
- if (!referralCode) {
+ if (!referralCode || referralCode.expiresAt < new Date()) {
return false;
}
Analysis
Missing expiration validation in setAppMembershipReferrer allows expired referral codes to be applied
What fails: The setAppMembershipReferrer() function in packages/app/control/src/services/db/apps/membership.ts does not validate whether a referral code has expired before applying it to a membership.
How to reproduce:
- Create a referral code with an
expiresAtdate in the past (code schema supports this via optionalexpiresAtparameter, defaulting to 1 year in future) - Call
setAppMembershipReferrer(userId, echoAppId, expiredCode) - The function returns
trueand applies the expired code to the membership
Result: Expired referral codes are accepted and applied. The function succeeds even when referralCode.expiresAt < new Date().
Expected: Function should return false for expired codes, matching the pattern used in other similar functions and the error message which states codes "may be invalid, expired, or you may already have a referrer for this app"
Verification: The same expiration validation pattern is correctly implemented in:
getCreditGrantCode()inpackages/app/control/src/services/db/credits/grant.ts- usesexpiresAt: { gt: new Date() }in WHERE clausefindRefreshToken()inpackages/app/control/src/services/db/auth/refresh.ts- usesexpiresAt: { gt: new Date() }in WHERE clause
The fix adds the missing expiration check: if (!referralCode || referralCode.expiresAt < new Date())
No description provided.