-
Notifications
You must be signed in to change notification settings - Fork 46
Sanitize affiliate tracking code prefixes #463
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,12 +19,17 @@ async function getAttributionWindowStart(admin: SupabaseClient, offerId: string) | |
| */ | ||
| export function generateTrackingCode(username: string, offerSlug: string): string { | ||
| const base = `${username}-${offerSlug}`; | ||
| const prefix = username | ||
| .toLowerCase() | ||
| .replace(/[^a-z0-9]+/g, "-") | ||
| .replace(/^-+|-+$/g, "") | ||
| .slice(0, 48) || "affiliate"; | ||
|
Comment on lines
+22
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The dash-trim ( |
||
| const hash = crypto | ||
| .createHash("sha256") | ||
| .update(base + Date.now()) | ||
| .digest("hex") | ||
| .slice(0, 6); | ||
| return `${username}-${hash}`; | ||
| return `${prefix}-${hash}`; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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
basevariable (used as the hash seed) still embeds the rawusername, but the prefix returned in the tracking code is now the sanitized form. This means the human-readable portion of the code (prefix) no longer matches the entropy source (base). For usernames that sanitize to"affiliate"(the fallback), all such usernames share the same prefix but generate hashes from their distinct raw values — so codes are still unique. The disconnect is harmless today, but ifbasewere ever used to reverse-lookup or validate the prefix this divergence would be surprising. Consider usingprefix(or a normalized form) as the base instead of the raw username.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!