Is writing a research paper on Overleaf risky for plagiarism?
Overleaf is unlikely to be a problem
To plagiarize your work, someone would have to

find it very valuable
hack your Overleaf account (and know it is there they need to hack) or that of your coauthors or you would have to have shared it publicly
finish the research before you do, which typically means they would have to have superior or in any case solid knowledge in the field,
publish it before you do
have more credibility than you do in the academic community, so that you can't just say that it was actually your work they are plagiarizing

Of all these factors the second one is the only one that has anything to do with Overleaf. In order for it to be the crucial issue, you already need to have a competent and well-connected researcher out to plagiarize you. While it could happen, it feels unlikely, and you probably know if you are in this situation or not.
If you do happen to be in a position that requires extreme information security (governmental research, dual purpose research, authoritarian regime, a powerful enemy out to get you), then it is a good rule of thumb to not use Overleaf or other cloud services. But in this case you really should seek help that is a lot more competent and specific than the answers here.