This Halacha is an excerpt from our Sefer
Spitting by Aleinu:
No doubt, one of the more peculiar customs, attributed to Chabad Chassidim, is the act of spitting that we perform during Aleinu. Many are not aware that this spitting is actually not an original Chabad custom, and is recorded in previous Poskim that lived over a century prior to the start of the Chassidic movement [as brought in the footnotes here]. For some reason, this custom of Jewry has been preserved mainly by Chabad Chassidim. Details associated with this custom include when one is to perform this spitting, and how it may be performed in a Shul. Must one rub the spit during Aleinu and may one rub the spit on Shabbos?
The custom: It is customary to spit prior to saying the words “ואנחנו כורעים”. Doing so does not pose any Halachic issues and is considered an act of respect of heaven. [However, some Poskim protest against this spitting. Practically, the Chabad custom is to spit after saying the words “שהם משתחוים להבל ולריק” and so is the custom of some Gedolei Yisrael. However, majority of Jewry is no longer accustomed to perform this spitting.]
Rubbing the spit into the ground: It is permitted to spit in a Shul, so long as one rubs the spit with his feet in order so the saliva does not remain visible in the Shul. [Thus, when spitting in Shul during Aleinu, one is to rub the spit with his shoe in order so it does not remain visible. If, however, one is Davening outside of a Shul, there is no need to rub the spit during Aleinu, unless one spits into a public area. It is permitted to rub the spit on the tiled floor of a Shul even on Shabbos, as will be explained next.]
Spitting on Shabbos: When spitting on Shabbos during Aleinu, it is permitted to rub the saliva as he usually does during the week, if one is spitting on a tiled floor. [Those who desire to be stringent must at least step on the saliva until it disappears.] It is, however, forbidden to rub the saliva when spitting on an earth floor, and one is rather to simply step on it until it disappears.
Women spitting: It is not customary for women to spit during Aleinu.
Spitting in front of others: Spitting in front of other people is considered a repulsive act, and hence when one spits during Aleinu [or during any other time that one feels necessary], one is to do so discreetly.
 Taz Yoreh Deah 179:5; Ketzos Hashulchan 24:11; Hayom Yom 9th Teves
 The Taz ibid does not mention how widespread this custom was in his time, and simply mentions it as the custom. The Shelah Hakadosh [brought below] however mentions that it is customary amongst only “some of the people”.
 The reason: This is done to show our disgust of the idols of the gentiles and our respect for Heaven. It therefore does not fall under the severe prohibition against spitting prior to saying a verse, which makes one lose his portion in the world to come [See Michaber Yoreh Deah 179:8], as everyone knows that here the spitting is being done as an act of respect towards Hashem. [Taz ibid] Alternatively, the reason behind this spitting is because we do not desire to receive benefit from the saliva that stated the words “And they bow to deities.” [Hayom Yom 9th Teves]
 Taz ibid brought in previous footnote
 Shelah Hakadosh in Emek Habracha Tefila 40
 The reason: As they spit while saying the words “Veanachnu Korim” and doing so is a grave prohibition. Likewise, the form of idolatry that existed in the times of Yehoshua is no longer around today. Furthermore, doing so is a danger for the public and breeds anti-Semitism. [ibid]
 Hayom Yom 9th Teves
 See Piskeiy Teshuvos 132:8 footnote 38
 Admur 90:14; Michaber 90:13 and 151:7; Brachos 62b
 See Ketzos Hashulchan 146:63 “If one spit in the street in an area that people pass by one is obligated to rub on the spit with his foot until the spit disappears, as certainly one who spits in an area that people will pass is included in the above statement of the Gemara, and hence one must be very careful in this matter.”
 Ketzos Hashulchan 146:65; Az Nidbaru 6:24; Piskeiy Teshuvos 316:7; See also 337 Biur Halacha “Veyeish Machmirim”
 The reason: Being that today majority of houses are tiled, and thus according to all the decree against tiled floors does not apply. [ibid]
 Olas Tamid 151:8; Elya Raba 151:12; P”M 151 A”A 9; Kaf Hachaim 151:49
 Michaber 316:11; Shabbos 121b; Olas Tamid 151:8; Elya Raba 151:12; P”M 151 A”A 9; Kaf Hachaim 151:49; However some Poskim rule that if majority of the city houses have tiled floors [as opposed to earth floors], it is permitted to rub saliva on a public earth floor, such as on a dirt road, so long as one does not intend to smoothen the gaps. However, by a dirt floor which one owns it remains forbidden to rub in the saliva according to all. [Ketzos Hashulchan 146 footnote 63-13]
 The reason: Seemingly this is due to reasons of modesty and female nature, as Kol Kevuda Bas Melech Penima. Perhaps this also explains why women are not accustomed to bow on the ground during Aleinu Leshabeiach which is said during the High Holidays.
 Michaber Yoreh Deah 282:1; Tur in name of Rambam
 I have not found any source in the Poskim for forbidding to spit when facing the Aron, and on the contrary, from the fact the Poskim ibid who allow spitting in a Shul do not state that it is forbidden to do so opposite the Aron implies that such a prohibition does not exist. Vetzaruch Iyun.
 See Michaber 316:11 “It is permitted being that the saliva is repulsive” However see M”A 316:25 “Today people are no longer particular regarding spit”; Chagiga 5a “On all the acts Hashem will bring to judgment, on all concealed matters, Shmuel says that this verse refers to one who spits in front of his friend and it became repulsive before him”; See Ketzos Hashulchan 146:63 “If one spit in the street in an area that people pass by one is obligated to rub on the spit with his foot until the spit disappears, as certainly one who spits in an area that people will pass is included in the above statement of the Gemara, and hence one must be very careful in this matter.”