Leakage from CO2 storage reservoirs is a threat towards safe and cost-efficient Carbon Capture and Storage (CCS), and active and abandoned wells have been identified as the most probable leakage paths. This underlines the importance of ensuring well integrity throughout the entire life-cycle of a well. CO2 is a reactive fluid, but its reactivity with well barriers such as rock and cement will depend on the other fluids present in the well. Both rock and cement are typically affected by drilling fluids before they are exposed to CO2 in a downhole situation. In the present study we investigate how the presence of drilling fluids affects the way rock and cement are influenced by CO2 exposure. This is done by performing a detailed X-ray tomography characterization of clean and mud-affected samples before/after they have been batch exposed to CO2. This revealed that the porosity of the samples was altered after CO2 exposure. For Saltwash North sandstone, the porosity at the edge and in the center of the sample was observed to decrease after CO2 exposure. For Castlegate sandstone, the porosity of the sample at the center was observed to increase, while the porosity at the edge was observed to decrease upon exposure to CO2. The cement sample with mud was observed to have a higher porosity than the pure cement sample.