auth0 / cosmos

🔭 Auth0 Design System
https://auth0-cosmos.now.sh/
MIT License
545 stars 114 forks source link

DXDP-1904 - Fixing Avatar component infinite loop when image not provided and gravatar fails to load #1733

Closed cristiandouce closed 3 years ago

cristiandouce commented 3 years ago

Description

We've identified an infinite loop in the Avatar component for when the image prop is not provided. In combination with bad initials or email props that end up failing to load, the following line get's HIT:

https://github.com/auth0/cosmos/blob/f96aaee5d6586a71d05c7a80b3cc2c003a4802eb/core/components/atoms/avatar/avatar.tsx#L143

You can notice that there is no handled case for when the Gravatar source has failed to load (except for the one in combination with image errors). This combination of events start an infinite loop of Line 143 being constantly hit, running several requests per second attempting indefinitely to load Gravatar again and again.

Motivation and Context

This is a bug which can cause systems to exhaust or block the user due to the excess of requests produced by the infinite loop.

How has this been tested?

There are stories in the storybook that reproduced the issue, now fixed!

vercel[bot] commented 3 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/auth0-design/cosmos/5dic38ifp
✅ Preview: https://cosmos-git-dxdp-1904-fix-infinite-loop.auth0-design.now.sh