Abdul-Rahman reported that the Messenger of Allah ﷺ said, "Allah the Exalted has pardoned my community for whatever crosses their minds, so long as they do not speak of it or act upon it."
أخبرنا إبراهيم بن الحسن وعبد الرحمن بن محمد بن سلام قالا حدثنا حجاج بن محمد عن ابن جريج عن عطاء
أن النبي ﷺ قال عبد الرحمن عن رسول الله ﷺ قال إن الله تعالى تجاوز عن أمتي كل شيء حدثت به أنفسها ما لم تكلم به أو تعمل
Grading, its chain of transmission is sahih. It is found in Sunan al-Kubra, hadith 5626, and Ibn Hibban graded it sahih, hadith 1498. The hadith has corroborating narrations in Bukhari, Muslim, and Hakim, 2/198, and others.