THE assault on Paris by Islamic State (IS) on November 13th was an attack on life’s innocent pleasures. The terrorists shot anyone who strayed into their gunsights—ordinary mecs out for a gig, sharing a drink, or watching a football friendly. It could have been any big city. It could have been you.

The deadly grasp of IS now reaches far from its base in Syria and Iraq. A day before Paris, suicide-bombers killed 43 people in Lebanon. Last month, 224 died when a bomb destroyed a Russian aircraft over Egypt. IS has spread death across the Middle East and north Africa. This week it pledged to kill Crusaders in Washington and beyond.

Paris was scarred by jihadist violence only ten months ago. It became a city whose world-class intelligence service was on high alert—and still IS got through to maim and kill (see article). Plainly and tragically, the world needs to build stronger defences. The question is how?

First, know thy enemy

IS bases its terrorism on a vicious calculation. It believes that successful attacks will inspire the would-be Muslim radicals that it is trying to recruit. But it also wants to provoke a backlash in order to convince those same radicals that the world despises them and their religion. In February IS propaganda described a “greyzone” in which some Muslims’ loyalty is divided between radical Islam and a country where they do not feel that they completely belong. IS wants terrorism to drive Muslims out of this greyzone and into the black-robed embrace of the Caliphate.

The response must be just as calculating. Leading the mourning this week, François Hollande, France’s president, vowed to destroy IS. That is a worthy aim, but a partial one, because other jihadist groups with equally murderous intent will thrive in the violent crevices of the Middle East. The struggle will be long. Countries therefore need policies that they can sustain even as the Middle East remains turbulent and, inevitably, the terrorists sometimes get through.

Remember that the West has two things to defend: the lives of its citizens, and the liberal values of tolerance and the rule of law that underpin its society. Where these are in conflict, it should choose policies that minimise the damage to values in order to make large gains in protection. Sadly, in the scramble for security, that principle often seems to be the first thing to go.

The starting-point for a safer world is at home, with the right legal powers. Jihadists are often radicalised online, in small groups. They communicate electronically. When they travel, they leave a trail. The intelligence services need controlled access to these data. Terrorists thrive on secrecy, yet the security services may abuse their powers. The solution is a legal framework subject to political and judicial scrutiny.

The law can be flexible—but only up to a point. After Mr Hollande declared a state of emergency, which he will seek to extend to three months using a vote in parliament, the police were able to stage raids across France without the need for a warrant. Some raids led to arrests and one, on November 18th in the suburbs of Paris, to shootings and to another plot being thwarted. Short-lived emergency powers are justified, because of the heightened risk of such follow-up attacks. But the French parliament needs to be careful. If warrantless searches later become routine, abuses will surely follow.

Resources count, too. This week Britain announced a 15% increase in the size of its security services, and a doubling of spending on cyber-defence. Mr Hollande has promised to recruit more police officers and judges. Yet some other states seem out of their depth. Several of the jihadists who attacked Paris came from Molenbeek, a suburb of Brussels with a large Muslim population that it struggles to integrate. Proportionately, more people have gone to join IS in Syria from Belgium than from any other country in Europe. The Belgian security services are a weak link.

That matters because the Schengen agreement abolished border controls between 26 European countries. Schengen has symbolic and economic value, but it also drags intelligence down towards the level of the weakest. Once a semi-automatic weapon crosses into a Schengen country from the Balkans, there is little to stop it reaching the hands of jihadists in France. A terrorist can put together a suicide-vest undetected in Brussels and travel unimpeded to Paris to detonate it.

The Schengen countries need to adapt to a more dangerous world. First, they need a stronger outer frontier. The French want to create an enhanced European border force, financed and staffed by all of Schengen’s members. This is a good idea, but an overdue one.

Second, within the borderless zone, Schengen’s members need to take down the barriers to policing. The EU’s database for migrants does not synch with the one at Europol, the law-enforcement agency. The European Parliament, worried about privacy, has been blocking a plan to give police access to passengers’ names on flights. Countries can do spot checks at the border, but not systematic ones. In Europe more broadly, requests for other countries’ records on, say, ballistics and criminals’ DNA, can be clumsy and time-consuming. To change such things would enhance security, but entails no infringement of fundamental rights. Do it.

The search for scapegoats

By contrast, the use of a strong external border to shut out refugees would gravely undermine liberal values without making Europeans any safer. Yet excluding refugees is what politicians in Europe and America have proposed, after one of the Paris attackers entered Europe through Greece, possibly on a false Syrian passport.

The coalition partners of the German chancellor, Angela Merkel, argue that, after Paris, the flow of refugees must be controlled. Poland’s Europe minister has written that it would be dangerous to take them in. Although America has a rigorous system for checking the backgrounds of refugees, over two dozen state governors now say a modest scheme to accept 10,000 Syrians should be halted. So does Marco Rubio, a Republican presidential candidate. Jeb Bush, another candidate, is broader-minded—he would allow in Syrian Christians (and IS propaganda chiefs would back him all the way).

In charts: Terror in western Europe In voters’ minds, Islamic terrorism and large-scale immigration seem to blend together, perhaps because the parents of some terrorists were themselves once migrants, perhaps because both denote a state that cannot control its own territory. Mainstream politicians, fearful of the populist right, seem reluctant to challenge such perceptions. But they have a duty to defend the values of a free society—if they want to live in one. The logic of turning away refugees is deeply flawed, practically and morally. Clearly, there is a risk of infiltration, and Europe should monitor new arrivals. But at least five of the Paris terrorists were European citizens, not refugees. Someone determined to blow himself up in a terrorist attack could always pay a people-smuggling network to get him in. Some of the refugees arriving on Greek islands were themselves the victims of jihadist violence, occasionally at the hands of Europeans who went to Syria to join IS. For Europe to put up a wall to Muslims would suggest that, as IS says, Europeans despise them all. That could be a pathway to terrorism, too.

