The actual question I'm reading from this is "are components that I build myself more secure than those provided by a third party library?"
You should correct me if that's not what your asking.
The short answer is "probably not." You can and will introduce bugs and vulnerabilities into your own software.
The main downsides of third party libraries are that they can have dependencies that you may not know about and vulnerabilities in third party libraries mean that a given vulnerability is just as widespread as a the library that it exists in.
Most "bad actors" are opportunists so a specific vulnerability being wide spread tends to work in their favor by increasing opportunities.
That said, I wouldn't waste your time rewriting functionality that already exists in other libraries unless you have a very compelling reason for it.