The following editorial appeared in the Miami Herald on Thursday:

A misguided ruling by a federal appeals court on press freedom last week underscores the need for a federal shield law that protects the news media's right to report on wrongdoing in the government and mischief by public officials.

The U.S. Court of Appeals for the 4th Circuit, based in Richmond, Va., declared in a 2-1 ruling that New York Times reporter James Risen must testify in the trial of a CIA operative charged with leaking classified information to him. The decision undermines the First Amendment privilege and gives the government unchecked power to intimidate Risen and other reporters who refuse to reveal their sources.

As Judge Roger Gregory noted in his dissent, the majority's ruling "severely impinges on the press and the free flow of information in our society."

It would compel reporters to reveal confidential sources in a criminal trial, effectively discouraging whistle-blowers in the government from coming forth. Fearing government retaliation, news organizations would be obliged to think twice before going public with information based on leaks by employees on the public payroll.

The government would no doubt prefer a lap dog to a watchdog, but the public would be the big loser. Hard-hitting journalism that uncovers wrongdoing in government provides information on some of the most important issues in the realm of public affairs, promotes transparency and keeps public officials on their toes.

The court's ruling should give Congress new impetus to enact a federal shield law, which the Senate Judiciary Committee will consider on Thursday. It is the best way to protect the public's right to know without damaging national security.

The proposed law protects journalists who are doing their job against being compelled to reveal their sources, but also requires courts to apply a balancing test to safeguard the public. Exceptions would include instances when the government seeks information that could be used to prevent terrorism attacks and when information sought from reporters can help prevent harm to others.

The bill would transform into law a set of guidelines issued by the Obama administration in response to the public backlash over disclosures that it had seized phone records and emails from reporters without notifying the news media beforehand.

The administration rules issued after the embarrassing disclosures of its overreach aren't enough. A law will guard against the possibility that a future president or attorney general, or the current ones, would try to get rid of the current guidelines at a later time.

One provision would not allow the Justice Department to delay notifying a reporter or news agency when their records are being sought for more than 90 days.

Another would broaden the guideline ban against seizing records, which currently is limited to cellphone companies and email providers, to include other documentation, like business and credit-card company records.

The law would also ban the use of search warrants to go after a reporter's records unless the reporter was under investigation for activity that did not involve gathering the news.

Congress has tried and failed several times to approve a federal shield law. This time it must not fail.

The Risen ruling and the administration's overzealous efforts to seize reporters' records should be enough to persuade legislators that the need to enact such a law is more compelling than ever.