Santa Clara and San Francisco counties jointly filed a lawsuit Tuesday challenging the Trump administration’s plan to deny green cards and visas to many immigrants who use public assistance such as Medicaid, food stamps and housing vouchers.

The suit, filed in the U.S District Court of Northern California, is the first legal volley in the nation fired against the so-called “public charge” rule, which the Trump administration unveiled in its final form on Monday. San Francisco and Santa Clara County previously sued the administration over its threat to deny federal funding to sanctuary cities.

“The Trump Administration’s new rule is an unlawful, foolish attack on immigrant communities,” Santa Clara County Counsel James Williams said in a written statement. “It will hurt all members of our communities by reducing access to critical health and safety-net services that create healthier communities for all of our residents.”

The change is one of the most aggressive attempts by the Trump administration to restrict legal immigration.

Federal law already requires people seeking permanent residency or legal status to prove they will not be a burden — or a “public charge” — to the United States. Current law factors cash assistance programs and/or long-term institutional care like Medicaid to stay at a nursing home in determining whether someone should be primarily reliant on the government for subsistence.

The new rule, which goes into effect on Oct. 15, broadens the factors that could disqualify a person to include public assistance programs such as Medicaid, food stamps and housing vouchers and considers factors like education, income and health.

The Trump administration has said the new rule would ensure people who come to the United States don’t become a burden and promote self-sufficiency.

“We want to see people coming to this country who are self-sufficient,” Ken Cuccinelli, acting director of Citizenship and Immigration Services, told the Associated Press. “That’s a core principle of the American dream. It’s deeply embedded in our history, and particularly our history related to legal immigration.”

A U.S. Citizenship and Immigration Services spokeswoman said the agency has a policy to not comment on pending litigation.

Santa Clara and San Francisco counties, along with a number of immigrant advocacy groups, say the rule would force people to withdraw from benefits out of fear their immigration status could be affected. The lawsuit seeks a temporary injunction to block implementation of the rule and to ultimately invalidate it.

In a statement Tuesday, San Francisco City Attorney Dennis Herrera called the rule “rubbish” and said it would shift health care costs to local government while pushing more people into homelessness.

“This illegal rule is yet another attempt to vilify immigrants,” Herrera said. “This rule forces people to make an impossible choice: their health or a better future for their family. We will all bear the cost of this misguided policy, which will shift millions of dollars in health care costs onto the taxpayers of San Francisco and Santa Clara counties.”

The counties’ lawsuit contends that the new rule drastically and illegally expands the definition of who is considered a public charge to include those using even minimal public benefits without sufficient justification.

“This abrupt shift in policy undermines the Counties’ critical public health and safety net systems, is arbitrary and capricious, flouts federal law, and seeks to usurp Congress’ authority by administratively repealing its longstanding family-based immigration system,” the lawsuit states.

The National Immigration Law Center announced Monday its intent to file a lawsuit, calling the policy change an attempt to “redefine our legal immigration system in order to disenfranchise communities of color and favor the wealthy.”

In their joint statement, the counties said reduced access to health care will lead to increased public health threats such as communicable diseases; raise local health care costs by “millions of dollars a year” because people will forgo preventative care and wind up in the emergency room; and cause local grocery stores and businesses to lose food stamp dollars.