Water mask control through DEM

I have a water mask binary image (water 1, non water 0).
I would like to create a link between DEM and water mask in the sense that I can get the DEM values for each corresponding water polygon through an automated python-based engine. In so doing, if some areas have been misclassified as water can be detected through its elevation difference threshold already set.

It’s kindda challenging. Any comment is truly appreciated.

Thanks