If you're referring to GPL variants, that depends. You can absolutely use GPL software and libraries with closed source software. You just need to separate the GPL portions from the closed source portions with some sort of boundary, like running it as a service of some sort or turning it into a CLI tool. You're just not allowed to create derivative works of GPL software that isn't also GPL.
Also, there should be nothing dangerous about open sourcing code (unless you're referring to financial risk to the business I guess). Secrets should never live in code, and obscurity is never secure.