The Messenger of Allah ﷺ said, "Whoever claims descent from someone other than his father, or attaches himself to people other than his own patrons, upon him is the curse of Allah, the angels, and all of humankind. Allah will accept from him no obligatory worship nor any voluntary deed on the Day of Resurrection."
قال رسول الله ﷺ: من ادعى إلى غير أبيه، أو انتمى إلى غير مواليه فعليه لعنة الله والملائكة والناس أجمعين. لا يقبل الله منه يوم القيامة صرفا ولا عدلا.
Bukhari narrated it in Hajj (1870), and Muslim in Hajj (1370), both from the hadith of Amash, from Ibrahim Taymi, from his father, who said, Ali bin Abu Talib addressed us and said, "Whoever claims that we have anything to recite besides the Book of Allah and this document" (he said, and it was a document hanging in the scabbard of his sword) "is lying. In it are the ages of camels, and matters concerning wounds, and in it the Prophet ﷺ said..." (then he mentioned the hadith). The wording is Muslim's, and Bukhari did not mention his saying, "Whoever claims descent from someone other than his father."