I created my own forum system, and one feature of that system is that users can link images in their posts. To be clear, they can surround their image link with BBCode like this:
[img]https://www.example.com/someimg.jpg[/img]
I then use regex to format the output of their post that is sent from the database, turning it into HTML:
<img src="https://www.example.com/someimg.jpg" alt="user-img" />
I thought this was fine until I had to create a system to allow users to upload their own profile pictures, during which time I researched and implemented several security checks to help prevent malicious data from being sent via image uploads (check file types, change the image's submitted name before storing, don't allow direct access to these images, etc.). I also read this question which mentions some potential security issues regarding user-generated HTML, but is more about letting users directly edit HTML.
I know numerous websites, including Stack Overflow, that allow users to insert images into their posts/comments. What's stopping someone from uploading a tampered image to their own site and linking it on another site? What can I do to make my current method safer?