The National Security Agency has paid millions of dollars to reimburse technology firms for complying with requests for user data, according to documents from former NSA contractor Edward Snowden shared with the Guardian newspaper.

MicrosoftMSFT +7.29%, GoogleGOOG -0.40%, YahooYHOO +0.32% and FacebookFB +5.30% all supply user data to the NSA based on secret ordered from the Foreign Intelligence Surveillance court under a program known as Prism. Although U.S. law mandates compliance, the government usually helps pay for it.

U.S. law allows firms to seek reimbursement for complying with law enforcement records request. U.S. telecommunications companies have been reimbursed for giving the government data related to U.S. phone calls and Internet traffic, former intelligence officials say. Silicon Valley is no different when they hand over data on users’ social media accounts, according to the latest Snowden documents.

The document, an NSA newsletter dated December 2012, says that the tech companies faced extensive costs for meeting new certification demands following a secret court ruling. The Obama administration Wednesday declassified the October 2011 ruling, which found the agency violated the Constitution for three years by collecting tens of thousands domestic communications without adequate privacy protections.

“Last year’s problems resulted in multiple extensions to the certifications’ expiration dates which cost millions of dollars for Prism providers to implement each successive extension – costs covered by Special Source Operations,” the document says, referring to a division of the NSA.

More On This... NSA officers sometimes spy on love interests

The NSA declined to comment.

Earlier this year, Microsoft acknowledged that it charges law enforcement for passing on data. “Microsoft only complies with court orders because it is legally ordered to, not because it is reimbursed for the work,” the company said in a statement Friday.

A Yahoo spokeswoman referred questions to its Friday comment in the Guardian. “Federal law requires the US government to reimburse providers for costs incurred to respond to compulsory legal process imposed by the government,” the company told the newspaper. “We have requested reimbursement consistent with this law.”

Click for more from The Wall Street Journal.