I would really suggest against it. I am certainly no authority on current body work practices, though all my experience has lead me to find that foam and its many "pores" or basically all the tiny bubbles that make up a foam of any type, will have the potential to hold moisture.
There are of course "closed cell" foams, that are literally what the name implies. All the bubbles are closed and there are no passages from bubble to bubble. I would assume at the very least that it is a closed cell "structural foam" that is on the market.
However... As someone who has fixed many-a-rust-repairs, as well as the quarters on my little Valiant, I would say just repair it with sheet metal, drown it with Ospho, and leave the area accessible for future treatment.
Two things on that note. It took many years for the rot to become an issue, and most likely that was when the car was driven daily in who knows what kinda of weather. If the repair is done well, and then treated correctly with a sealer and rust inhibitor, it will last longer than it ever did the first time.
I cant take credit for this idea, however I have certainly used it and will again.
I used Ospho (a rust inhibitor / converter) and used it in two ways.
1. I poured it into the 1/4 panel at the rear most part and let it saturate the seam weld. It then poured out into a paint pan, and I continuously repeated the process for a few days, letting the 1/4 drip and dry.
Ospho easily has the same viscosity of water possibly less. It literally penetrates and saturates deep into all the seam and converts and stops the rust.
2. I put Ospho in a spray bottle and sprayed the entire inside of the 1/4. I sprayed the areas with under coat as well. Seems pointless, but in a few spots I noticed where the opsho must have found some rust as it discolored a few tiny spots as it did when it reacts with rust and bare metal.
Again, my take is to stay away from foam in the areas that have a great potential for moisture. Not to mention.... I have done the "foam repair" when I was in HS.... It turned out to be the major contributor to the repair being needed years later. It had actually trapped moisture. Granted..... It was the foam in a can "Great Stuff" and was NOT intended for the use I did! Hahaha
Sorry for the long winded answer.