We consider the inverse source problem of determining a source term depending on both time and space variables for fractional and classical diffusion equations in a cylindrical domain from boundary measurements. With suitable boundary conditions, we prove that some class of source terms which are independent of one space direction can be reconstructed from boundary measurements. Actually, we prove that this inverse problem is well-posed. We also establish some results of Lipschitz stability for the recovery of source terms which we apply to the stable recovery of time-dependent coefficients. © 2019 IOP Publishing Ltd.