Context. Hydrogen chloride (HCl) and hydrogen fluoride (HF) are expected to be the main reservoirs of fluorine and chlorine over a wide range of conditions, wherever hydrogen is predominantly molecular. They are found to be strongly depleted in dense molecular clouds, suggesting freeze-out onto grains in such cold environments. We can then expect that HCl and HF were also the major carriers of Cl and F in the gas and icy phases of the outer solar nebula, and were incorporated into comets. Aims. We aimed to measure the HCl and HF abundances in cometary ices as they can provide insights on the halogen chemistry in the early solar nebula. Methods. We searched for the J(1−0) lines of HCl and HF at 626 and 1232 GHz, respectively, using the Heterodyne Instrument for the Far-Infrared (HIFI) onboard the Herschel Space Observatory. HCl was searched for in comets 103P/Hartley 2 and C/2009 P1 (Garradd), whereas observations of HF were conducted in comet C/2009 P1 (Garradd). In addition, observations of H 2 O and H 2 18 O lines were performed in C/2009 P1 (Garradd) to measure the H 2 O production rate at the time of the HCl and HF observations. Three lines of CH 3 OH were serendipitously observed in the HCl receiver setting. Results. HCl is not detected, whereas a marginal (3.6-σ) detection of HF is obtained. The upper limits for the HCl abundance relative to water are 0.011% and 0.022%, for comet 103P/Hartley 2 and C/2009 P1 (Garradd), respectively, showing that HCl is depleted with respect to the solar Cl/O abundance by a factor more than 6 +6 −3 in 103P/Hartley 2, where the error is related to the uncertainty in the chlorine solar abundance. The marginal HF detection obtained in C/2009 P1 (Garradd) corresponds to an HF abundance relative to water of (1.8 ± 0.5) × 10 −4 , which is approximately consistent with a solar photospheric F/O abundance. The inferred water production rate in comet C/2009 P1 (Garradd) is (1.1±0.3)×10 29 s −1 and (0.75±0.05)×10 29 s −1 on 17 and 23 February 2012, respectively. CH 3 OH abundances relative to water are 2.7 ± 0.3% and 3.4 ± 0.6%, for comets 103P/Hartley 2 and C/2009 P1 (Garradd), respectively. Conclusions. The observed depletion of HCl suggests that HCl was not the main reservoir of chlorine in the regions of the solar nebula where these comets formed. HF was possibly the main fluorine compound in the gas phase of the outer solar nebula. However, this needs to be confirmed by future measurements.