A federal appeals court ruled Thursday that the National Security Agency's bulk, warrantless collection of Americans' phone records is illegal, writing that the spying program "exceeds the scope of what Congress has authorized," reported The Hill.

The case was brought by the American Civil Liberties Union against Director of National Intelligence James Clapper after former NSA contractor Edward Snowden revealed that the government was collecting millions of Americans' phone metadata - including phone numbers, durations of calls and time stamps.

While the Second Circuit Court of Appeals stopped short of calling the program unconstitutional, the landmark decision overturns a previous 2013 decision and represents a major victory for opponents of mass surveillance programs.

The ruling comes as Congress begins to debate whether to renew sections of the Patriot Act - the law the NSA uses to justify the spying program.

On behalf of the three-judge panel, Judge Gerard Lynch wrote that Section 215 of the Patriot Act "cannot bear the weight the government asks us to assign to it and that it does not authorize the telephone metadata program," reported The Hill.

"If the government is correct," Lynch wrote, "it could use § 215 to collect and store in bulk any other existing metadata available anywhere in the private sector, including metadata associated with financial records, medical records, and electronic communications (including e‐mail and social media information) relating to all Americans."

"Such expansive development of government repositories of formerly private records would be an unprecedented contraction of the privacy expectations of all Americans," Lynch wrote in the 97-page decision. "We would expect such a momentous decision to be preceded by substantial debate, and expressed in unmistakable language. There is no evidence of such a debate."

This particular NSA program doesn't collect the phone conversations, but Lynch wrote that metadata itself can reveal "civil, political, or religious affiliations" along with personal behavior and "intimate relationships," which is much more than Congress intended when it passed the Patriot Act to fight terrorism following Sept. 11, 2001.

Even Rep. Jim Sensenbrenner, R-Wis., the original author of the Patriot Act, said that he never meant to authorize the NSA's bulk phone collections program, according to The Hill.

The court didn't order the NSA to stop its collection of data, though. Lynch noted that some sections of the Patriot Act including Section 215 are set to expire on June 1, and said it is Congress' responsibility to debate the program and clearly establish boundaries.

"If Congress chooses to authorize such a far-reaching and unprecedented program, it has every opportunity to do so, unambiguously. Until such times as it does so, however, we decline to deviate from widely accepted interpretations of well-established legal standards," Lynch wrote, adding that the law "cannot be interpreted in a way that defines any meaningful limit."

Some members of Congress have said they weren't even made aware of the scope of the program, as most of the details were kept classified, reported The Verge. Because of that, Lynch wrote that "Congres cannot reasonably be said to have ratified a program of which many members of Congress - and all members of the public - were not aware."

Anthony D. Romero, executive director of the ACLU, said that Congress needs to consider more serious reforms following the court's decision.

"The current reform proposals from Congress look anemic in light of the serious issues raised by the Second Circuit," Romero said. "Congress needs to up its reform game if it's going to address the court's concerns."

National Security Council spokesman Ned Price told CNN that the White House is reviewing the court's decision.

"The President has been clear that he believes we should end the Section 215 bulk telephony metadata program as it currently exists by creating an alternative mechanism to preserve the program's essential capabilities without the government holding the bulk data," Price said. "We continue to work closely with members of Congress from both parties to do just that, and we have been encouraged by good progress on bipartisan, bicameral legislation that would implement these important reforms."

Attorney General Loretta Lynch defended the program, telling lawmakers on a Senate Appropriations subcommittee on Thursday that mass surveillance has been a "vital tool in our national security arsenal," and she is "not aware" of any privacy violations that have occurred since President Obama implemented new reforms, according to The Hill. Lynch said the Justice Department will review the decision and work with Congress to reauthorize the program while maintaining privacy.