Some of the Federal Bureau of Investigation’s warrantless searches through the National Security Agency’s enormous troves of communications data violated the law and the Constitution, according to secret surveillance court rulings partially declassified on Tuesday.

The bureau’s so-called backdoor searches, long regarded by civil libertarians as a government end-run around warrant requirements, were overly broad, the court found. They appear to have affected what a judge on the court called “a large number of individuals, including U.S. persons.” On one day in December 2017 alone, the court found, the FBI conducted 6,800 queries of the NSA databases using Social Security numbers. The government, in secret, conceded that there were “fundamental misunderstandings” among some FBI personnel over the standards necessary for the searches.

The redacted ruling was kept secret for a year. It represented the latest legal battle over the scope of post-9/11 mass surveillance that affects American freedoms in the name of counterterrorism. It was one of several secret court documents released Tuesday by the ODNI.

Judge James Boasberg of the Foreign Intelligence Surveillance Act (FISA) Court found last October that elements of FBI procedures for querying the databases and then purging irrelevant results–a mechanism to protect Americans’ privacy–“inconsistent with statutory minimization requirements and the requirements of the Fourth Amendment,” which protects Americans against unreasonable searches.

“ On one day in December 2017 alone, the court found, the FBI conducted 6,800 queries of the NSA databases using Social Security numbers. ”

As early as March 2018, the FISA Court identified to the government that the FBI was not sufficiently documenting which of its queries were tied to people inside the United States, despite a statutory obligation to do so. Nor were the searches “reasonably designed” to find evidence of crimes or foreign spying.

“Without such documentation and in view of reported instances of non-compliance with that standard, the procedures seemed unreasonable under FISA's definition of minimization procedures’ and possibly the Fourth Amendment,” Boasberg wrote.

Boasberg’s ruling represented a rare defeat for the government before the FISA Court, and the government appealed it to the FISA Court of Review, another rarity. The appeals court sided with the lower court in July, and the FBI agreed to change its querying, documentation, and related procedures.

The subsequent changes now require the FBI to explain why searching Americans’ data is necessary to find foreign-spying information or potential evidence of criminal activity, as well as to distinguish between its searches involving Americans and its searches involving foreigners. Civil libertarians questioned the ability of those changes to adequately protect American privacy.

“The FBI’s conduct clearly shows that giving the government warrantless access to Americans’ communications will lead to fishing expeditions and abuse,” said Jake Laperruque, senior counsel with the Project on Government Oversight’s Constitution Project.

“But the new FISA Court rules don’t do enough to prevent more misconduct. The only way to do that is for Congress to pass a law closing the backdoor search loophole.”

The decision highlights the persistent controversy under what is known as Section 702 of the Foreign Intelligence Surveillance Act, a constitutionally questionable law created to legalize the NSA’s post-9/11 warrantless dragnets for ostensibly foreign communications. Those surveillance dragnets inevitably–“incidentally,” in NSA’s preferred terminology–collect massive amounts of Americans’ communications and associated records. The law currently provides the basis for massive amounts of NSA collections harvested from major tech firms, a program known as PRISM, and in transit across the internet, known as upstream collection.

NSA in March 2017 stopped collecting Americans’ electronic communications that merely discuss foreign surveillance targets, known as “about” collection, after violating restrictions placed on the collection by the FISA Court. Yet the FISA Court ruling indicates that the government attempted arguing that “about” collection was acceptable under PRISM, if not upstream collection. Boasberg rejected the argument.

In addition, the NSA, FBI, and CIA can warrantlessly search the vast Section 702 databases for information on Americans, something known as a backdoor search, something they have reported doing at least tens of thousands of times annually. Yet until a recent change, the FBI did not even record how many times it searched through the NSA databases for Americans’ information.

The bureau’s insufficient compliance with the new standards for documenting, tailoring, and then appropriately purging its sources is the issue at stake in Tuesday’s declassifications. FBI representatives did not immediately respond to a request for comment.

Ever since Edward Snowden’s 2013 surveillance revelations, the security agencies and their congressional allies have fought to protect Section 702, even as they acquiesced to restrictions around the warrantless bulk collection of domestic phone records. Those restrictions, the USA FREEDOM Act, failed; the NSA deleted a trove of over half a billion domestic phone records. Yet the FREEDOM Act required the FISA Court, which had previously only ever heard from government lawyers, to appoint outside attorneys who could push back on government arguments. The rulings indicated the so-called “amici” were a significant factor behind new restrictions on the FBI backdoor searches.

Congress reauthorized Section 702 for another five years in January 2018, though this time required the FBI to document its queries. President Donald Trump incorrectly viewed it as part of his baseless conspiracy theory that Obama had him placed under surveillance, but himself signed the reauthorization into law.

Senator Ron Wyden, the intelligence committee member who has sounded the loudest alarms about the backdoor-search provision, said the FISA Court ruling showed that Congress should never have accepted the FBI’s assurance that it was unable to account for its backdoor searches. He also indicated the government was still hiding evidence of wrongdoing.

“Today’s release demonstrates how baseless the FBI’s position was and highlights Congress’ constitutional obligation to act independently and strengthen the checks and balances on government surveillance,” Wyden said. “The information released today also reveals serious abuses in the FBI’s backdoor searches, underscoring the need for the government to seek a warrant before searching through mountains of private data on Americans. Finally, I am concerned that the government has redacted information in these releases that the public deserves to know.”