Facebook has been making big investments in security measures ahead of the 2018 midterm elections, and the social network says that some of those efforts are paying off.

On Tuesday, Facebook (FB) - Get Report said that it had removed a network of pages linked to 'coordinated inauthentic behavior' originating in Iran and Russia. Nathaniel Gleicher, Facebook's head of cybersecurity policy, wrote in a blog post that acting on a tip from FireEye security researchers, Facebook took down 652 groups, pages and accounts dubbed 'Liberty Free Press', and intended to influence political opinion in the U.S. and elsewhere. Gleicher also reported that Facebook had removed another round of pages, groups and accounts linked to Russian military intelligence.

"We constantly have to improve to stay ahead. That means building better technology, hiring more people and working more closely with law enforcement, security experts and other companies," Gleicher wrote.

Gleicher's report is the latest effort by Facebook to appear transparent in how it does business, and to show that it takes issues like foreign election interference seriously. In late July, Facebook also reported removals of Russian-linked pages that had been buying ads and publicizing political rallies. It also suspended the official account of the conspiracy theorist Alex Jones earlier this month.

Just how costly are these efforts, and how well do they really work? Only Facebook knows the answer to both questions.

David Wehner, Facebook's CFO, told investors on a July earnings call that the investments totaled "in the billions of dollars per year," and also suggested that they would continue for an indefinite period. "Those will have a negative impact on margins. We think that's the right thing to do for the business in terms of ensuring the community's safety and security and the durability of the franchise," he added. "So those are important investments from an ROI perspective, but they don't have, obviously, immediate translation into revenue dollars."

Combined with decelerating revenue and warnings that margins will shrink into the foreseeable future, that sent Facebook's stock into a nosedive, with shares down about 20% since its July 25 earnings report.

On the same call, CEO Mark Zuckerberg warned that "Security is not a problem you ever fully solve...we face sophisticated well-funded adversaries who are constantly evolving."

Notably, the $500 billion social network is tapping outside researchers to help. In July, it sent out an offer to academic researchers that granted access to a pipeline of data that circulated on Facebook, for purposes of studying misinformation around elections. There was a catch to the project, dubbed Social Science One: No data before January 1, 2017 would be made available, meaning that the November 2016 election -- the election that set off a domino effect for Facebook, leading eventually to the Cambridge Analytica scandal, Congressional hearings and months of negative headlines -- can't be studied by the researchers. A spokesperson for the project declined to comment.

With the November midterm elections less than three months away, there are some signs that Facebook is feeling the pressure of what will be their next big test. In a Recode profile of the company's efforts, Facebook's head of civic engagement Samidh Chakrabarti told the website: "I feel like we have a good handle and a good plan for many of the problem types that we're seeing.But whether we will get far enough, fast enough, is really the question." 

Facebook shares were trading at $172.62 as of Tuesday close. 

Facebook is a holding in Jim Cramer's Action Alerts PLUS member club. Want to be alerted before Jim Cramer buys or sells FB? Learn more now.