If you want to be super safe, limit refrigerator storage to not much more than four days. The reason is the unlikely but potentially devastating situation in which botulinum bacteria were carried into the pesto via the raw herbs. Botulinum is soil borne so is a risk with all that grows in soil. It is a hazard, because it grows in an environment free of oxygen, which the oil provided. The toxin thrown off by the bacteria is lethal. Some refrigerators are not set cold enough to significantly retard growth.
The good news is that botulism is relatively rare, but it has occurred from such diverse causes a baked potatoes sealed in foil and kept at room temperature and prison hooch. (Remember that it's the toxin that's lethal, not the bacteria itself.)
Freezing is safe for long-term storage. When I make batches of pesto from a harvest of basil, I store it in individual serving-size freezer containers. But remember that it should still be thawed under refrigeration or quick-thawed, rather than being left for hours at room temperature.