The Supreme Court on Thursday struck down California’s law that required charities to privately disclose their top donors to the state attorney general, a ruling that could carry implications for political donation disclosures and “dark money” spending.

The issue divided the court along ideological lines, and Chief Justice John G. Roberts Jr. wrote for the conservative majority. He said California’s demand for information about donors violated the constitutional right of freedom of association.

“California casts a dragnet for sensitive donor information from tens of thousands of charities each year, even though that information will become relevant in only a small number of cases involving filed complaints,” Roberts wrote. He said that could chill the First Amendment rights of donors who might not contribute if their names became public.

The decision drew fire from Democratic members of Congress, who called it a victory for “dark money” political groups. And the court’s three liberals said it could endanger other forms of disclosure.

“Today’s analysis marks reporting and disclosure requirements with a bull’s eye,” wrote Justice Sonia Sotomayor, joined by colleagues Stephen G. Breyer and Elena Kagan.

“Regulated entities who wish to avoid their obligations can do so by vaguely waving toward First Amendment ‘privacy concerns.’ It does not matter if not a single individual risks experiencing a single reprisal from disclosure, or if the vast majority of those affected would happily comply.”

California law requires the approximately 100,000 charitable nonprofits that fundraise in the state to file the identities of their most generous donors with the attorney general. The same information is sent to the Internal Revenue Service, which determines tax-exemption status.

California says the attorney general needs to have the information on hand in case there are complaints about charitable fraud, and that only the names of those who contribute so much that they could influence the charity are required. It says a key fact is that the information is not publicly disclosed, although it acknowledges past problems with that.

But two groups, the Americans for Prosperity Foundation and the Thomas More Law Center, sued. They said that the information is unnecessary and that the disclosure could lead to threats and harassment. The requirement, they said, chills the protected First Amendment speech of their donors and violates their right to free association.

“Today’s decision protects Americans from being forced to choose between staying safe or speaking up,” said Americans for Prosperity Foundation CEO Emily Seidel. “The ability to maintain one’s privacy makes it possible for people to join together in causes and movements. Especially given how polarized our country has become, the work of addressing injustice and advocating for change is hard enough without people facing fear of harassment and retaliation from the government and from potentially violent opposition.”

A district court ruled for the groups. But a panel of the U.S. Court of Appeals for the 9th Circuit upheld California’s practice.

The Supreme Court ruled in 1958 that the NAACP did not have to comply with Alabama’s demand that it list its donors because of the danger that could befall donors if their names were disclosed.

But the court just 11 years ago also said that anonymity is not guaranteed in political speech, such as when people sign petitions to put a referendum on the ballot.

Roberts said that when the First Amendment is at stake, disclosure regulations must be narrowly tailored to the government’s asserted interest.

“We have no trouble concluding here that the Attorney General’s disclosure requirement is overbroad,” he wrote, joined by conservative Justices Clarence Thomas, Samuel A. Alito Jr., Neil M. Gorsuch, Brett M. Kavanaugh and Amy Coney Barrett.

Even though the information filed to the California attorney general is supposed to remain under wraps, the chief justice noted breaches where it was disclosed.

He said the organizations challenging the requirement had said its members were exposed to “bomb threats, protests, stalking, and physical violence. Such risks are heightened in the 21st century and seem to grow with each passing year, as ‘anyone with access to a computer [can] compile a wealth of information about’ anyone else, including such sensitive details as a person’s home address or the school attended by his children.” He was quoting a concurrence in a past case.

Perhaps to deflect the notion that his ruling would protect conservative interests, Roberts noted that the court received concerned briefs from organizations that “span the ideological spectrum, and indeed the full range of human endeavors: from the American Civil Liberties Union to the Proposition 8 Legal Defense Fund; from the Council on American-Islamic Relations to the Zionist Organization of America; from Feeding America — Eastern Wisconsin to PBS Reno.”

The Biden administration took a middle-of-the-road approach to the question. It said the requirement shouldn’t be found unconstitutional in all applications, but the groups should have another opportunity to prove the rights of their donors had been violated.

Sotomayor said the majority’s ruling went much further.

“The same scrutiny the Court applied when NAACP members in the Jim Crow South did not want to disclose their membership for fear of reprisals and violence now applies equally in the case of donors only too happy to publicize their names across the websites and walls of the organizations they support,” she wrote.

She said the court “trades precision for blunt force, creating a significant risk that it will topple disclosure regimes that should be constitutional.”

The Americans for Prosperity Foundation is the charitable arm of Americans for Prosperity, the political organization formed by billionaire conservative Charles Koch and his brother David Koch, who died in 2019.

Some Democratic members of Congress had called on Barrett to recuse herself from the case because Americans for Prosperity supported Barrett’s confirmation with a million-dollar campaign.

Sen. Sheldon Whitehouse (D-R.I.), one of those Democrats, denounced the ruling. “We are now on a clear path to enshrining a constitutional right to anonymous spending in our democracy, and securing an upper hand for dark-money influence in perpetuity,” he said.

California’s Attorney General Rob Bonta (D) said, “Stripping our office of confidential access to donor information — the same information about major donors that charities already provide to the federal government — will make it harder for the state to fight fraud and prevent the misuse of charitable contributions.”

The cases are Americans for Prosperity v. Bonta and Thomas More Law Center v. Bonta.