Hong Kong’s High Court on Friday banned people from disclosing personal information about the police and their families, widely targeted in protests that have gripped the Chinese-ruled city for months, prompting concern among legal experts.

Pro-democracy activists have attacked police with petrol bombs, rocks and lasers shone in their eyes, furious at social media footage of random beatings, especially one against protesters cowering on the floor of a subway train.

One officer this month was slashed in the neck with a knife.

Police have responded to the violence with tear gas, water cannon, rubber bullets and occasional live rounds, wounding several.

The court agreed to an injunction, including a broad ban on “harassing” and “pestering”, which media said would last until 8 November.

Hong Kong protesters out in force after months of turmoil: In pictures Show all 32 1 /32 Hong Kong protesters out in force after months of turmoil: In pictures Hong Kong protesters out in force after months of turmoil: In pictures A protester throws a stone into a building at Hong Kong Polytechnic University on 11 November Reuters Hong Kong protesters out in force after months of turmoil: In pictures Police patrol the streets of Hong Kong the day after an officer shot a protester during a protest on 11 November EPA Hong Kong protesters out in force after months of turmoil: In pictures Riot police stand guard during a protest against police brutality in Hong Kong on 27 October EPA Hong Kong protesters out in force after months of turmoil: In pictures Protesters carry traffic cones to build a barricade during anti-government protests in Causeway Bay, Hong Kong on 11 November Reuters Hong Kong protesters out in force after months of turmoil: In pictures Protesters use obstacles and bricks to block a road in Hong Kong on 11 November AP Hong Kong protesters out in force after months of turmoil: In pictures Graffiti on a window smashed by student protesters in Hong Kong Polytechnic University AP Hong Kong protesters out in force after months of turmoil: In pictures Protesters carry US and British flags during a demonstration in Hong Kong on 11 November Reuters Hong Kong protesters out in force after months of turmoil: In pictures A protester throws a bottle of water as he is shrouded in tear gas during a demonstration in the Tsim Sha Tsui district of Hong Kong on 27 October Reuters Hong Kong protesters out in force after months of turmoil: In pictures Journalists take pictures of police officers as they move to disperse protesters in Hong Kong on 27 October Reuters Hong Kong protesters out in force after months of turmoil: In pictures An man lies injured after being attacked by protesters who suspected him of being an undercover police officer on 27 October EPA Hong Kong protesters out in force after months of turmoil: In pictures A man runs among tear gas during a protest in Hong Kong on 27 October Reuters Hong Kong protesters out in force after months of turmoil: In pictures Protesters gather on a field in the Tsim Sha Tsui district of Hong Kong on 27 October Reuters Hong Kong protesters out in force after months of turmoil: In pictures Pro-democracy protesters turn away from a fire lit outside the Causeway Bay Mass Rapid Transit (MTR) station in Hong Kong on 4 October Getty Hong Kong protesters out in force after months of turmoil: In pictures People rest near rows of riot police officers during a protest in Mong Kok, Hong Kong on 27 October Reuters Hong Kong protesters out in force after months of turmoil: In pictures Pro-democracy protesters hold umbrellas as police fire tear gas at them ouside Tai Koo MTR station in Hong Kong on 3 October Getty Hong Kong protesters out in force after months of turmoil: In pictures Hong Kong police fire a water cannon from the central government office at protesters during a mass rally on the 70th anniversary of the founding of communist China on October 1 AFP/Getty Hong Kong protesters out in force after months of turmoil: In pictures Protesters burn a Chinese national flag during a mass rally on the 70th anniversary of the founding of communist China on 1 October AFP/Getty Hong Kong protesters out in force after months of turmoil: In pictures Protesters remove signs celebrating the 70th anniversary of the founding of communist China during a mass rally in Hong Kong on 1 October AFP/Getty Hong Kong protesters out in force after months of turmoil: In pictures Cardboard boxes set alight by protesters burn in the streets of Hong Kong during a mass rally on the 70th anniversary of the founding of communist China on 1 October EPA Hong Kong protesters out in force after months of turmoil: In pictures An anti-China banner has been placed in a barricade during a mass rally on the 70th anniversary of the founding of communist China on 1 October EPA Hong Kong protesters out in force after months of turmoil: In pictures A pro-democracy protester runs away after police fire a tear gas canister in Hong Kong's Wong Tai Sin district on October 4 Reuters Hong Kong protesters out in force after months of turmoil: In pictures Protesters run after police fire tear gas during a mass rally on the 70th anniversary of the founding of communist China on 4 October AFP/Getty Hong Kong protesters out in force after months of turmoil: In pictures Pro-democracy protester take cover after police fire a tear gas canister in Hong Kong's Wong Tai Sin district on 4 October Reuters Hong Kong protesters out in force after months of turmoil: In pictures The rally comes after months of protests on the streets of Hong Kong which began in oppposition to a proposed extradition bill EPA Hong Kong protesters out in force after months of turmoil: In pictures The extradition bill would have allowed the government to extradite people to China if they were facing certain criminal charges AFP/Getty Hong Kong protesters out in force after months of turmoil: In pictures Opposition to the bill stems from the fear that the Chinese government would abuse this power for political or commercial reasons EPA Hong Kong protesters out in force after months of turmoil: In pictures Protesters soon came to demand greater freedom and universal suffrage under the One Country, Two Systems principle AFP/Getty Hong Kong protesters out in force after months of turmoil: In pictures Protesters are wearing black to symbolise opposition to China as they take to the streets in a "day of grief" while the Chinese state celebrates the 70th anniversary of its communist founding AFP/Getty Hong Kong protesters out in force after months of turmoil: In pictures A protester charges forward holding umbrellas as a mass rally breaks out in violence in Hong Kong on 1 October AFP/Getty Hong Kong protesters out in force after months of turmoil: In pictures A protester pours water on a tear gas canister fired by police during a mass rally on the 70th anniversary of the founding of communist China on 1 October Reuters Hong Kong protesters out in force after months of turmoil: In pictures A protester carries a vandalised Chinese flag through Hong Kong during a mass rally on the 70th anniversary of the founding of communist China on 1 October EPA Hong Kong protesters out in force after months of turmoil: In pictures Protesters carry a banner that denounces the celebration of the 70th anniversary of the founding of communist China on 1 October EPA

