I was in a similar situation where I had an idea for a similar product the company I worked for was toying around but was not able to implement. In the end I quit, waited a few month and then implemented it, just to be sure.
There's an entire law about inventions made in your on and off time - the "Gesetz über Arbeitnehmererfindungen". It does cover inventions (patents or similar) that are related to your work, whether done during your work time or outside. (https://www.gesetze-im-internet.de/arbnerfg/__4.html)
The law stipulates compensation and there's a separate set of compensation guidelines that takes into account how related to your work this invention is.
An employer can even claim right of first buy for inventions that are unrelated to the employees work (freie Erfindung), if the employer is active in the area of business that the invention covers (see https://www.gesetze-im-internet.de/arbnerfg/__19.html)
Mind you, this is by law. Many employment contracts will only mention this in passing or not at all.
Now, most contributions to open source will not pass the bar to be an invention in the sense of the law. But if you come up with a novel solution for a hard problem, that might cross the boundaries.