1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00
unleash.unleash/src/lib/util/generateImageUrl.ts
Christopher Kolstad c60bca777f
feat: replace gravatar-url with inline function (#5128)
As #4475 says, MD5 is not available in secure places anymore. This PR
swaps out gravatar-url with an inline function using crypto:sha256 which
is FIPS-140-2 compliant. Since we only used this method for generating
avatar URLs the extra customization wasn't needed and we could hard code
the URL parameters.
 
fixes: Linear
https://linear.app/unleash/issue/SR-112/gh-support-swap-out-gravatar-url-lib
closes: #4475
2023-10-24 10:07:26 +02:00

18 lines
521 B
TypeScript

import { createHash } from 'crypto';
const base: string = 'https://gravatar.com/avatar';
export const generateImageUrl = (user: {
email?: string;
username?: string;
id?: number;
}): string => {
let ident = user.email || user.username || String(user.id);
if (ident.indexOf('@')) {
ident = ident.toLowerCase().trim();
} else {
ident = ident.trim();
}
const identHash = createHash('sha256').update(ident).digest('hex');
return `${base}/${identHash}?s=42&d=retro&r=g`;
};