Do not swear by anything other than Allah, for I heard the Messenger of Allah ﷺ say, "Whoever swears by other than Allah has committed disbelief or polytheism."
حدثنا قتيبة حدثنا أبو خالد الأحمر عن الحسن بن عبيد الله عن سعد بن عبيدة أن ابن عمر سمع رجلا يقول لا والكعبة
لا يحلف بغير الله فإني سمعت رسول الله ﷺ يقول من حلف بغير الله فقد كفر أو أشرك
Sourcing, its chain of transmission is sahih. Abu Dawud narrated it in the Book of Oaths and Vows, chapter on the dislike of swearing by fathers, hadith 3251, from the hadith of Hasan bin Ubaydullah with this wording. Ibn Hibban graded it sahih, hadith 1177, as did Hakim, 4/297, and Dhahabi. Saad bin Ubayda heard it from Ibn Umar, as found in Bayhaqi, 10/29, who also related it from Abu Abdul-Rahman Sulami, from him, with this wording. Both routes are preserved.