The fight with IS

As well as securing its borders and making terrorists easier to detect within them, the world needs to fight IS in its territory in Iraq and Syria. As a last resort, that should include the deployment of Western ground troops.

Some, particularly on the left, argue that military engagement will defend neither Western values nor Western security. Unless it is clear how military action would end, killing people is hard to justify. Moreover, jihadist violence will only rise from the ashes and expose the world to greater danger. That, they say, is what the wars in Afghanistan and Iraq tell you.

Those conflicts do indeed hold sobering lessons. Yet—for the narrow purposes of IS—the wrong ones are being drawn. Modern armies are good at driving jihadists off territory, even if they are bad at rebuilding countries afterwards. Military action forced al-Qaeda out of Afghanistan. Later, the sustained strikes on its leaders hiding in Pakistan gravely weakened it.

Crucially, IS holds territory, as al-Qaeda once did in Afghanistan. Dislodging it would be worthwhile, because IS uses this territory to raise money and attract, train and co-ordinate many thousands of potential terrorists. For as long as it controls its would-be capital, Raqqa, and the Iraqi city of Mosul, IS remains a symbolic “homeland” for radical Muslims. The fact of having withstood the world’s great powers—because Allah wills it—serves as potent inspiration.

An alternative strategy to warfare might be to wait for IS to wither by itself. But that is a forlorn hope. IS continues to exist because the Middle East is consumed by a titanic struggle between Sunni and Shia Islam. This is overlaid by the clash between regional powers and the rivalry of America and Russia. Whatever the opponents of military action say, the West is not what sustains this fight. Were Western countries to withdraw and focus on diplomacy alone, the violence would still go on, possibly for decades.

The case for military action, then, is that the alternative is worse. And yet, partly because it has been a low priority, progress in America’s campaign to “degrade and ultimately destroy” IS has been agonisingly slow.

After Paris, however, the mission has taken on some urgency. Mr Hollande, vowing to be “merciless”, has ordered intense French bombing on Raqqa. America has been gradually increasing its efforts, including recently by saying it will deploy 50 special-forces troops against IS. Britain’s government is likely to seek parliamentary backing for bombing raids in Syria—about time it supported its allies.

All this is welcome, but it is unlikely to be enough. To destroy IS means taking Raqqa and Mosul. That requires an army. So far, the plan has been to train Iraqi forces to use in Iraq, and to look to Kurds and sympathetic fighters in Syria. That plan is not going well. The Kurds have other worries. Despite the training (and money), neither the Iraqis nor the Syrians are ready for a big fight.

The first step now must be to try harder to make the existing plan work, using more trainers and many more special forces fighting alongside Iraqi units. But if that fails, troops will have to come from elsewhere. Nicolas Sarkozy, the former French president, spoke for many this week when he suggested making common cause with Russia, and putting up with Mr Assad in order to use their fighters against IS. That approach has a superficial appeal, but would lead to a bloodbath—because both Mr Assad and his Iranian backers are sworn enemies of the Sunnis whose home is in IS’s territory. Better to assemble a UN-mandated force using Turkish, Saudi and Gulf Arab troops. That will not be easy, but all these countries have an interest in stabilising a Sunni region that threatens them—directly in the case of Turkey, which has itself been the victim of IS terrorism.

Barack Obama, America’s president, and other Western leaders have an incentive to shepherd such an alliance, because, if that scheme fails, a military campaign would depend on troops from NATO. Such a deployment still lacks political support. Speaking this week, Mr Obama seemed keener to dismiss suggestions of ground troops than he did to pursue IS. Yet, with each attack that IS unleashes on the West, the imperative to use Western troops against it will grow. In the terrible event of a large strike on American soil, the matter would be settled.

Talk, too

Military force is not enough on its own, though. It will make the rest of the world safer in the short run, but the critics are right that Islamic terror will end only when the Middle East lives in peace. The parallel aim, therefore, must be for regional powers to stop fighting through their proxies, and for the creation of federal states in Syria and Iraq that give Sunnis, Shias, Alawites and Kurds confidence that they can live together with decent representation in government. That requires strengthening the administration in Baghdad. And it means bringing an end to Syria’s civil war. Alas, judging by last week’s meeting in Vienna, such a settlement is still distant indeed.

The diplomacy will not be easy and military action should not be forestalled by its lack of progress. But the pursuit of political settlements must be earnest and involve all the parties, including Russia and Iran. The sticking-point is Mr Assad, whom both countries support. If there is to be peace in the remnants of his country, he has too much blood on his hands to remain in power indefinitely. Yet Vladimir Putin has his own jihadist threat—exacerbated by the departure of Islamists from the south Caucasus to Syria. Just perhaps, Mr Putin can be persuaded that Russia does not need Mr Assad to get rid of IS and also end up with an ally in western Syria.

Raqqa seems a terribly long way from the streets of Paris on a carefree Friday night. But the killings showed how easily violent ideas cross borders. Innocent lives are still at risk. They will probably be at risk for many years. All the more reason to act now, against every link in the chain.