As you can see from one of my previous answers, photons do not have a proper time, but you can use a λ affine parameter, that increases monotonically along the lightlike worldline.
https://physics.stackexchange.com/a/492332/132371
Now you are saying that a photon will travel faster in space then in a medium. In reality, photons always travel at speed c in vacuum, when measured locally.
Now when a photon enters a medium, it still travels in vacuum between the atoms/molecules, at speed c.
It is the wavefront of the whole EM wave, that is built up by a herd of photons in a coherent way, that slows down in the medium, due to the interactions of the individual photons with the atoms/molecules in the media. That interaction takes time.
The simplest picture is that light always travels at the speed of light. But in a material it travels at the speed of light until it hits an atom. It is then absorbed and re-emitted in the same direction, which takes a small amount of time.
The more this happens, the slower the effective average speed.
The denser the material, the more atoms there are in the way.
https://physics.stackexchange.com/a/105574/132371
As the medium gets denser, the number of interactions will be more, it will take more time from the individual photons and the wavefront will slow down more.
https://physics.stackexchange.com/a/395608/132371