A federal appeals court has ruled a controversial cocaine test that resulted in the firing or punishment of 10 black Boston police officers may violate their civil rights, and kicked the case back to the district court that had thrown it out.

The Massachusetts Association of Minority Law Enforcement Officers, as well as Boston police officers, filed suit claiming the test — which uses hair follicles to hunt for traces of cocaine — resulted in false positives and was abandoned by the federal government over concerns about its quality.

Six of the officers have been hired back — and given lost pay — after the Massachusetts Civil Service Commission also threw out the hair test last year. But all of the officers are seeking further damages and the jobs back for the others.

The test, their union claims, singled them out unfairly.

“I don’t want any police officer, anyone who works in public safety, or anywhere for that matter, to be using drugs. I also don’t want people accused of something that the science can’t say, ‘This is what they did,’ ” said Larry Ellison, president of the minority officers organization. “Not everyone grows hair. Not everyone’s hair grows in the same manner. They’re not taking all the hair from the same place. You end up with these problems.”

Some of the officers also said they may have come in contact with cocaine while on the job.

The United States Court of Appeals for the First Circuit on Wednesday overturned a 2012 ruling by district court Judge George A. O’Toole Jr. In a 48-page decision, the appeals court said the cops may be able to prove that the police department’s policy, which uses hair samples to test for illegal drug use, has a “disparate impact” based on race.

Data showed that 55 black officers and cadets, and 30 white officers and cadets tested positive for cocaine from 1999 to 2006 — but 4,222 black officers were tested compared to 10,835 white police.

After conducting a complicated statistical analysis, the court ruled that the differences were not completely random — an important barrier to pass when determining whether a state-issued test runs afoul of the Civil Rights Act.

The test’s reliability also came under fire.

“The plaintiffs’ experts argue that hair tests are relatively unreliable and not that the federal government has refused to authorize hair testing in drug screening of federal employees,” wrote Judge William J. Kayatta, for a unanimous three-judge panel. “The plaintiffs’ experts also opine that black individuals tend to have higher levels of melanin in their hair, that melanin causes cocaine and associated chemicals … to bind to hair at a higher rate.”

The cops didn’t come away with a complete victory. The court ruled that Boston police provided due process in their hiring and firing procedures, and adequately trained and supervised their drug testers.

The Herald reported last year the civil service commission slammed the hair test for not meeting the standard needed to fire somebody.

The civil service ruling added: “A reported positive test result is not necessarily conclusive of ingestion.”