"The CBSA uses DNA testing in order to determine the identity of longer-term detainees when other avenues of investigation have been exhausted," spokesman Jayden Robertson said.
The agency said the testing assists in "determining identity by providing indicators of nationality thereby enabling us to focus further lines of investigation on particular countries."
It always obtains consent from the individual before submitting their DNA to these websites, it added.
Toronto immigration lawyer Jared Will, who represents several people who had their DNA analysed in order to establish their nationality, disputes that.
"In my experience, the CBSA has made these requests to detainees who are then accused of non-cooperation with removal efforts if they decline, and that non-cooperation is then invoked as a justification for continued and prolonged detention," he told AFP.
"In other words, while the detainees may formally give their consent, the validity of that consent is dubious," he said.
Others noted that one's ethnicity or family ties may not determine their nationality.
Scrutiny of the practice comes as Canada announced on Monday it was expanding the collection of biometrics like fingerprints and photos for refugee claimants, individuals facing extradition and foreign nationals seeking a temporary resident visa, work permit or study permit.
Border security has become a political hot potato with the arrival on foot from the United States of 30,000 asylum seekers since January 2017 putting strains on Canada's refugee system and provoking a public backlash.
According to court documents, migrant Ebrahim Toure spent more than four years in Canadian detention pending removal. He initially refused a DNA swab but eventually relented last year.
Toure had arrived in Canada in 2011 using a fraudulent French passport and was ordered deported.
He later claimed to be a Guinean national, so Canada tried to send him there. But on arrival at the Conakry airport, Guinean officials refused him entry, saying a birth certificate he provided was fraudulent. They also noted that he didn't speak French, the official language of Guinea.
The CBSA subsequently examined his Facebook account that listed 48 friends mostly from Gambia, interviewed members of Toronto's Gambian community who knew him, concluded from a linguistic analysis that he was "very likely" Gambian, and sought to match his DNA on genealogical sites to relatives in Gambia.