This work is devoted to the study of stability of horizontal filtration flow of a mixture through a closed porous domain taking into account impurity immobilization. The instability arises due to the vertical concentration difference of heavy impurities, which creates unstable density stratification. A general mathematical model describing the transport of an impurity through a porous medium is presented. The equations are simplified for the case of low impurity concentration. Simplification made it possible to analytically obtain the solution corresponding to homogeneous horizontal filtration and to study its stability. It is known that, in the narrow regions of porous medium and at weak intensities of the external flow, convection is excited in a monotonous manner. On the contrary, in the case of an infinite horizontal layer, oscillatory instability is observed. A study of the transition between the instability modes is presented. It is shown that the oscillatory regime is observed in long regions or at significant intensity of the external horizontal flow. At low flow intensities, convective cells do not move relative to the region and, hence, there is no reason for oscillations. It has been established that the range of flow intensity values, in which oscillations are observed, grows with increasing length of the domain. Impurity immobilization leads to the stabilization of horizontal filtration with respect to convective perturbations. Critical curves and stability maps are obtained in a wide range of problem parameters and then analyzed. For limiting cases, a comparison is made with the known results obtained for an infinite layer.