A quasi-symmetry of an action $S$ is a transformation of the fields that leaves the action invariant up to a boundary term (see e.g. the answer to this question). In contrast, let us call a transformation of the fields that leaves the action invariant without producing a boundary term a strict symmetry. Under which conditions is it possible to convert a quasi-symmetry into a strict symmetry of an action by the addition of boundary terms?
As an example consider the following action: $$ S=-\frac{1}{2}\int dt \left(\frac{f''(t)}{f'(t)}\right)^2 \,. $$ This action is invariant under the transformation $\delta_{\epsilon}f=\epsilon_1+\epsilon_2 f+\epsilon_3 f^2$ up to a boundary term $$ \delta_\epsilon S=\epsilon_3 \int dt f''(t)\,,$$ so that the transformation is a quasi-symmetry. However, adding the boundary term $\frac{d}{dt}\left(\frac{f''(t)}{f'(t)}\right)$ to the action which subsequently reads $$ S=\int dt \left(\frac{f'''}{f'}-\frac{3}{2}\left(\frac{f''(t)}{f'(t)}\right)^2\right)$$ the action is invariant under the symmetry without an additional boundary term so that the transformation comprises a strict symmetry.
Under which condition does this work in general?