There is no salvation outside the Church. While Aquinas stressed the necessity of Church membership for entrance into eternal life, he also saw the possibility of people who where unable to be baptized into the faith, “who nonetheless had a desire either to be baptized or at least to be saved and were essentially willing to do whatever God wanted them to do for salvation.” But being taught a certain truth all their lives, they are unable to see the falsehood of that teaching. The possibility of salvation for those individuals was called by Aquinas to be through ‘baptism of desire’.
He says that such a one ‘can obtain salvation without being actually baptized, on account of the person’s desire for baptism, which desire is the outcome of faith that works through charity, whereby God, Whose power is not tied to visible sacraments, sanctifies a person inwardly’ (Summa Theologiae III, q.68, a.2).
God is not bound to the sacraments. He Who made sacraments is likewise free to bestow His grace in other ways.
Pope Pius IX making this most nuanced statement in Singulari Quadam: “It is known to Us and to you that those who labor in invincible ignorance concerning our most holy religion and who, assiduously observing the natural law and its precepts which God has inscribed in the hearts of all, and being ready to obey God, live an honest and upright life can, through the working of the divine light and grace, attain eternal life.”
And finally in Pope John Paul II’s encyclical Redemptoris Missio, our Vicar of Christ states also that: “Salvation in Christ is offered to all. The universality of salvation means that it is granted not only to those who explicitly believe in Christ and have entered the Church. Since salvation is offered to all, it must be made concretely available to all. But it is clear that today, as in the past, many people do not have an opportunity to come to know or accept the gospel revelation or to enter the Church…For such people salvation in Christ is accessible by virtue of grace, which, while having a mysterious relationship to the Church, does not make them formally part of the Church but enlightens them in a way which is accommodated to their spiritual and material situation. This grace comes from Christ…”
As you well know, a doctrine has growth as our understanding grows and deepens. Although early on our Church Fathers damned people to hell for not being baptized (ie visibly part of our Church), the line where someone can be part of the Church is found to include a much larger group of people than originally thought because Jesus Himself said that an individual will be judged by what he knows and not blame him for his honest ignorance (John 15:22). Some may not be formally part of it but still inside the Church.
Please read paragraphs 1260 and 1281 of the Cathechism of the Catholic Church for more info.