(CNN) -- In late November, U.S. soldiers were supervising artillery training for Afghan troops in Nangarhar province, close to the Pakistan border.
After they climbed a ridge to assess the impact area, an Afghan border policeman suddenly turned on them and opened fire.
Seconds later, six Americans and their assailant were dead.
It was one of the deadliest incidents of what the military call "green on blue" -- a euphemism for attacks by members of the Afghan security forces on their allies in the international force known as ISAF.
They have risen sharply over the past year, raising fears that the Taliban are infiltrating the Afghan National Army and police force.
But military analysts and intelligence officials say the reality is more complicated.
The Taliban said they had recruited the border policeman, but his real motive was never established, and it transpired that he'd had an argument with his father over his choice of bride.
In an even deadlier incident, an Afghan air force officer shot dead eight U.S. Air Force personnel and a U.S. contractor at Kabul International Airport in March.
But there is little to suggest he was a Taliban infiltrator either.
According to a NATO analysis seen by CNN, "green on blue" attacks have killed 52 U.S. and allied soldiers since 2005, many of them in the past year.
The analysis concludes that combat stress provoked 36% of the attacks, even if the Taliban subsequently claimed responsibility.
In 23% cases, an Afghan soldier had been persuaded by the Taliban to carry out an attack -- but the motive in an additional 32% of cases was unknown.
A senior intelligence official involved in NATO's training program told CNN that "battlefield conditions and frequent deployments are the leading causes" of such incidents.
"When you are in the mountains for months, you've just had enough," he said.
The official said cultural differences over the handling of weapons and the attitude of western soldiers to Afghan women can exacerbate tensions.
Coalition officers often reprimand their Afghan colleagues for lax control of weaponry, and that can breed resentment.
Some incidents defy explanation.
In late 2008, an Afghan soldier liked and relied upon by his U.S. comrades in Wardak province suddenly turned his gun on them and shot two dead before fleeing.
He was never found.
For the Taliban, infiltration is a cheap tactic and one they boast about.
Beyond the incidents, it sows mistrust and apprehension on a wider scale among troops who should be cooperating.
As the struggle against the Taliban reaches its climax, military analysts say a growing "insider threat" could be disruptive.
For example, after three German soldiers were shot dead by an Afghan soldier this year, some of their comrades refused to go on patrol with their Afghan counterparts, according to the magazine Spiegel.
Earlier this month, Lt. Gen. William Caldwell, the commander of the NATO training mission, admitted recent incidents "erode the hard-earned trust that is required for an effective partnership."
But the senior intelligence official told CNN that the insurgents' efforts to infiltrate Afghan security forces had not so far yielded much of a dividend and wasn't anywhere near the top concerns facing ISAF.
He pointed out that the 52 coalition deaths caused by Afghan security personnel were a small percentage of nearly 2,000 "hostile fatalities" between 2005 and 2011.
Other estimates are higher -- but include killings by Afghan contractors and incidents of "impersonation," where an insurgent launches an attack disguised as a soldier or policeman.
Police and military uniforms are easy to come by in Afghanistan. In one incident this year, a soldier passed on a uniform and identification to a suicide bomber who attacked a military hospital in Kabul. Six people were killed.
One reason "green on blue" attacks have risen is because there's more interaction between U.S. and Afghan soldiers as the latter take on more responsibility.
There are about 290,000 Afghans in uniform. The number of joint military patrols has increased drastically, exceeding 10,000 last year.
Among measures being taken to prevent such attacks, commanders are told to ensure Afghan troops who've been in combat are getting adequate rest; and coalition officers are being taught to watch for warning signs.
More U.S. counter-intelligence officers are being deployed to Afghanistan to help with screening recruits and reviewing the profiles of serving soldiers.
The recruiting process now includes eight steps.
A recruit's application must be supported by two letters from community elders.
Gradually a nationwide database of Afghan security forces is being compiled based on biometric information.
Some fifty Afghans at the Interior Ministry, helped by the FBI, are populating the database. The objective is to screen out anyone with a criminal record or links to the insurgency.
The process of vetting and biometrically enrolling the records of nearly 300,000 Afghan security forces will be completed this year, according to a NATO training mission document compiled in February.