Twitter is suing the U.S. Department of Homeland Security and alleging the government is misusing an investigative tool as part of an internal witch-hunt to uncover who is behind a Twitter account critical of the immigration service.

The lawsuit, filed on Thursday in California, comes on the heels of a report that visitors to the U.S. could soon be routinely asked to hand over email and social media account passwords to the immigration service.

In its lawsuit, Twitter says that U.S. Department of Homeland Security and U.S. Customs and Border Protection have demanded it hand over information regarding the @alt_uscis Twitter account.

The account is one of many established after the inauguration of President Donald Trump as dissent accounts of U.S. government agencies. The writers are critical of Trump and new leadership, and most claim to be insiders working in government or former staffers.

On March 14, Twitter received a summons from the customs agency demanding the identity of the person behind the account, the company says.

Twitter refused, contending the law that allows the government to demand the information, 19 U.S. Code § 1509, only covers a narrow range of alleged offenses, including import violations.

“CBP’s investigation of the @alt_uscis account plainly has nothing whatsoever to do with the importation of merchandise into the United States,” it says in the lawsuit.

“Permitting CBP to pierce the pseudonym of the @alt_uscis account would have a grave chilling effect on the speech of that account in particular and on the many other ‘alternative agency’ accounts that have been created to voice dissent to government policies.”

The lawsuit follows discussions between Twitter and a U.S. customs investigator over the appropriateness and lawfulness of the summons. Twitter says it told the investigator it would notify the account holder unless it was served with a court order forbidding it from doing so. The government did not apply for such an order.

Then Twitter told the government that it would challenge the summons unless it was withdrawn. That didn’t happen, and Twitter then filed Thursday’s lawsuit.

Earlier this week, The Wall Street Journal said visitors to the U.S. could soon be asked to hand over email and social media passwords as part of their vetting to get into the country. The so-called “extreme vetting” would give the U.S. government deep access into the personal lives of visitors in a way no other country has ever attempted.

The Department of Homeland Security and U.S. Customs and Border Protection agency have yet to comment on Thursday’s lawsuit.

To comment on this article and other Macworld content, visit our Facebook page or our Twitter feed.