Cosmic rays accelerated by a shock form a streaming distribution of outgoing particles in the foreshock region. If the ambient fields are negligible compared to the shock and cosmic ray energetics, a stronger magnetic field can be generated in the shock upstream via the streaming (Weibel-type) instability. Here we develop a self-similar model of the foreshock region and calculate its structure, e.g., the magnetic field strength, its coherence scale, etc., as a function of the distance from the shock. Our model indicates that the entire foreshock region of thickness $sim R/(2Gamma_{rm sh}^2)$, being comparable to the shock radius in the late afterglow phase when $Gamma_{rm sh}sim1$, can be populated with large-scale and rather strong magnetic fields (of sub-gauss strengths with the coherence length of order $10^{17} {rm cm}$) compared to the typical interstellar medium magnetic fields. The presence of such fields in the foreshock region is important for high efficiency of Fermi acceleration at the shock. Radiation from accelerated electrons in the foreshock fields can constitute a separate emission region radiating in the UV/optical through radio band, depending on time and shock parameters. We also speculate that these fields being eventually transported into the shock downstream can greatly increase radiative efficiency of a gamma-ray burst afterglow shock.