THE RECORD of the federal government in dealing with aliens during periods of high international tension has never been very pretty. Unfortunately, the U.S. Court of Appeals here seems content to let it stay that way. By clinging to the view that there are almost no limits on what Congress and the president can do to aliens, that court has upheld President Carter's order singling out Iranian students for special and obviously discriminatory treatment.

That order has made those students the sole objects of a nationwide search by the Immigration and Naturalization Service. The service is attempting to determine which students have overstayed their visas or dropped out of school, with an eye toward deporting all it can. Students from other nations, not to mention non-students who have also violated the immigration laws, are being ignored in the sweep of campuses.

A search of that kind is wrong as a matter of national policy. It should also be wrong as a matter of law. The government should be in the business of discouraging, instead of insisting upon, special treatment of people, especially punishment on the basis of nationality. But it is on this precise point that the history of the country conflicts with the principles for which professes to stand.

While the Supreme Court has not been reluctant to insist that aliens can exercise many of the rights that make Americans free, it has usually averted its gaze when those rights conflict with immigration and deportation proceedings. Thus, a state cannot deny a man a license to run a laundry solely because he is an Iranian national, but the federal goverment can deport him because he is an Iranian -- or so it would seem from the rationale applied by the Court of Appeals in this case.

That rationale may well be consistent with the theory that the courts should rarely, if ever, interfere in the exercise of the power Congress has over immigration policy and the president has over foreign policy. But it is a rationale that opens the door to hasty and unprincipled action, like that the president has taken against the Iranian students.

The courts, at a minimum, can provide a cooling-off period while the country and its leaders think through the implications of decisions classifying people by nationality -- or race or political beliefs, which have also got into immigration policy. The haste (seven days) with which the Court of Appeals reverse a thoughtful decision by Judge Joyce H. Green, who held the search of Iranian students unconstitution, suggests that the court merely wished to get rid of the matter as fast as it could.