Most likely, the taste you are referring to is oxalic acid, which has a bitter/astringent taste and is found in many green vegetables including spinach, Brussels sprouts, green beans, collard greens, etc.
Herbs such as basil don't contain a lot of oxalic acid, and I can't say I've ever noticed it there, but they do have some.
One important thing to note is, cooking green vegetables and herbs in water (i.e. boiling them) is a very effective way of removing the oxalic acid - but the most important part of that process is removing the vegetables afterward. If they're canned, or added raw to a sauce, then the oxalic acid is just going to stew.
Dried herbs likely contain lower oxalic acid content because it's been evaporated away along with the water.
If you're only finding this taste in leafy greens (and not green beans, green peppers, broccoli, etc.) then it's also possible that you're tasting iron. It tastes like... well, metal. Some of the foods highest in iron include shellfish and seeds (pumpkin, sesame, etc.). So if you're finding a similar taste in those, even just a hint of it, it may be the high iron that you find "nasty".