Raw flour and raw eggs can carry bacteria.
Most people worry about the raw eggs in cookie dough, and they're one risk: eggs can carry Salmonella. But raw flour is a hazard too. Flour is a raw agricultural product. Wheat grows in fields where animals roam, and milling doesn't kill bacteria. Outbreaks of E. coli in the United States have been traced to raw flour, leading to large recalls.
Baking kills these bacteria, which is why cookies are safe and the dough isn't. The CDC and FDA advise against eating raw dough or batter, including for cakes, brownies and homemade play dough.
If you love cookie dough, there are safer ways. Store-bought "edible" cookie dough is made with heat-treated flour and no raw eggs. At home, you can heat-treat flour by baking it at around 350°F (175°C) for several minutes or microwaving it in short bursts until it reaches 165°F (74°C), then use pasteurized eggs or skip eggs entirely.