Supplemental; When and where did passports and the current notion of protected boarders originate? I know for example a Roman boarder was relatively porous unless they were engaged in war with the neighbor that shares the boarder but boarders and immigration today tends to be more regulated and a more important factor of national sovereignty.
Answering the supplemental question: I've read in several places about how Genghis Khan and the Mongol empire codified passports for officials traveling on business. They used metal discs which could be worn or stored, and granted official passage across all of their territory, and served as credentials beyond it. Genghis Khan and the Making of the Modern World (Jack Weatherford) speaks to this a good deal, and implies that this was the first wide-spread use of official passports.
The Met has one in their collection. As you can see here, they mention that they were in use in China before the time of Genghis Khan as symbols of office: http://www.metmuseum.org/toah/works-of-art/1993.256
the literature states that most modern people would be highly surprised by the relative lack of paperwork / passports of older eras. Ellis Island, for example, existed precisely because there were no control personnel at the loading ports checking papers and backgrounds-- immigrants were inspected upon arrival and quarantined if they demonstrated signs of tuberculosis (then, as now, incurable). many travel accounts exist as late as the 1920s of individuals riding a boat from the UK to France, and staying as long as they wished (or as funds permitted). it was WW1, and then even much more so, the refugee / genocides of WW2 that sparked absolutist modern controls on borders.
there are exceptions. historically, even in Czarist times, Russians have been required to have TWO passports -- one for internal checks by police, and one if they wish to travel abroad (and today, the "exit visa"-- the permission to leave the country-- doesn't exist as a concept in Western countries but is absolutely familiar, for example, to mainland Chinese). China also provides the counter-examples of specific "Chinese exclusion acts" to control their immigration to the US and the related "Gentlemen's Agreement" with Japan.
I think first I should clarify something about Shanghai - Shanghai being a completely open port was an anomaly even in 1949.
There were no passports as such until relatively recently. but non-colonial ports even in the early modern period generally had some measure of controls and customs, even if it wasn't always based on paper documentation. Shanghai was an exception to the rule at that time because although China was never formally claimed as a colonial possession by any Western power, it was divided into "Spheres of influence", and Shanghai itself was divided into different foreign quarters; there was a French district and a British District, a Dutch district, etc., and that made the port situation incredibly complicated.
That story goes back to 1842 and the first Opium war. Before then, China had refused to open any ports to Western traders. The first Opium war was fought between the British Empire and China over the issue of British East India company opium smugglers. The British imposed the first of a series of unequal treaties on the Chinese, and one of the treaty provisions was that China would open 13 ports to Western Trade, and over time a lot of other imperial powers managed to get similar concessions. Shanghai became so open because all of the imperial powers had a presence.
It was a legal nightmare for the Chinese authorities because people with foreign citizenship could claim diplomatic immunity within their respective districts, and it made enforcing border and customs rules almost impossible.
The treaty port system did not disappear when the Qing dynasty collapsed, it did not disappear during the Chinese civil war. The treaty port system and the unequal treaties were not conclusively overturned until the Communists took power and China was unified under a single government again. In short, this kind of open port wasn't common even in 1949.
My main sources on this, I do not have with me. When I get home I'll run through this and make sure it all checks out. The first one; it's a great book though, I highly recommend it, it's called Webs of Smoke. The second source I'm drawing from is the textbook for one of those classes; I can't consult it anymore because I sold it back after the class ended, but if you're interested.
Tha Austrian novelist, playwright, journalist and biographer Stefan Zweig (1881 - 1942) writes about passport-less travel in his autobiography (1942, title: "The world of yesterday"). He compares the 1930s with the time he travelled as a young man (from 1900 until 1914) and reports a massive change in the restrictions on travelling due to identity document checks.
I'll translate some relevant parts from pages 463f (I only have the German original version):
Before 1914, the world belonged to everybody. Everyone went where they wanted to and stayed as long as they pleased. There were no visa, and I am still amazed by the awe of young people, when I tell them that before 1914, I travelled from India to America without owning or ever having seen a passport. (...) Everywhere countries defended themselves against the foreigner. All the degradations which once were created for dealing with criminals, were now used for normal travellers before and during their trip. You had to let yourself be photographed, from the right and from the left, in profile and en face, the hair cut so short so that your face could be seen; you had to give fingerprints, first only the thumb, then all ten fingers; you had to present credentials, references, helth certificates, invitations and the addresses of your relatives; you had to bring moral and financial guarantees; you had to fill in forms and sign them in three or four copies; and if only one sheet of all this paperwork was missing you were lost. (...) If I count how much time I spent filling in forms, the hours spent waiting in administration offices and being searched and questioned, then only I feel how much human dignity has been lost in this century, which as young people we dreamed of as one of freedom and world citizenship."
edit: forgot to introduce who Stefan Zweig was.
I believe that Shanghai was unique at the time. The free port concept was not in place until after the Japanese occupied the city in 1937.
Jews, largely from Germany, came to Shanghai because there was no other place on earth that would admit them. It certainly was not a convenient destination geographically and there was significant risk that the Japanese would adapt the genocidal policy of their allies, the nazis.
Some 20-30 thousand Jews came to Shanghai. The Jews were required to live in a ghetto, though they were not confined there.
After the war almost all the Jews left. One of the Synagogues survives as a museum supported by those who survived the war because they were in Shanghai.
Does this also have anything to do with being Shanghai'd.