In this work, polyaniline-cellulose nanofiber (PANI-CNF) nanocomposites were prepared by in-situ polymerization of aniline on 2,2,6,6-tetramethyl-1-piperidinyloxy (TEMPO) oxidized CNFs. Fourier transform infrared spectroscopy and transmission electron microscope demonstrate the successful polymerization of aniline on CNFs. The PANI-CNF nanocomposites were added as nanofillers to waterborne epoxy resin (WER) in different proportions. The composite coatings with different contents of PANI-CNFs were prepared by fabricating the mixture on the Q235 steel sheets. The corrosion resistance of different coatings was evaluated by potentiodynamic polarization and electrochemical impedance spectroscopy. The results confirmed that composite coatings containing 0.5% PANI-CNF exhibit the optimum anticorrosion behaviors and best corrosion resistance, which shows the lowest corrosion current density (1.788 Â 10 À7 A/cm À2 ) and highest corrosion potential (À0.458 V). In addition, PANI-CNF can significantly enhance the anticorrosion performance of WER coatings and maintain a high value even after 40 days of immersion in NaCl solutions. The above performances are attributed to the synergistic effect of the barrier effects and the passivation mechanism. Therefore, the bio-based composite materials developed in this work are promising in enhancing the corrosion protection of mild steel, which is essential for the sustainable development of waterborne coatings.