Britain's Court of Appeals has ruled the UK government is breaking the law with its measures to collect internet activity and phone records of its citizens.
The Data Retention and Investigatory Powers Act (DRIPA) was originally passed in 2014 after the EU Court of Justice ruled the previous data collection scheme was unlawful.
DRIPA allowed for the collection of phone and internet records of UK citizens by communications companies. The information stored by the companies consisted of location history and details about calls, emails and text messages.
According to the UK government, the stored data was only to be used in criminal investigations and with sufficient presumption the person being investigated was involved in a crime.
However, critics said the DRIPA act violated the privacy of UK citizens and allowed authorities and other public bodies to access the collected data without proper oversight.
The Court of Appeals agreed with the critics, saying DRIPA was "inconsistent with EU law", and that access to the data was "not restricted solely to fighting crime".
Tom Watson, the Labour MP who challenged DRIPA and Liberty, the civil liberties organisation that represented Watson in court, welcomed the decision in a joint statement.
"This legislation was flawed from the start. It was rushed through Parliament just before recess without proper parliamentary scrutiny," Watson said in a statement.
"No politician is above the law. When will the Government stop bartering with judges and start drawing up a surveillance law that upholds our democratic freedoms," Liberty said.
Tuesday's ruling forces the UK government to scale down its more extensive Investigatory Powers Act, dubbed "snooper's charter" by critics, which replaced DRIPA in 2016.
Although DRIPA has been replaced, much of its content was used in the by the Investigatory Powers Act. As a result, the snooper's charter, will have to undergo significant changes to make sure it adheres to the law.
"This judgment tells ministers in crystal clear terms that they are breaching the public’s human rights. The latest incarnation of the snooper's charter, the Investigatory Powers Act, must be changed," Liberty said in its statement.
The Investigatory Powers Bill requires websites to keep customers' browsing history for up to a year and allow law enforcement agencies access to help with investigations.
The bill gives legal footing to existing but murky powers such as the hacking of computers and mobile phones, while introducing new safeguards such as the need for a judge to authorise interception warrants.
Critics have said that, in authorising the blanket retention and access by authorities of records of emails, calls, texts and web activity, it breaches fundamental rights of privacy.
The UN's special rapporteur on the right to privacy, Joe Cannataci, criticised the bill in his March 2016 report, saying "privacy-intrusive measures such as bulk surveillance and bulk hacking, as contemplated in the Investigatory Powers Bill, be outlawed rather than legitimised".
After Tuesday's ruling, Labour MP Tom Watson hopes the government will change the snooper's charter as well.
"The Government must now bring forward changes to the Investigatory Powers Act to ensure that hundreds of thousands of people, many of whom are innocent victims or witnesses to crime, are protected by a system of independent approval for access to communications data," Watson said.
"I'm proud to have played my part in safeguarding citizen's fundamental rights."