There's definitely an element of learning mindfulness that's key too. Learning to accept the uncertainty of random "terrible" thoughts that pop into your head, learning to not engage with them and letting them pass, etc.
I recommend two books: The Imp of the Mind by Dr. Lee Baer [2] and The Mindfulness Workbook for OCD by Jon Hershfield and Tom Corboy [3]
[1] https://iocdf.org/about-ocd/treatment/erp/
[2] https://www.amazon.com/Imp-Mind-Exploring-Epidemic-Obsessive...
[3] https://www.amazon.com/Mindfulness-Workbook-OCD-Overcoming-C...