As Islamic State insurgents threaten the Turkish border from Syria, Turkey is struggling to staunch the flow of foreign jihadists to the militant group, having not so long ago allowed free access to those who would join its neighbor's civil war.

Thousands of foreign fighters from countries including Turkey, Britain, parts of Europe and the United States are believed to have joined the Islamist militants in their self-proclaimed caliphate, carved out of eastern Syria and western Iraq, according to diplomats and Turkish officials.

The militants, who seized an air base in northeast Syria on Sunday as they surge northwards, are trying to secure control of the area bordering Turkey above the city of Raqqa, their major stronghold, in a bid to further ease the passage of foreign fighters and supplies, sources close to the Islamic State group said.

Some of the foreign fighters in their midst reached Syria via Turkey, entering the region on flights to Istanbul or Turkey's Mediterranean resorts, their Western passports giving them cover among the millions of tourists arriving each month in one of the world's most visited countries.

Open-border Policy

From Turkey, crossing the 900-kilometer (560-mile) frontier into northern Syria was long relatively straightforward, as the Turkish authorities maintained an open-border policy in the early stages of the Syrian uprising to allow refugees out and support to the moderate Syrian opposition in.

That policy now appears to have been a miscalculation and has drawn accusations, strongly denied by the Turkish government, that it has supported militant Islamists, inadvertently or otherwise, in its enthusiasm to help Syrian rebels topple President Bashar al-Assad.

The rapid and brutal advance of Islamic State militants, bent on establishing a hub of jihadism in the center of the Arab world and on Turkey's southern fringe, has alarmed Ankara and its Western allies, forcing them to step up intelligence sharing and tighten security cooperation.

“Thousands of Europeans have entered Turkey en route to Syria, and a large number of them we believe have joined extremist groups,” said one European diplomat in Ankara, describing Turkey as a “top security priority” for the EU.

“In recent months especially we've seen a real hardening in Turkey's attitude, a recognition that this is a potential threat to their national security and a desire to take more practical steps through intelligence channels, police channels,” the diplomat said, declining to be named so as to speak more freely.

That cooperation includes tighter screening of passengers on flights into Turkey in collaboration with European Union member states, and the beefing up of border patrols on the frontier with Syria, the diplomat and other officials said.

Turkey already kept a “no-entry” list of thousands of people suspected of seeking to join “extremists in Syria” based on information from foreign intelligence agencies, a Turkish official said, and barred more than 4,000 people from entering the country last year alone as a result.

Limited border gates

Only three of 13 border gates between Syria and Turkey were now fully open, the official said, with foreign nationals only allowed to pass through two of them. Close to 70 people were detained in Turkey last year on suspicion of links with extremist groups in Syria.

“Security measures were increased a while ago as a result of the latest developments ... The Turkish armed forces believe the current precautions are sufficient,” a second senior government official told Reuters.

The presence of foreign fighters among the Islamic State group's ranks was made brutally apparent this month by the beheading of American journalist James Foley, his killer's London accent apparently identifying him as one of an estimated 500 Britons believed to have joined the jihadists in Iraq and Syria.

Highlighting security failures on the Turkish border, a Syrian source close to the Islamic State group told Reuters that the militants had been tipped off to a planned U.S. operation to rescue Foley when Americans were seen asking about the hostages in the Turkish city of Antakya, about 12 miles (20 km) from the Syrian border.

Foley and other U.S. hostages were moved as a result, the source said, speaking on condition of anonymity.

“If Turkey had not opened its border with Syria ... to Islamic State (IS), if so many fighters had not crossed the border into Syria with their guns and equipment, and if this group had not used Turkey as a base, IS could not have amassed its current strength in Syria,” wrote columnist Kadri Gursel on Al-Monitor, a news website focused on the Middle East.

Border crossings more difficult

One non-Syrian Islamist fighter who joined the Syrian rebel ranks in 2012 said he had crossed the border several times in the early stages of the conflict, though he said it had since become much more difficult.

“The borders were wide open. We used to get in and out of Turkey very easily. No questions were asked. Arms shipments were smuggled easily into Syria,” he told Reuters from outside Syria.

Syria's rebels at the time enjoyed Western backing despite concerns about Islamist militants in their ranks, with Washington providing non-lethal aid and European states including Britain and France pressuring the EU to allow its arms embargo to expire.

Turkey has repeatedly denied harboring or arming militants or turning a blind eye to their presence. Officials say it designated the Islamic State group's precursor a terrorist group as long ago as 2005 and that Prime Minister Tayyip Erdogan vowed “zero tolerance” for al-Qaida-linked groups last November.

But they recognize a growing threat to their own security, particularly with Islamic State fighters still holding 49 hostages seized from the Turkish consulate in the Iraqi city of Mosul in June, including the consul general, special forces' soldiers, diplomats and children.

They also refer to video footage filmed in Raqqa and broadcast this month by Vice News in which an Islamic State activist said the group would “liberate” Istanbul if Turkey did not reopen a dam on the Euphrates river, prompting a government minister to respond that it would not surrender to such threats.

“The Islamic State is here to establish the law of God ... Turkey is not being ruled based on God's law but as a secular state,” one Islamic State fighter in Syria told Reuters.

“Right now the priority is Lebanon, Syria, Iraq, Palestine and Saudi Arabia, then Turkey,” he said.

Sources close to Islamic State in Syria say the group wants to take control of the border crossing at Jarablus, northwest of Raqqa. Earlier this year, it pushed out rival Sunni Islamist militants from the village to try to do so, but the Turkish authorities closed the passage.

Islamic State fighters also control the area around the tomb of Suleyman Shah, grandfather of the founder of the Ottoman Empire, in northern Syria. The group has destroyed several shrines and tombs sacred to Shi'ites and other sects, stirring fears in Turkey that their next target might be Suleyman Shah.

Ankara regards the tomb as sovereign Turkish territory under a treaty signed with France in 1921, when Syria was under French rule, and has said it will defend the mausoleum.

Threat on its own soil

But Turkey, along with its Western allies, could also face the threat of militant attacks on its own soil.

“I think they're waking up to the severity of the situation, particularly as the internal threat is getting higher and higher,” said a second European diplomat, adding coastal resorts popular with European holidaymakers could become a soft target.

“It's a danger for Turkey because if Islamic State decide that Turkey is an enemy (and launch an attack) then Turkey becomes like Egypt ... That's the end of tourism,” he said.

Turkey's experience with a range of security threats, from Kurdish militants who fought a three-decade insurgency in its southeast to leftist extremist groups behind urban bombings, has left it with a formidable domestic intelligence agency.

But officials in Ankara estimate there are foreigners from more than 80 nations fighting in Syria and Iraq and say it is unreasonable for Turkey to act as “lone gatekeeper”, stopping individuals who have traveled freely from their countries of residence after being radicalized at home.

“I don't think anyone has to worry about capabilities, but it's the scale of the threat and the speed it's evolving that any country would struggle with,” said the first European diplomat. “And Turkey finds itself right on the front line.”