  We study the combined impact of magnetic mirroring and focusing on the
ionization by cosmic rays (CRs) in dense molecular clouds and circumstellar
disks. We show that for effective column densities of up to $\sim10^{25}$
cm$^{-2}$ (where ionization is the main mechanism of energy losses by CRs) the
two effects practically cancel each other out, provided the magnetic field
strength has a single peak along field lines. In this case the ionization rate
at a given location is controlled solely by attenuation of interstellar CRs due
to energy losses. The situation is very different in the presence of magnetic
pockets -- local minima of the field strength, where the CR density and thus
ionization can be reduced drastically. We obtain simple analytical expressions
allowing accurate calculation of the ionization rate in these regions.
