Children's rights charity Just for Kids Law brought the case against the Home Office, saying that it breached young people's human rights and they were not given the necessary safeguards to protect them from harm.
However, Mr Justice Supperstone dismissed the case, concluding that he was satisfied the practice is lawful.
The judge did acknowledge that children are "inherently more vulnerable than adults" and that the "very significant risk of physical and psychological harm" to them being covert human intelligence sources in the context of serious crimes is "self-evident".
Despite this, he rejected Just for Kids Law's assertion that safeguarding provided for 16- and 17-year-olds in such circumstances was inadequate.
Enver Solomon, chief executive officer at Just for Kids Law, said it was disappointed with the ruling and is considering what further steps it can take.
Teenagers as young as 15 have been authorised as covert human intelligence sources, according to official figures.
As of March this year, 17 children across 11 areas have been taken on by police and other UK investigative agencies since January 2015 - a majority of them aged 16 and 17.
In one case, a 17-year-old female informant continued to be sexually exploited by the man she was gathering intelligence on, and was coerced into being an accessory to murder.
"We remain convinced that new protections are needed to keep these children safe," Solomon said. "The reaction we have had shows that despite the ruling, there is widespread concern among the public about the government's policy.
"The Home Secretary should act urgently to ensure that when the police find a child being exploited, their primary concern is to protect the child rather than allow that exploitation to continue."
Security minister Ben Wallace welcomed the judgment.
"The court recognised that the protections we have written into law ensure the best interests, safety and welfare of the child will always be paramount," Wallace said.
"Juvenile covert human intelligence sources have been used fewer than 20 times since January 2015, but they remain an important tool to investigate the most serious of crimes. They will only be used where necessary and proportionate in extreme cases where all other ways to gain information have been exhausted."