-
Notifications
You must be signed in to change notification settings - Fork 0
fix(dos-id): refresh the IdP avatar on every login instead of once #16
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 |
|---|---|---|
|
|
@@ -415,16 +415,13 @@ export const syncDosProfileAndOrgs = async ({ | |
| }); | ||
| } | ||
|
|
||
| // 2. Sync Avatar if URL is provided | ||
| // 2. Sync Avatar if URL is provided. The IdP avatar is the source of truth | ||
| // (same policy as the name above): refresh on every login so upstream | ||
| // avatar changes propagate - the old skip-if-exists guard froze the first | ||
| // avatar forever. A locally-uploaded avatar is only replaced when the IdP | ||
| // actually provides a URL; with no IdP avatar the local upload stays. | ||
| if (avatarUrl) { | ||
| const user = await prisma.user.findUnique({ | ||
| where: { id: userId }, | ||
| select: { avatarImageId: true }, | ||
| }); | ||
|
|
||
| if (!user?.avatarImageId) { | ||
| await syncUserAvatarFromUrl(userId, avatarUrl); | ||
| } | ||
| await syncUserAvatarFromUrl(userId, avatarUrl); | ||
|
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. 🔒 Security & Privacy | 🛡️ Detected with Advanced Tier | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect the URL validator and its redirect handling.
rg -n -C 8 '\bassertNotPrivateUrl\b' packages
# Inspect fetch configuration and redirect policies in the avatar-sync code.
rg -n -C 5 '\bfetch\s*\(|redirect\s*:' packages/lib/server-only/dos-idRepository: DOS/Crove-Sign Length of output: 27877 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- validator ---'
sed -n '1,180p' packages/lib/server-only/webhooks/assert-webhook-url.ts
printf '%s\n' '--- avatar helper ---'
sed -n '45,85p' packages/lib/server-only/dos-id/sync-dos-profile.ts
printf '%s\n' '--- requested call and diff summary ---'
git diff --stat c119235da406618167f2209edb24b1372fac04ba 4f36d65b0594e15159409445e522c310a9870daf -- packages/lib/server-only/dos-id/sync-dos-profile.ts
git diff --unified=8 c119235da406618167f2209edb24b1372fac04ba 4f36d65b0594e15159409445e522c310a9870daf -- packages/lib/server-only/dos-id/sync-dos-profile.ts | sed -n '1,180p'Repository: DOS/Crove-Sign Length of output: 6920 SSRF Reachability: External Reject redirects before downloading avatar URLs.
Reject avatar URL redirects const response = await fetch(avatarUrl, {
signal: AbortSignal.timeout(5000),
+ redirect: 'error',
});🤖 Prompt for AI Agents🔒 Security & Privacy | 🛡️ Detected with Advanced Tier | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: printf '%s\n' '--- PR diff ---'
git diff --unified=6 c119235da406618167f2209edb24b1372fac04ba 4f36d65b0594e15159409445e522c310a9870daf -- packages/lib/server-only/dos-id/sync-dos-profile.ts
printf '%s\n' '--- profile sync relevant lines ---'
git show 4f36d65b0594e15159409445e522c310a9870daf:packages/lib/server-only/dos-id/sync-dos-profile.ts | nl -ba | sed -n '365,445p'
printf '%s\n' '--- avatar function references ---'
rg -n -C 5 'syncUserAvatarFromUrl|arrayBuffer\(|avatarUrl|assertNotPrivateUrl|AbortSignal\.timeout|timeout' packages/lib/server-only/dos-id/sync-dos-profile.ts packages/lib/utils/images/avatar.ts packages/auth/server/lib/utils/handle-oauth-callback-url.tsRepository: DOS/Crove-Sign Length of output: 15955 🏁 Script executed: git show 4f36d65b0594e15159409445e522c310a9870daf:packages/lib/server-only/dos-id/sync-dos-profile.ts | nl -ba | sed -n '50,115p'Repository: DOS/Crove-Sign Length of output: 2499 Denial of Service Reachability: External Limit avatar response size while streaming. 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| // 3. JIT Provision Organizations from claims OR shared PostgreSQL DB fallback | ||
|
|
||
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.
Awaiting
syncUserAvatarFromUrlon every login introduces a potential performance bottleneck and reliability risk. The function performs an external network request (with a 5-second timeout) and a CPU-intensive image optimization step (optimiseAvatar) on every single login, even if the avatar hasn't changed.\n\nSince the avatar is non-critical for the login flow to succeed, consider running this asynchronously without blocking the login response. SincesyncUserAvatarFromUrlalready has internal error handling, it is safe to trigger withoutawait.