I am working to tighten my 1920s house. With respect to junction boxes (receptacles and switches) the common approach seems to be sealing the gap between the box and the wall with spray foam and/or caulking and optionally adding a gasket.
However, there are still holes into the junction box: Knockout through which the cables enter and other small holes. Various sources explicitly say not to put spray foam into junction boxes. But since there is still a small gap between a switch paddle and the case as well as receptacles (even if only the holes) I don't understand what's the point.
Is it really not necessary to seal the gaps/knockouts in a junction box itself? If no, why not? If yes, how? Is a bit of spray foam permissible? For example a bit spray around the gaps and where romex wires enter the box?
To clarify, I mean all the gaps and small holes in the junction box itself. They are far from airtight. As an example, this is a metal junction box in my attic (but plastic boxes have the integrated clamps that let air through):
Of course, the extreme is a low voltage ring because that goes straight into the wall cavity. This shows an example of a low voltage ring (installed CAT6 cabling) next to a receptacle:
What is the right way to seal these?


