A risk is a potential danger that arises because of your own actions. That is, you take on risk or engage in risky behavior.
A threat is a potential danger that arises from external circumstances. That is, you can be under threat or be in a threatening situation.
In your examples, the "threat of attack" is from external aggressors, whereas the "risk of hydrocarbon pollution" is generally due to the actions of the local population.
This difference is most clear-cut when you're talking about business or finance:
Our investment strategy is high-risk, high-reward. [because of our choice of investments]
A rising US dollar poses a threat to our profit margins in Asia. [because of economic factors outside of our control]
Sometimes you will hear risk used for situations that seem to be completely based on external circumstances, particularly with weather:
There is a risk of afternoon thunderstorms.
But even then, the implicit context is that if you choose to do something outdoors this afternoon, you will risk getting rained on.