How to deal with masks and shadowcatcher when compositing 3D elements over an image or video?
I didn't check a Mask option, but seems to me more natural to use an Object as a Mask and Shadow Catcher in once, so shadow follow the shape.

Alpha Over node seems to be working as expected.



Notes:

Image in my 3Dviewport is an Empty object for a reference it doesn't influence a render. For the same effect (and probably easier) you can use image as bacgroud for camera (Camera Properties &gt; Background Images) that can be video as well.
With Object ID pass or Cryptomatte you can separate shadow and adjust if needed.