The court of appeal’s ruling in the case of David Miranda’s 2013 detention at Heathrow is indisputably an advance for press freedom. It establishes with very great care, balancing the needs of security and the rights of journalists, that existing police anti-terror powers to stop and question travellers in and out of this country are incompatible with freedom of expression protections under the European convention on human rights.

That judgment should be strongly welcomed by all news organisations and journalists, since the media’s ability to protect confidential sources was otherwise wide open to real abuse, as the Miranda case proved. The government, which has behaved as though no such need for balance exists, is now under an obligation to respond with changes to the law. It should make clear in parliament that it will do this soon.

The ruling does not protect Mr Miranda, who was stopped when carrying material from the Edward Snowden revelations. But it re-establishes the principle, which the Guardian always pressed in the Snowden case, that Mr Miranda should have had the protection of a public interest defence against his detention. The stop powers in schedule 7 of the Terrorism Act 2000 are very sweeping. In some years, as many as 85,000 people have been stopped, overwhelmingly Muslims. Tuesday’s victory is important for journalism, but the stop powers need to be well scrutinised in other respects too.