The Prophet ﷺ said, "Allah has pardoned my community for whatever crosses their minds, so long as they do not act upon it or speak of it."
عن النبي ﷺ قال: إن الله تجاوز عن أمتي ما حدثت به أنفسها ما لم تعمل أو تتكلم.
Bukhari narrated it in the Book of Divorce (5269), and Muslim in the Book of Faith (127), both by way of Hisham, who said, Qatada narrated to us, from Zurara bin Awfa, from Abu Hurairah, and he related it. The wording is Bukhari's, and Muslim did not present his own wording for this chain.