  Context. Transmission spectroscopy is one of the most powerful techniques to
characterize transiting exoplanets since it allows to measure the abundance of
the atomic and molecular species in the planetary atmosphere. However, the
stellar lines can bias the determination of such abundances if their
center-to-limb variations (CLVs) are not properly accounted for.
  Aims. This paper aims to show that three-dimensional (3D) radiation
hydrodynamic models and non-local thermodynamic equilibrium (non-LTE) line
formation are required for an accurate modeling of the stellar CLV of the Na I
D$_1$ and K I resonance lines on transmission spectra.
  Methods. We model the CLV of the Na I D$_1$ and K I resonance lines in the
Sun with 3D non-LTE radiative transfer. The synthetic spectra are compared to
solar observations with high spatial and spectral resolution, including new
data collected with the CRISP instrument at the Swedish 1-m Solar Telescope
between $\mu=0.1$ and $\mu=1.0$.
  Results. Our 3D non-LTE modeling of the Na I D$_1$ resonance line at 5896
{\AA} and the K I 7699 {\AA} resonance line in the Sun is in good agreement
with the observed CLV in the solar spectrum. The simulated CLV curve for a
Jupiter-Sun system inferred with a 3D non-LTE analysis shows significant
differences from that obtained from a 1D atmosphere. The latter tends to
overestimate the amplitude of the transmission curve by a factor that is of the
same order of magnitude as a planetary absorption depth (up to 0.2 %).
  Conclusions. In order to correctly characterize exoplanetary atmospheres, 3D
non-LTE synthetic spectra should be used to estimate the stellar CLV effect in
transmission spectra of solar-like planet hosts. The work will be extended to
other lines and FGK-type stars, allowing synthetic high-resolution spectra to
mitigate the stellar contamination of low-resolution planetary spectra, e.g.
those from JWST.
