Suggest to repair at workshop. The usual keypoints and procedure of repair are:
1. Clean the dirts in sunroof railing to ensure smooth operation. Repair if necessary.
2. Activate the sunroof auto returning function.
3. Check the seal between the frame at the front and the rail. Replace the sunroof frame assembly if necessary.
4. Test the sunroof against rain water to ensure problem is resolved after repairing done.