It’s an old stack. Can you suggest an alternative self hosted option?
What you instead want is a whitelist: Only allow properly formatted images and videos and ruthlessly reject anything else. I wrote about how I implemented this for my service in another response.