Civil liberties groups took Britain's spy agencies to court Monday in a bid to limit electronic surveillance, as the country’s government tries to pass legislation to extend snooping powers.

A special court, the Investigatory Powers Tribunal, is hearing a challenge to mass online surveillance from groups including Liberty, Amnesty International and the American Civil Liberties Union.

The organizations claim that mass collection of individuals’ communications data breaches the rights to private life and freedom of expression.

“Not content with forcing service providers to keep details of our calls and browsing histories, the government is fighting to retain the right to trawl through our communications with anyone outside and many inside the country,” said Liberty legal director James Welch. “When will it learn that it is neither ethical nor efficient to turn everyone into suspects?”

The rights groups launched their legal action after leaks about cyber-spying from former U.S. National Security Agency (NSA) contractor Edward Snowden. He revealed details of a program called PRISM, which gives the NSA access to Internet companies' customer data, and a British operation, TEMPORA, that allows Britain's electronic spy agency to harvest data from undersea cables.

British authorities have not confirmed the existence of TEMPORA.

A lawyer for the British government contended in Monday’s hearings that intelligence capabilities in their current form, and the sharing of surveillance with the NSA, was imperative.

“There is a clear need for the intelligence services to be able to share intelligence, on a proportionate basis, with foreign intelligence partners,” James Eadie QC said.

The court action comes as the British parliament is set to take up debate on a bill that would force phone and Internet companies to store call and search records for a year.

The government has introduced the legislation in response to a recent European Court of Justice decision that ruled that a European Union directive requiring companies to store communications data for up to two years was too broad and a threat to privacy.

Prime Minister David Cameron says the new law does not extend existing surveillance powers, and is needed to protect the country from pedophiles, gangsters and terrorists.

The British legislation covers the collection of metadata, which make it possible for law enforcement authorities to identify subscribers and who they communicate with, as well as the time, place and frequency of communications. Such information doesn't include the content of any communications.

But critics, including Liberty, say it seeks to legalize activities that the European court has ruled unlawful.

At the time of its announcement last week, Shami Chakrabarti, director of Liberty, expressed doubt that there was really a critical need for Cameron's measures now.

"We are told this is a pedophile and jihadi ‘emergency’ but the court judgment they seek to ignore was handed down over three months ago and this isn't snooping on suspects but on everyone," she said. "We are promised greater scrutiny and debate but not until 2016, as it seems that all three party leaders have done a deal in private. No privacy for us and no scrutiny for them."

Al Jazeera and The Associated Press