Twitter users who revealed details of Ryan Giggs's alleged affair with Imogen Thomas could face legal action, according to the government's senior law officer.

Attorney General Dominic Grieve said that individuals could be prosecuted for contempt of court if they use the micro-blogging site to publish sensitive material.

Twitter played a key role in the exposure of Manchester United footballer Ryan Giggs's purported affair with glamour model Imogen Thomas after MP John Hemmings argued in the House of Commons that it was not possible to prosecute 75,000 of the site's users who had named Giggs.

Alleged details of a number of other injunctions have been anonymously posted on Twitter including details of a married actor who supposedly had an affair with a colleague.

Giggs's lawyers have subsequently applied for a disclosure order in an attempt to force Twitter to hand over details of those who first revealed his name in connection with the alleged affair.

Enforcement was usually at the discretion of whoever had taken out a privacy order, Grieve said.

But he told the BBC he would take action himself if he thought it essential to maintain the rule of law.

In an interview with Radio 4's Law in Action programme, the attorney general said that individuals who used Twitter or other internet sites to undercut the rule of law could face the consequences of their actions.

"I will take action if I think that my intervention is necessary in the public interest, to maintain the rule of law, proportionate and will achieve an end of upholding the rule of law," Grieve said.

"It is not something, however, I particularly want to do."