Re: Is this legal?
I hate to break it to people but this is standard in many industries. Or at least any industry even partially related to the defence sector, and in quite a few high tech research groups similar bans exist. I've experienced this in multiple countries across Europe (UK and continent), Asia and Australia.
Depending on the level of security clearance you need for your work, even just having been to visit these countries can be enough to get questions asked. China, Russia, Iran and North Korea are the main ones, but if you need tighter clearance expect questions if you've been to Cuba, Laos, Venezuela, etc...
For the high tech research groups it tended to be less about "national security" and more that actually verifying that people were who they say they were and had the training, education, experience they claimed was very difficult. Additionally, theft of research and IP was considered a real risk - I know of one case where a chinese person was given a job, and thankfully that countries intelligence service identified them as a chinese intelligence agent BEFORE they started working. The risk is definitely real.
So is it discrimination - yeah. But is it legal - also yeah. It's unfortunate, but sometimes nations put themselves out of the trustworthy bracket, and the costs are borne by their own citizens...