In the U.S., the government's Food and Drug Administration (FDA) must approve any drug - whether it's prescription or over-the-counter - before it can be sold. The FDA evaluates the safety of a drug by looking at side effects, how it's manufactured, results of animal testing and clinical trials, and more. The FDA also monitors a drug's safety after approval.
For you, drug safety means buying online from only legitimate pharmacies and taking your medicines correctly.
References and abstracts from MEDLINE/PubMed (National Library of Medicine)