I heard the Messenger of Allah ﷺ say, "True dreams are from Allah, and disturbing dreams are from Satan. So when one of you sees something he dislikes, let him spit lightly to his left three times and seek refuge from its evil, and then it will not harm him."
حدثنا النفيلي قال سمعت زهيرا يقول سمعت يحيى بن سعيد يقول سمعت أبا سلمة يقول سمعت
سمعت رسول الله ﷺ يقول الرؤيا من الله والحلم من الشيطان فإذا رأى أحدكم شيئا يكرهه فلينفث عن يساره ثلاث مرات ثم ليتعوذ من شرها فإنها لا تضره
Bukhari narrated it in the Book of Dream Interpretation, chapter "Dreams Are from Allah," hadith no. 6984, from the hadith of Zuhayr, and Muslim narrated it in the Book of Dreams, hadith no. 2/2261, from the hadith of Yahya bin Saeed Ansari, with the same wording.