Context. Galactic cosmic rays are particles presumably accelerated in supernova remnant shocks that propagate in the interstellar medium up to the densest parts of molecular clouds, losing energy and their ionisation efficiency because of the presence of magnetic fields and collisions with molecular hydrogen. Recent observations hint at high levels of ionisation and at the presence of synchrotron emission in protostellar systems, which leads to an apparent contradiction. Aims. We want to explain the origin of these cosmic rays accelerated within young protostars as suggested by observations. Methods. Our modelling consists of a set of conditions that has to be satisfied in order to have an efficient cosmic-ray acceleration through diffusive shock acceleration. We analyse three main acceleration sites (shocks in accretion flows, along the jets, and on protostellar surfaces), then we follow the propagation of these particles through the protostellar system up to the hot spot region. Results. We find that jet shocks can be strong accelerators of cosmic-ray protons, which can be boosted up to relativistic energies. Other promising acceleration sites are protostellar surfaces, where shocks caused by impacting material during the collapse phase are strong enough to accelerate cosmic-ray protons. In contrast, accretion flow shocks are too weak to efficiently accelerate cosmic rays. Though cosmic-ray electrons are weakly accelerated, they can gain a strong boost to relativistic energies through re-acceleration in successive shocks. Conclusions. We suggest a mechanism able to accelerate both cosmic-ray protons and electrons through the diffusive shock acceleration mechanism, which can be used to explain the high ionisation rate and the synchrotron emission observed towards protostellar sources. The existence of an internal source of energetic particles can have a strong and unforeseen impact on the ionisation of the protostellar disc, on the star and planet formation processes, and on the formation of pre-biotic molecules.