Hilchos Lashon Hara chapter 6, section 5
We wrote in paragraph 2 that even listening to lashon hara is a Torah prohibition. This is if one went to listen. But if one was with a group of people who began speaking lashon hara and one reckons that rebuking them will not help at all, it depends. If one can leave or stop one’s ears with one’s fingers it is a great mitzvah to do so as the sages say (Ketubos 5). But if one cannot leave and reckons that stopping one’s ears is also very difficult as the people will mock him and he will certainly not do this, he should at least strive not to believe the lashon hara.
This requires three conditions. a) He should firmly decide that he does not believe the denigration. b) He should not enjoy from the lashon hara. c) He should not make any movement that the speakers can interpret as agreement to the lashon hara but sit like a stone. If he can maintain an angry expression that shows he does not agree to their lashon hara it is even better.