Right. I think the best solution is for coding to become a Profession, in the same way that Law, Engineering, and Accounting are in many countries.
In most places, every Lawyer has to follow the same code of ethics and can refuse to do anything that violates that code without fear of retribution.
I think the ACM is the closest thing we have to that so far.
The people behind the ACM’s code of ethics, recently did an AMA on reddit, which makes for a compelling read, if you are interested.