There is a long-standing border search exception to the usual 4th Amendment no-search protections, but there still are limits. As you know, warrantless searches are allowed when an arrest occurs in public and is based on probable cause, and searches and seizures of limited duration and intrusiveness may be allowed given reasonable suspicion of criminal activity. The border search exception (US v. de Hernandez) means that limited searches are allowed at border crossing without any suspicion at all. This happens to also hold of the "extended border" that reaches in to the US by 100 miles, but only in connection with immigration issues. In the case of Riley v. California, SCOTUS held that searching digital information on a cell phone requires a warrant, with certain exceptions pertaining to officer safety or destruction of evidence. No risk is posed by data on a cell phone, so no compelling government interest is posed by requiring a warrant to search a cell phone. The seizure of a cell phone, in aid of obtaining a warrant or in connection to officer-safety issues on the other hand could be reasonable.
The question of just how intrusive a search is allowed in the border crossing context is not clearly resolved: a cursory search is reasonable, an intrusive search is not. Full-scale forensic searches are unreasonable. In Alasaad v. Nielsen (Nov 12, 2019), the district court in Massachussetts ruled against a warrantless search which was "non-cursory", which gives you a state of the art view of what is allowed. In this case,
an advanced search is defined as "any search in which an officer
connects external equipment, through a wired or wireless connection,
to an electronic device, not merely to gain access to the device, but
to review, copy and/or analyze its contents"
The alternative, under CBP policy is
a basic search, which is merely defined as "any border search that is
not an advanced search."
Policy requires reasonable suspicion for an advanced search. In this case, a number of individuals (US citizens and one LPR) were subjected to an advanced search of their cell phones. In connection with these searches, data was copied and retained for an extended period of time.
The court points out that the border search exception applies to "routine inspections and searches of individuals or conveyances seeking to cross our borders", where "routine search" is defined in terms of cursoriness – the court concludes that forensic searches are by nature non-routine (get a warrant). This seems to kick the can down the road (what is a forensic search) – the court has some suggestions:
Basic searches, defined only as any search of an electronic device
that is not an advanced search, can access content from space
physically resident on a device using the devices' native operating
Using a device's native operating system, a basic search can access
content from the allocated space physically present on the device, it
can extend to any allocated file or information on the devices and,
for devices that contain metadata, it can reveal "the date/time
associated with the content, usage history, sender and receiver
information or location data."
Even in a basic search, agents can peruse and search the contents of
the device, using the native search functions on the device,
including, if available, a keyword search. An agent conducting a basic
search may use the device's own internal search tools to search for
particular words or images
The court does not address the question of what it means by "a device's native operating system" (Given things that I installed on my laptop which are not part of the OS, you can get a lot more information than you can with plain vanilla Win10). This, at least, suggests where the line is – it's about the tools that you use to obtain the information.