My post regarding cavity wax contains a link to 3M's site where you can view the rust preventative. Any foams would be sealed off by this. The cavity wax is applied by inserting a long wand into the openings and pulling the trigger while you pull the wand back out.. it has a 360 degree spray pattern so nothing gets missed, and if you don't want to take a chance, do a quick second coat. The cavity wax is somewhat like Carwell products and Fluid film, apart from a few things.. Its not a yearly maintainence item, and unlike fluid film it's nonflammable.. whereas fluid film is a 4 on the flammability scale, and I just can't bring myself to coat the inside and underneath of my car with anything that's a risk for ignition from static discharge. Let alone ignition from a spark if something metal breaks, or you bottom out a skid plate or so on..
The fact that you only have to do it once is a big factor in my book.. even proper application of preventatives such as POR-15 and rustoleum rust fighters can't end up being temporary bandaids in high salt areas.
Vehicle makers already fill many rails with structural foams for added strength and crash predictability.
These foams are closed cell and will not absorb moisture.
Only open cell foams, such as sound deadeners, would trap moisture.