Something to consider
Expanding foam products for construction come in many variations and some are open cell while other are closed cell

Both open and closed can get water logged, but closed cell takes much longer to soak in water
All foams once water logged cannot be dried out and must be cut out, my dad had a old panel van that was foam insulated and the foam didn’t stop condensation from penetrating the foam to the back side of the metal body and this lead to massive rusting out of the whole vehicle in a decade.

Since this foam would be acting like it’s own vapor barrier I would only consider a closed cell type for in a car

All the single can foam products are open cell
You need a kit that mixes two products in the nozzle to get closed cell foams
They are highly exothermic but spraying in metal you should be fine.
-s