Finland would have needed to consider this as a scenario and make contingency plans if early German success was enormous, but long term Allied success was still likely, and figure out how to backstab Hitler while keeping Finland safe from reprisal.
One could more or less say this was exactly what Finland did in 1942-44 IOTL. The Finnish leadership anticipated that the Soviets start rolling back the front by main force. They were preparing to jump ship as soon as Germany was weak/cornered enough not to turn Finland into a battlefield.
What Mannerheim et al. did not expect was that the USSR would try to hammer Finland into submission in the summer of 1944, before the main offensive against the Germans that would later be known as Bagration. One could well see that the Finnish leadership held too positive views about the possibility of escaping relatively unscathed. This is why the Finns declined the Soviet peace terms of April 1944 - 1940 borders, loss of Hanko or Petsamo, monetary reparations, expelling the German troops and demobilisation - as too punitive.
But the writing was on the wall: by the winter 1943-1944 Stalin felt the Soviet position was strong enough not to compromise with the Finns anymore. The most
lenient Soviet terms to be offered to Finland were already set in the Tehran Conference, and they were exactly those listed above.
But on the other hand, before mid-1944 Germany was too strong for Finland to try and detach itself from the alliance/co-belligerence with Hitler. In, say, late 1942 Finland might have managed to regain most of the land lost in 1940 - only to see the interior turned into a battleground between Finnish troops and Germans. In the worst case scenario, add various militias - and the Red Army.
Thus, I agree with my Finnish compatriots above - what Finland got IOTL was very likely the best it could realistically hope for.