There are several different issues here. One, deos the government have the right to search anything comming into or leaving the country, apperantly this is within the authority of the US Customs service, and every country on the planet does it. Two, under this aurhority, do they have the authority to search electronic devices for illegal items. Well, again apperantly that is a yes. There is quite a bit of software that is illegal to export, although other than kiddie porn, there isn't a lot that is illegal to import by itself. Third, however, is where the trouble begins, can they search for things that are not a crime to possess (like word documents) and examine them for evidence that a crime has or may be committed? I don't think this is permitted, and they indicate that themselves on their website:
"The authority to delay and speak with travelers derives from the United States Code (section citations below) enables CBP to prevent the entry of persons who are inadmissible under the Immigration and Nationality Act, and to prevent the smuggling of merchandise, including narcotics and other contraband items, into the United States.". They do not need to remove anything from a computer do do this, they need to run a simple program that looks for very specific things, if they need to do anything at all. The government has proven time and time again, they cannot be trusted with any latitude at all. They will abuse any authority and use any imformation they seize for any purpose they want regardless of the legality. Any inside business information may end up being used to illegally make money purchasing stocks, anything possibly incriminating will be used to start an investigation, if the crime is on the political hot list. When this gets to the Supreme Court, it will be stopped if Congress doesn't act first. There is no way they will allow the seizing of a lawyer's laptop when they can't even look at papers. They are certainly overreaching on siezing of data.