Things Forbidden Because of the Danger they Pose
The Gemara (Niddah 17a) states in the name of Rabbi Shimon bar Yochai that if one does any one of five specific things, one takes his life into his own hands (meaning that one is endangering himself). One of these things is eating an egg, garlic, or onion that was left peeled all night.
We see from here that there is a prohibition to eat eggs, garlic, or onions that were left peeled overnight. The Poskim tell us that the reason why eating these foods left peeled overnight is dangerous is because an evil spirit which can cause much damage rests upon them.
The Evil Spirit Nowadays
Nevertheless, the Hagahot Mordechi (one of the great Rishonim) was asked to explain why people in those lands were not careful to abstain from eating eggs left peeled overnight, he writes that people are not careful about this because nowadays, there is no longer a harmful evil spirit present like there was during the era of the Talmud. Likewise, the great Maharshal (Hagaon Rabbeinu Shlomo Luria, one of the greatest Ashkenazi Poskim who lived approximately four-hundred years ago) writes that the warnings of our Sages regarding the Evil Spirit are no longer a concern, for the Evil Spirit is no longer present among us. Some Ashkenazi Poskim rely on the above ruling.
On the other hand, it seems from the words of the Tosafot (Shabbat 141a) that we must be concerned about our Sages’ warnings of the Evil Spirit even nowadays. (Although the Evil Spirit may not be as common as it was during the era of the Sages of the Talmud, it is nevertheless somewhat common nowadays as well.) We likewise find in the words of the Poskim that they were concerned with such warnings of our Sages in many places and they did not rely on the words of the Mordechi and Maharshal regarding this matter.
Maran Rabbeinu Ovadia Yosef zt”l rules in accordance with the opinion of the Tosafot and other Poskim who write that one must take care not to leave eggs, garlic, or onion peeled overnight, for an Evil Spirit rests upon them. However, if they were left peeled and the night has already passed, they are not forbidden for consumption, for one may rely on the opinion of the Mordechi and Maharshal. However, this should preferably not be done, as we have written.
There is a way to rule completely leniently regarding this matter which is if the peeled onion or garlic was mixed another food, such as in a salad or in a cooked food, for in this manner, no Evil Spirit rests on it whatsoever. The custom is indeed to rule leniently in this manner. Maran Rabbeinu zt”l indeed rules leniently on this matter.