In a major vindication for Edward Snowden — and a blow for the national security policy pursued by Republicans and Democrats alike — the U.S. Court of Appeals for the Second Circuit ruled Thursday that the National Security Agency's metadata collection program is unlawful. This is the most serious blow to date for the legacy of the USA Patriot Act and the surveillance overreach that followed 9/11.

The central question depended on the meaning of the word "relevant": Was the government's collection relevant to an investigation when it collects all the metadata for any phone call made to or from anywhere in the U.S.?

The court said no. That was the right decision — not so much because it protects privacy, as because it broke the bad precedent of secret law created by the NSA and endorsed by the secret national security court known as the Foreign Intelligence Surveillance Court.

The first striking thing about the court's opinion was how openly it relied on Snowden's revelations of classified material. The court described how the program was known — by Snowden's leaks. It also analyzed the NSA order to Verizon, leaked by Snowden, that proved the existence of the program and revealed indirectly the legal reasoning that the government relied on to authorize the metadata collection.

The Second Circuit seemed supremely untroubled by the origin of the information in a violation of classification laws. At one point, it noted that the government disputed the claim that virtually all metadata are being collected — then dismissed the government's suggestion as unconvincing in the light of the evidence. Today, it would seem, the Snowden revelations are treated as judicially knowable facts, at least in this court.

Then there's the legal reasoning, which was equally striking. To get to the conclusion of unlawfulness, the Second Circuit initially had to find that anyone who has had metadata collected — that is, anyone in the U.S. — has the right to sue and challenge the statute.

The government said no one could challenge the NSA program except the telephone companies, like Verizon, who received the order. Its logic was particularly Orwellian. The Department of Justice argued that the Patriot Act demanded secrecy in reviewing challenges to the surveillance program. The secrecy, in turn, implied that the statute meant to preclude anyone from challenging the program under the non-secret provisions of the Administrative Procedure Act, the catch-all statute for challenging unlawful government programs.

The Second Circuit wisely rejected what it called this "argument from secrecy." It reversed a lower district court that had refused to allow the suit to proceed, and set the stage for an analysis of relevance under the statute.

Relevance, the court said, should be measured the way the idea is used in ordinary grand jury investigations. That standard of relevant documents or objects to be brought under subpoena is pretty broad. It's often said a prosecutor could indict a ham sandwich. Well, a prosecutor can also subpoena the recipe the cook used to make it.

The government argued that this broad standard of relevance covered the metadata it's been gathering. After all, once the metadata is in hand, the government uses it to look for patterns connected to terrorism or other national security threats — so the body of data must be in this sense relevant to the investigation.

The court wasn't buying this expansive notion of relevance. It pointed out that only some of the metadata collected turns out to be relevant to investigations — meaning most or all of it doesn't matter at all.

Although the court didn't use this language, it was essentially saying that the collection of all metadata is an overbroad search, well beyond even the most expansive conception of relevance.

The court didn't address the question of whether it would be constitutional for Congress to order such broad searches; it just held that Congress didn't intend to authorize them. That left Congress and the President with the option of changing the law to authorize the metadata collection, assuming political will were to exist.

This was the right result — but not necessarily because of privacy, which the court didn't address directly at all. What was most wrong with the secret NSA orders was that they depended on a secret interpretation of the law, according to which "relevant" was assigned the broadest possible meaning. By implication, the secret intelligence court endorsed this interpretation. But the public never knew about it, at least not until Snowden.

Secret laws are anathema to democracy. The text of the Patriot Act wasn't secret, but the government's legal interpretation of it was. Secret interpretations of laws have the same effect as secret laws — and are therefore just as bad. The public can't approve or disapprove of what it doesn't know.

Now that we do know, the Second Circuit will push the government to pass its next law, if any, with full public knowledge. That's democracy — and we have the courts to thank for it.

The Ninth and D.C. circuits have similar cases before them now. Here's hoping they rule the same way, and that the Supreme Court can then stay out of it. The legal story may or may not be over. But it should be.

— Noah Feldman is a professor of constitutional and international law at Harvard and the author of six books, most recently "Cool War: The Future of Global Competition."