Professor Simon Young, of the University of Hong Kong’s law school, told Reuters that the move effectively amounted to a law targeting a select group – a serious move which should be dealt with through new legislation, not an injunction.

“It opens a whole new can of worms and questions about enforcement,” he said. “It reflects the dysfunction of the legislative process that injunctions are being used in this way.”

Hong Kong-based lawyer and author Antony Dapiran said the injunction was a “very alarming development”.

“Serious restriction on freedom of expression effectively criminalises a whole range of perfectly lawful acts which will now be punishable as contempt of court,” Mr Dapiran wrote on Twitter.

Protesters are angry about what they see as creeping Chinese interference in Hong Kong, which Britain returned to China in 1997 under a “one country, two systems” formula intended to guarantee freedoms that are not enjoyed on the mainland.

China denies meddling. It has accused foreign governments, including the United States and Britain, of inciting the unrest.

The police and justice secretary applied for a ban on disclosing names, addresses, email addresses, telephone numbers and other details, including children’s school addresses.

Police said in August more than 1,600 officers and their family members had been victimised by doxxing – the publication of private information online.

“They also suffered all sorts of harassment, including nuisance calls, verbal intimidation and even death threats,” police public relations branch Chief Superintendent Tse Chun-chung said at the time. “Some people misused our officers' personal data to apply for loans.”

The rallying cry of the protest movement is “five demands, not one less”, including universal suffrage and an independent inquiry into perceived police brutality, which leader Carrie Lam has refused to grant.

Hong Kong is now in its fifth month of protests, which have plunged it into its biggest political crisis in decades and taken a heavy toll on the economy.

Hong Kong protesters clean mosque after police spray it with blue liquid

A rally dubbed “Medical Workers Resisting Tyranny” is planned at Chater Garden in the heart of the financial centre on Saturday, with another protest, “Fight Against Police Brutality, Stand with Muslims, Citizens and Journalists”, due on Sunday across the harbour in Kowloon district.

A police water cannon truck shot bursts of blue-dyed water at a small clutch of people on the footpath outside a mosque during protests in Kowloon on Sunday, hitting its gate and steps, drawing criticism from some in the Muslim community.

Police said the incident was “most unfortunate” and unintended, while senior officers met Muslim leaders to offer apologies.

US vice president Mike Pence accused China on Thursday of curtailing “rights and liberties” in Hong Kong and blasted US company Nike and the National Basketball Association for falling in line with Beijing in a disagreement over free speech.

Chinese Foreign Ministry spokeswoman Hua Chunying denounced Mr Pence’s comments and said the United States should reflect on its own domestic issues, like gun violence.