You can avoid the issues with cookie dough in a few ways. First of all, make sure you use the freshest eggs possible when you make your cookie dough. You should always be using the freshest ingredients you have on hand, but with eggs, you will have less risk of disease if you use fresh ones. There are no significant studies to prove this, but in general, you may feel a little less risky if you use locally sourced, organic eggs. The main reason for this is that humanely raised chickens are less likely to have come into contact with contaminants that may cause disease for you. However, as no studies have proven this, you can just focus on getting the freshest ones that are available to you. Many bakers also claim taste improvements when fresher ingredients are used, so your cookies will be as yummy as possible!
You can also always enjoy cookie dough and cookies without eggs in them. The most common substitutes for eggs in cookies are oils, flax seeds, and fruits like applesauce. This can help your cookie dough last longer, as well as the added bonus of being vegan, and make your dough safe to consume. However, you need to pay attention to the expiration dates of these items, as some of them do go bad as well. These substitutes can also provide additional flavor profiles to your cookies, especially in the case of the fruits, so make sure the recipe you are making can handle the substitute flavors, and that you look up more specific articles on how to properly substitute these items for eggs. Otherwise, you can risk throwing off the entire batter (and no one wants a wasted batch of cookies!).