Am I subject to the CRA if I only contribute to an open source project?

No. Contributions to an open source codebase are explicitely not in scope of the CRA, as stated in Recital 18:

This Regulation does not apply to natural or legal persons who contribute with source code to products with digital elements qualifying as free and open-source software that are not under their responsibility.