RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
40.29k stars 10.46k forks source link

setAvatar throws error-avatar-invalid-url for a valid domain #33584

Open Caperious opened 2 hours ago

Caperious commented 2 hours ago

Description:

When setting a user avatar via url the api responds with status 400, with the error type error-avatar-invalid-url.

After investigation i have figured out this happens because of the regex in the function isValidDomain, as the regex consideres a combination of subdomain and a domain with a hypen as invalid

An example of url that is deemed invalid: https://www.american-giant.com/cdn/shop/t/788/assets/loading.svg

This would be considered valid https://american-giant.com/cdn/shop/t/788/assets/loading.svg https://www.americangiant.com/cdn/shop/t/788/assets/loading.svg

Expected behavior:

The expected behaviour is that the example url provided is considered valid.

Actual behavior:

The example url provided is conidered as an invalid url.

Server Setup Information:

Caperious commented 2 hours ago

A quick solution for this issue would be to also validate the second part of a domain regex. A proper solution would probably be, to properly validate the domains and subdomains.

Non working regex /^(?!-)(?!.*--)[A-Za-z0-9-]{1,63}(?<!-)\.?([A-Za-z]{2,63}\.?)*[A-Za-z]{2,63}$/

Working regex /^(?!-)(?!.*--)[A-Za-z0-9-]{1,63}(?<!-)\.?([A-Za-z0-9-]{2,63}\.?)*[A-Za-z]{2,63}$/