WASHINGTON—Many 2020 presidential campaigns face challenges in rebuffing cyberattacks despite taking some steps to beef up security, an issue brought into fresh focus by President Trump’s comments that he might accept information from foreign governments that was damaging to his rivals.

Three years after John Podesta, Hillary Clinton’s 2016 campaign chairman, clicked on a spear-phishing email that allowed Russian hackers to break into his account, followed by the publication of his emails by WikiLeaks, campaigns today are...