We consider the impact of counterparty risk on the pricing of financial derivatives contracts on energy commodities. We model the counterparty credit risk exposure within the Heath-Jarrow-Morton framework (Heath et al. Econ J Econ Soc. 6: 77-105, 1992), allowing the counterparty credit spread curve to evolve according to its own volatility and to the correlation between the risk-free interest rate and the credit spread. We focus on the case in which the underlying swap contract is the spark spread. We evaluate the counterparty credit valuation adjustment (CVA) of the swap fair price. In doing so, we take into consideration all relevant correlations, namely the correlation between the electricity and natural gas return processes and between these and the credit spread. Finally, we show how in our framework CVA varies with electricity and natural gas price volatilities, with the volatility of the credit spread, and as a function of the correlation between the spark spread and the counterparty credit spread.