A UV filter can provide some level of protection for your Canon EF 50mm f/1.8 STM lens, but it is not sufficient to protect the lens in heavy rain. The lens itself lacks weather sealing and is primarily made of plastic, making it vulnerable to moisture ingress. While a UV filter can help prevent water from directly contacting the front element and offers some scratch protection, it does not make the lens waterproof or resistant to heavy rain conditions.
In heavy rain, the risk of water entering the lens through other openings or the body is significant, even with a UV filter in place. For adequate protection, consider using additional measures such as a rain cover, keeping the lens under a protective barrier when not in use, and avoiding prolonged exposure to wet conditions[3].
Citations:[1] https://www.amazon.com/49mm-Multi-Coated-Protective-Filter-Canon/dp/B0719QLBQP
[2] https://www.canonrumors.com/forum/threads/best-buy-mandatory-uv-filter-for-canon-ef-50mm-f-1-8-ii-camera-lens.20366/
[3] https://photo.stackexchange.com/questions/18090/how-resistant-is-the-canon-7d-50mm-f-1-8-ii-in-light-rain
[4] https://www.amazon.com/Ultraviolet-Multi-Coated-Glass-Protection-Filter/dp/B075Y7WK5Q
[5] https://6ave.com/products/canon-ef-50mm-f-1-8-stm-lens-uv-filter-cleaning-kit-base-bundle