Ali said, "We did not record anything from the Messenger of Allah ﷺ except the Quran and what is in this document."He said, the Messenger of Allah ﷺ said, "Madinah is a sanctuary from Air to Thawr. Whoever introduces an innovation in it or shelters one who does, upon him is the curse of Allah, the angels, and all people. No compensation or ransom will be accepted from him.The protection granted by the Muslims is one, and the lowest of them may extend it. Whoever betrays a Muslim's pledge of protection, upon him is the curse of Allah, the angels, and all people. No compensation or ransom will be accepted from him.Whoever claims allegiance to people other than his own masters without their permission, upon him is the curse of Allah, the angels, and all people. No compensation or ransom will be accepted from him."
حدثنا محمد بن كثير أخبرنا سفيان عن الأعمش عن إبراهيم التيمي عن أبيه
ما كتبنا عن رسول الله ﷺ إلا القرآن وما في هذه الصحيفة قال قال رسول الله ﷺ المدينة حرام ما بين عائر إلى ثور فمن أحدث حدثا أو آوى محدثا فعليه لعنة الله والملائكة والناس أجمعين لا يقبل منه عدل ولا صرف وذمة المسلمين واحدة يسعى بها أدناهم فمن أخفر مسلما فعليه لعنة الله والملائكة والناس أجمعين لا يقبل منه عدل ولا صرف ومن والى قوما بغير إذن مواليه فعليه لعنة الله والملائكة والناس أجمعين لا يقبل منه عدل ولا صرف
Bukhari narrated it in Fadail Madinah, chapter on the sanctity of Madinah, hadith 1870, and Muslim in Hajj, etc., hadith 1370, from the hadith of Sufyan Thawri, with this wording.Chapter on the virtue of Madinah and the Prophet's ﷺ supplication for blessing upon it.