NEW YORK (Reuters) - A federal appeals court said foreign-born students may sue the U.S. government over claims it wrongfully canceled their visas, following a sting where it set up a fake university to entrap corrupt visa brokers.

The 3rd U.S. Circuit Court of Appeals in Philadelphia revived a proposed class action on behalf of more than 500 students who said they were deprived of due process when the government revoked their lawful immigration status after ensnaring them in the sting.

Writing for a three-judge panel, Circuit Judge Theodore McKee also faulted the government’s “flip-flop” over whether the students, including many from China and India, who thought they had “enrolled” at the fictitious University of Northern New Jersey were innocent victims, or participants in the fraud.

Spokespeople for the U.S. Department of Justice had no immediate comment.

The government in 2013 created the University of Northern New Jersey, supposedly located in the town of Cranford, to catch brokers of fraudulent student visas, even creating a website and social media accounts for the school that looked real.

It said brokers recruited more than 1,000 students to enroll, typically charged thousands of dollars for visas so they could stay, and sometimes arranged illegally for work visas.

Twenty-one arrests were announced when the university “closed” in April 2016.

The Department of Homeland Security then revoked the visas of many affected students, citing their “fraudulent enrollment,” prompting the lawsuit to restore their legal status.

In October 2017, U.S. District Judge Jose Linares in Newark, New Jersey, dismissed the lawsuit, saying it was filed too soon because U.S. Immigration and Customs Enforcement, or ICE, had yet to act on the students’ reinstatement applications.

McKee, however, said visa revocations were “final” orders that could be challenged in court, even if students had other means to fight removal, and criticized the government’s shifting views on whether the students were victims or conspirators.

“It would be a cruel irony indeed if we were to allow the government’s own flip-flop on that characterization to deprive us of the ability to review the disputed governmental action,” McKee wrote. “The flip-flop underscores the need for judicial review of a decision that would otherwise escape review by any court or agency.”

Ira Kurzban, a lawyer for the students, welcomed the decision, calling it the “first salvo” in efforts to stop ICE from “trying to entrap innocent students.”

McKee said it may still prove a “formidable challenge” to certify a class action because of many differences among affected students.

The case is Fang et al v Director, U.S. Immigration & Customs Enforcement et al, 3rd U.S. Circuit Court of Appeals, No. 17-3318.