In presence of a static pair of sources, the spectrum of low-lying states of whatever confining gauge theory in D space-time dimensions is described, at large source separations, by an effective string theory. In the far infrared the latter flows, in the static gauge, to a two-dimensional massless free-field theory. It is known that the Lorentz invariance of the gauge theory fixes uniquely the first few subleading corrections of this free-field limit. We point out that the first allowed correction -a quartic polynomial in the field derivatives -is exactly the composite field TT , built with the chiral components, T andT , of the energy-momentum tensor. This irrelevant perturbation is quantum integrable and yields, through the thermodynamic Bethe Ansatz (TBA), the energy levels of the string which exactly coincide with the Nambu-Goto spectrum. We obtain this way the results recently found by Dubovsky, Flauger and Gorbenko. This procedure easily generalizes to any two-dimensional CFT. It is known that the leading deviation of the Nambu-Goto spectrum comes from the boundary terms of the string action. We solve the TBA equations on an infinite strip, identify the relevant boundary parameter and verify that it modifies the string spectrum as expected.