A federal judge in San Francisco has ordered the FBI to stop issuing “national security letters” to phone companies and Internet service providers, denying the bureau an investigative tool it has used with alarming frequency to secretly gather logs of Americans’ calls, e-mails and related activity.

It was the second time a federal court found a key aspect of such letters — the gag order that almost invariably accompanies them — to be unconstitutional. Congress should swiftly change the law to bring more oversight to the process and narrow the letters’ use.

Congress created the letters in the 1980s to help the FBI track communications by foreign agents in the United States without a court’s prior approval or oversight, but over time lawmakers broadened the letters’ use and reach. The USA Patriot Act ushered in the largest expansion, causing the number of letters to rise from about 8,500 in 2000 to more than 56,500 in 2004.

Critics worry that even though the letters don’t authorize the government to eavesdrop on targets, the “transactional” records about e-mail and mobile Internet usage, including e-mail addresses and potentially Web-browsing logs, are much more revealing than conventional telephone logs were. Just how revealing they may be is impossible to say, given that the law doesn’t compel the government to disclose what it collected from whom, even after an investigation is closed.

U.S. District Judge Susan Illston held last week that the law unconstitutionally prevented the courts from scrutinizing the government’s decision to keep a letter secret. The Second Circuit Court of Appeals had reached the same conclusion four years ago, requiring the FBI to create a way for recipients of the letters to challenge a gag order. Illston wasn’t satisfied, saying that only Congress could fix the law. To give the government time to appeal, though, she put her decision on hold for 90 days.

Rather than waiting to see whether Illston’s order stands up to appellate review, Congress should change the law now to give courts clear authority to review FBI gag orders. It also should require disclosure of the letters after a year unless the government demonstrates that it would harm national security. And lawmakers should consider what sorts of records are being collected to ensure that they’re truly “transactional,” not a shortcut to surveillance.