Legal or not, NPAC members should be aware this can happen.
It would seem border security can perform these searches because you are engaging them as opposed to the other way around. In the simplest of terms, laws prevent authorities from stopping you on the street and making you dump out your back pack and hand over your mobile phone to be searched through. But once you've approached a border crossing and knowingly engage them, it's a different game. You are making yourself available to them and you don't have the same rights as a citizen being stopped randomly on the street.
But where it gets troublesome is what happens when border security wants to go through all your emails and personal records if you've given them no reason to think you're carrying contraband or involved in any illegal activity. Where is the line drawn? If they can search your luggage and car and look through any paper documents you may have at the border, can they demand to look at your emails on your phone, too?
Millions of people cross back and forth the Canadian and US borders without incident. But be prepared and know what your rights are - or lack of them - when doing so.