The killing of General Mohammad Daud Daud, the police commander for northern Afghanistan, on Saturday by a suicide bomber who infiltrated security wearing a police uniform, highlights a recent change in Taliban tactics, says the BBC's Bilal Sarwary in Kabul.
Attacks by rogue soldiers or police and Taliban infiltrators have increased in frequency and ambition in recent months, say Afghan officials, and have sparked panic among President Hamid Karzai and his government.
A week before his death, Gen Daud said that militants had tried to infiltrate his security. He had had warnings about a threat to his life.
"The Haqqanis [Pakistan-based militant network] and Taliban groups tried to offer money to some of my police, some of my guards," Gen Daud told me in his heavily armoured convoy as he travelled to a meeting with visiting US Senator John Kerry in Mazar-e-Sharif.
"I am very vigilant. I have made a lot of changes in my movements, and keep a close eye on who guards the front and rear of my headquarters, but I have to travel all over northern Afghanistan, to different provinces. It is becoming tiresome."
He said the success of Nato's International Security Assistance Force and their Afghan partners was playing a role in the shift of Taliban tactics.
"They are not able to achieve any big victory in clashes with the security forces, so they have turned to rogue soldiers. Such attacks create mistrust within security agencies and demoralise them."
Until earlier this year, such attacks were sporadic and largely ignored by the authorities and the media.
But when a militant dressed as a soldier managed to get past the fortified walls of the defence ministry headquarters in Kabul in April killing several soldiers before being shot dead by Afghan soldiers, the government panicked.
The attacker was after Defence Minister Gen Abdul Rahim Wardak, who was not in the building at the time.
"The insurgents struck the very heart of the government," an official close to President Karzai told the BBC, requesting anonymity. He said Mr Karzai was very upset and angry over the incident.
Officials say rogue soldiers have tried to carry out at least 25 suicide attacks in the past two months.
Afghan security forces managed to prevent nine of them, Gen Wardak told the country's parliament recently.
A senior general with the country's interior ministry said suicide attacks by rogue soldiers was like a recurring nightmare.
"The only difference is that these nightmares turn into a reality."
One of the most audacious of these attacks was on a team of US special forces, which was teaching Afghan soldiers how to fire mortars in the eastern province of Nagarhar.
During a break from the training, an Afghan named Ezatullah, who had served with the border police for three years and had a spotless record, offered tea to the American trainers.
The trainers relaxed, put their weapons down and removed their flak jackets waiting for the tea to arrive. It was then that Ezatullah opened fire, killing six of the Americans on the spot.
Afghan policemen then killed Ezatullah, the chief of border police in eastern Afghanistan, Gen Aminullah Amarkhel, said.
The general said investigators later found songs promoting Taliban activities on his mobile phone. Gen Amarkhel said the Taliban had recruited Ezatullah some time ago.
An official working for Afghanistan's intelligence agency, the National Directorate of Security (NDS), in Jalalabad, said US forces were also responsible for the incident to a certain extent.
"They use the F-word," he said. "We have had complaints that Afghan soldiers are not given meal or prayer breaks when on training with American forces.
"All this hurts their sentiments and develops a breeding ground for anti-American feelings, which the Taliban exploits. We need to train not only the Afghans but also the Americans on how to behave when in the company of Afghans."
Flaws in the recruiting process are also being blamed for the attacks.
Aides close to Mr Karzai say the president is upset with his ministers in charge of building up Afghanistan's army and police for failing to carry out effective background checks on recruits.
"After one such incident, the president told some of his ministers: 'You are incompetent and irresponsible'," one official said.
"Seek guarantees from village elders and family members before recruiting anyone," he told the defence and interior ministers.
But a spokesman for the NDS, Lutfullah Mashal, says the Afghan government is now getting a handle on the problem.
"Intelligence officers have been instructed to go to the villages and talk to the friends, neighbours and others about the temperament, attitude, leanings and values of a potential recruit," he said.
"The Afghan National Army and police have been asked to carefully study the dossier prepared by the intelligence officers before offering a job to anyone."
He said background checks could prevent incidents such as the killing of the police chief of Kandahar province, Khan Mohammad Mujahid.
Mr Khan Mohammad was killed in a suicide attack carried out by his own bodyguard. The bodyguard had served Mr Khan for years and was known to enjoy a good rapport with him.
The attack left the establishment perplexed.
"How can we explain this to the people, especially the Americans?" an aide to Mr Karzai asked.
"He was not a Taliban 10 years ago, he was not Taliban five years ago. Of course, he was recruited recently. Why and how did we fail to detect this?"