A card that blocks people from buying provinces or colonies would be overpowered
How about this.... OBSTRUCTIONIST: "while this is in your hand, you may prevent all players from buying cards of your choice except for province and colony. If you select province or colony, players who purchase them must take a curse."
This is phrased very poorly. As worded, that means that while I have Obstructionist in my hand, you cannot buy anything except for Province or Colony. It doesn't specify a limit. You probably want something more like this:
Obstructionist
Reaction
At the start of a player's turn, you may reveal this from your hand and set it aside. If you did, choose one kingdom card. That card may not be gained this turn. Return this card to your hand at the end of the player's turn.
This isn't perfectly worded, but it seems close to your intention. You need the set aside wording because otherwise you are allowed to reveal the same reaction over and over again. Another possible implementation of this idea might be to make it a Duration.
There are multiple problems with this card. It is political -- you can ban something critical for one player but inconsequential for another. If you have multiples, you can shut down other players. This is even worse with more than two players, as multiple opponents could do this to ban multiple cards.
It doesn't even solve the problem you are complaining about. You ban Wharf but on this particular turn I draw my best stuff and can afford a Colony. On the next turn, I have just enough to buy Wharf but you no longer have Obstructionist in hand. Meanwhile, I happen to have Obstructionist in hand and ban Wharf when you plan to buy it. Or maybe you have the means to end the game with a win but I have Obstructionist and prevent you from 3-piling. On my turn I do the same thing as you and can win the game on piles, but you were unlucky and didn't have Obstructionist in hand that time. Basically, this "defense" just makes the whole game swingier.
This is even more luck-based than before Obstructionist was a thing.