Picture the scenes in MI5, MI6, the Home Office and the UK Border Agency as Christmas Day passed into Boxing Day. The news channels were reporting that a young Nigerian had tried to blow up a passenger plane on its approach to Detroit. Not just any young Nigerian, but one believed to have a British connection.
You can imagine the sinking hearts of the few staff on duty as frantic calls and computer checks finally established that this Umar Farouk Abdulmutallab was indeed the same Umar Farouk Abdulmutallab who had spent three years at University College, London.
Just as you can imagine the blessed relief when they found records showing that this same Abdulmutallab had tried to return to the UK in May, but been barred for citing a 'bogus' college on his application.
After a tense 24 hours, the security services had emerged with credit. In place of the Great British Christmas blunder - which is what this would have been if, say, there had been no record of Abdulmutallab at all, or he had been cheerfully commuting between London and Yemen - we had something resembling a success.
The system worked. Although the young man concerned came from a privileged background and had a genuine degree to show for his three years at UCL, he had been refused entry on an elementary technicality.
Thus it was that the plane he reportedly intended to down was mostly not full of Britons; that the beleaguered national flag-carrier was spared and that the justice in store for the presumed would-be bomber will be the US brand, rather than ours.
Thus it is, too, that - as President Obama instantly understood - it is the US intelligence agencies that must face the music, not Britain's, especially as Abdulmutallab's father had warned US diplomats that his son might present a danger.
Yet even if the British agencies did well here, they should not become so carried away by the congratulations, potential medals and - oh dear - perhaps bonuses, that they do not pause to reflect that there but for the grace of God . . .
Take what has been reported about Abdulmutallab. Why was he refused entry to Britain? Because, it is said, he had given the name of a non-existent or non-registered college.
Had he been that bit more careful, it might have been a different story. Then again, he might not have needed to apply for re-entry at all, had he simply stayed after his visa expired. How many over-stayers are ever detected or expelled?
In national security, as in police work, it is the small slip-up that can make the difference - as it did with Abdulmutallab and his dealings with the British authorities and did not with Abdulmutallab and the United States.
But when the US security services turn round, as they may well do, and blame the British Government for general laxness - even though in this case they struck lucky - they will have a point that is not simply about passing the buck.
For the student visa system is a weak point in Britain's defences - and known to be so by pretty much everyone, except, it seems, those who actually run it.
Why trek across mountains and brave tempestuous seas, why risk trying to stow away in a lorry at Calais, if you can achieve the same objective - entry into Britain - by a means that is relatively comfortable and entirely legal?
Last year, the UK issued almost a quarter of a million student visas - three times more than the number issued 10 years before and almost twice as many as visas issued last year for employment.
Another 144,000 students were admitted for six months or less as student 'visitors'", and a similar number of students already here applied successfully to extend their stay.
Altogether that is half a million student visas of one sort or another issued in a single year. And that does not include students from the EU who move freely between the member countries. Yet the way visas are issued leaves much to be desired.
The new points-based system was supposed to make the issuing of visas more rigorous. In fact, it seems to be having, if not the opposite, then a perverse, effect.
Applications are now mostly a box-ticking exercise handled by commercial agencies; very few applicants are interviewed any longer face-to-face. Such rigidity tends to exclude those, including friends and relatives, who do not tick the right boxes (or pay the right consultants). Personal discretion, seen as a weakness, has largely been eliminated from the procedure, even though it is increasingly clear that the exercise of discretion, otherwise known as gut feeling, was a strength. Obtaining a student visa has become more and more a question of money than character.
The Government's target of getting 50% of school-leavers to continue their studies encouraged universities to increase student numbers exponentially.
Without the money to pay for this growth, they admitted more and more overseas students, using their full fees to subsidise their British counterparts. Universities flatter themselves that their desirability to foreign students reflects internationally acclaimed standards. The reality is more complicated.
The price of coming to Britain under the real or feigned pretext of studying may not be significantly higher than paying a 'snake-head', or equivalent, to organise illegal entry.
And the requirement that all students be able to support themselves is, as a recent BBC Newsnight programme illustrated, easily bypassed, as the same sum of money is shuttled between bank accounts. Even the academic requirements may not be as rigorous as they seem, given the proliferation of self-styled 'colleges'.
Fears that the system is regularly subverted are not just xenophobic apocrypha. While Abdulmutallab appears to have been a genuine student, who completed his degree, the system is wide open to be used not just as a passport to study, but as an all-purpose way into Britain, and thence to the rest of the world.
Nor is it at all apparent that the Government realises quite how degenerate the visa system has become. Remedial measures introduced so far look distinctly half-hearted - as they are probably bound to from ministers who seem to judge the value of everything, including education, only by numbers.
Colleges are supposed to be approved and registered before they can support visa applications, but the number of establishments is huge and, at the lower end, ever-changing. Institutions are now also supposed to confirm the status and attendance of their students.
But college authorities understandably ask why they should be doing a job the UK Border Agency is paid to do. Which is where, arguably, the rot set in.
Responsibility for the national border is not something that should be delegated. It is a prime function of government.
Until this Government understands that, or hands over to the next, the US is justified in asking when Britain is going to take security seriously.
MI5 and the rest struck lucky with Umar Farouk Abdulmutallab. But the holes in the system are still there for all to see.