"So how do we guard against this type of attack?"
Don't allow access to your 'secret' source code from the open Internet.
Don't allow access to your 'secret' source code from the open Internet.
In comparison proprietary software companies are a single point of failure where customers can't access the source and have no means to verify what ghe binaries they get actually contain.