The Catechism teaches that the Catholic Church is "the universal sacrament of salvation" (CCC 774–776), uniting God and humanity (CCC 780).
Some misunderstand this, thinking any church will do, while others believe only baptized Catholics can be saved. However, the Church Fathers and modern teaching agree that, while being Catholic is normally required for salvation (CCC 846), people outside the Church can be saved in certain cases, like through "baptism of desire" or "baptism of blood" (CCC 847).
Those who knowingly reject Church teachings or cause division must repent to be saved.
Here are examples of what early Christian writers taught about salvation outside the Church:
Ignatius of Antioch
“Be not deceived, my brethren: If anyone follows a maker of schism [i.e., is a schismatic], he does not inherit the kingdom of God; if anyone walks in strange doctrine [i.e., is a heretic], he has no part in the passion [of Christ]. Take care, then, to use one Eucharist, so that whatever you do, you do according to God: For there is one flesh of our Lord Jesus Christ, and one cup in the union of his blood; one altar, as there is one bishop, with the presbytery and my fellow servants, the deacons” (Letter to the Philadelphians 3:3–4:1 [A.D. 110]).
Justin Martyr
“We have been taught that Christ is the first-begotten of God, and we have declared him to be the Logos of which all mankind partakes [John 1:9]. Those, therefore, who lived according to reason [Greek, logos] were really Christians, even though they were thought to be atheists, such as, among the Greeks, Socrates, Heraclitus, and others like them. . . . Those who lived before Christ but did not live according to reason [logos] were wicked men, and enemies of Christ, and murderers of those who did live according to reason [logos], whereas those who lived then or who live now according to reason [logos] are Christians. Such as these can be confident and unafraid” (First Apology 46 [A.D. 151]).