Castoreum, the type of vanilla flavoring known for having a musky, vanilla-like smell, does come from a beaver, but myths about it must be addressed.
To mark territory, beavers secrete castoreum through their castor sacs located between the tail and pelvis, not the anal glands.
The brown, syrupy flavoring has been used in food for nearly a century. The Food and Drug Administration and The Flavor and Extract Manufacturing Association consider it safe.
The chances of it being in mass-produced products or sweet treats are very low. The laborious harvesting process makes castoreum a high-end product with a niche audience.
Extracting castoreum involves anesthetizing beavers, so compared to vanilla beans, the US harvests only a minuscule amount of castoreum, making it unlikely to end up in your food.