Image copyright AFP Image caption Canada's spy agency illegally kept and analysed metadata for a decade

Canada's spy agency is under scrutiny itself after a scathing court ruling said it was illegally keeping data on Canadians who posed no national security threat.

The programme had been going on since 2006.

Ottawa says it will ensure the spy agency is in is full compliance with Thursday's Federal Court decision.

The news came in the wake of revelations that police in Quebec had been spying on journalists.

The Federal Court ruling said that the Canadian Security Intelligence Service (CSIS) had been illegally keeping and analysing so-called "associated data", more commonly known as metadata, from third party communications.

That metadata, which could include the date, time, and telephone number linked to a phone conversation or an email address, was collected legally.

But it could only be retained if it was related to national security threats or of use to an investigation or prosecution.

It could also be kept if it was related to national defence or international affairs.

The court found CSIS was holding onto data from an unknown number of Canadians unrelated to threats or to the target of the warrants and that did not fall under any of those categories.

The spy service also failed to inform the court about that programme for a decade.

CSIS said it has suspended all access to and analysis of that metadata while it determined the its next steps .

Image copyright AFP Image caption Canadian Public Safety Minister Ralph Goodale

Canadian Public Safety Minister Ralph Goodale said on Friday that CSIS's compliance with the judgement will be supervised by Canada's security intelligence review committee.

Opposition New Democrat MP Murray Rankin called the retention of the metadata "a gross abuse of power and an unjustifiable intrusion into the privacy of Canadians" and said that Canadian spy agencies lacked oversight.

Canada is currently reviewing its national security laws and framework.

The court judgment added to an ongoing debate in Canada over police powers, press freedom and privacy following revelations that Quebec police had spied on at least seven journalists.

Image copyright Getty Images Entertainment Image caption Edward Snowden has spoken out against the surveillance of Quebec journalists

Quebec announced it will hold an inquiry into the surveillance of journalists by police forces in the province.

Prime Minister Justin Trudeau called the surveillance "troubling" and said nothing similar was happening at the federal police force level.

Two of the province's police forces admitted they had obtained court warrants to monitor phones owned by journalists in order to track sources linked to leaks.

NSA whistleblower Edward Snowden spoke out on the revelations, calling police actions a "radical attack on the operations of the free press".