Indeed. Example:
In Germany you usually have some paragraphs on this in the (work) contract (there are a couple popular variations - there isn't much leeway provided by German law here, which is good). "We own everything you do" is definitely illegal in Germany, and also not put into work contracts (such a clause would be void anyway).
The legal construction is basically that the employee grants an exclusive, irrevocable license[1] to any IP produced by the employee for the employer. There is of course a grey zone here, but it's quite narrow, and directly non-existent if the side project is unrelated to the current core business of the employer.
FOSS contributions aren't really touched by this; you work on behalf of the employer to contribute to a FOSS project and the exact same terms and conditions apply as always (you put your name on it, not your employers; since exclusivity of the license implicitly granted to your employer conflicts with the FOSS terms, but the employer explicitly commissioned you to do that, the latter "wins" over the former, ie. the license of your employer to the diffs you write becomes non-exclusive in these cases, because the exclusivity is implicitly revoked by the work assignment, essentially action implying intention) -- or so it was explained to me).
[1] This also means that you retain your copyright: it's not possible to transfer copyright in Germany. Very rarely things like "Copyright (c) 1871-1918 Softwareschmiede GmbH" pop up in open sourced stuff, but it's obviously something stamped on when open sourcing, and equally obviously incorrect. The copyright still belongs to the developers involved in the project, but because the company "Softwareschmiede GmbH" has an exclusive license they can re-license it on their own accord under any terms they want. They'd still have to, technically, state the correct copyright, though.