Police seeking to identify a journalist's source by accessing communications data will need the approval of a judge before going ahead under a new code of conduct, MPs have been told.

Security Minister James Brokenshire urged the Commons to agree to the new rules on communications data, which can be used by police and other law enforcement agencies to identify who spoke to whom, by what method, and at what time, but without accessing the content of a conversation.

The new measure is contained in one of two new codes of conduct dealing with the acquisition and retention of communications data. The codes are contained in statutory instruments which must be approved by MPs and peers.

Mr Brokenshire said the measure would enact a recommendation by the Interception of Communications Commissioner Sir Anthony May.

The minister told MPs: "Communications data policy can broadly be split into two areas - acquisition and retention. Acquisition is carried out by relevant public authorities such as law enforcement agencies, retention is carried out by communication service providers.

"The two codes of practice we are debating today... set out the processes and safeguards governing the retention and acquisition of communications data. They are intended to provide clarity and incorporate best practice on the use of the relevant powers, ensuring higher standards of professionalism and compliance in this important aspect of law enforcement.

"One of the most important new safeguards, contained in the acquisition code, (is) that of access to journalistic material. As MPs will know, the Interception of Communications Commissioner recently conducted an inquiry into police acquisition of journalist's communications data.

"The measures contained in the revised code are intending to give effect to his recommendations which were accepted straight away by the Government.

"The acquisition code we are debating now now stipulates law enforcement must use production orders under the Police and Criminal Act 1984, or its equivalents in Scotland and Northern Ireland, when seeking to acquire communications data to identify or determine the source of journalistic information. We are doing this because production orders require judicial approval.

"This will help protect the freedoms journalists enjoy in the UK. Whenever law enforcement are seeking the journalist to determine sources - and this includes where police are seeking to confirm or corroborate other evidence of the identity of a journalist's sources - the decision on the application will be made by a judge.

"However, this is only a stop gap until we can make this change in primary legislation in the next Parliament."

The measures, which also introduce a maximum £50,000 fine for airlines that carry people who are on the British no-fly list either into or out of the country, were passed unopposed by MPs.

Home Affairs Select Committee chair Keith Vaz criticised the introduction of a fine for airlines, after finding out from Mr Brokenshire that no air carrier had actually broken the rules before.

After Mr Vaz asked how many times an airline has carried someone when asked not to by British authorities, Mr Brokenshrie replied: "I can perhaps reassure you that the circumstances that you describe, certainly to my knowledge, has never occurred and we would not wish to see it happen and I think that that underlines the purpose and utility of having the authority to carry scheme in place.

"But I do say to you that we think that that it is important to have a penalty in place nonetheless.

"Clearly you have a scheme that sets out those requirements but it needs to have enforcement and the ability to be able to rely on that to ensure that there is good compliance with the scheme."

Mr Vaz said he did not support bringing in new laws to cover a problem that did not exist, and stressed that civil penalties are often left uncollected.

The Labour MP said: "I have no problem in principle with what you are proposing but you have basically told the House that this has never happened so far.

"That a carrier being asked not to carry has then defied the Government, either inbound or outbound and said we are going to carry this person."

He added: "I just feel that we should legislate when we know that there is a problem and we finally got out of the minister the fact that it has never happened, there has never been a situation where it is happened, and therefore here we are passing legislation to stop something that's never happened.

"But what you are saying to us is this is very important to have in your back pocket because you never know when you might need it and you never know when you might be able to wave it in front of carriers and say if you don't do this then you will be fined.

"My real objection to civil penalties is that the amount of these penalties that are collected by the Government is lamentably small."

Meanwhile, shadow security minister Diana Johnson criticised the codes of practice on communications data for being vague on whether social media messaging would be covered.

The Labour frontbencher said there was a section on fixed line telephone calls and also on electronic messages, but stressed that social media was not mentioned explicitly.

Ms Johnson said: "This is fine as far as it goes and it was probably all that was needed perhaps 20 or 30 years ago, but this code of practice is for 2015 and beyond and the way we communicate now, I'm sure you will accept is very different from just having fixed telephone lines.

"Fixed telephone calls are a small element of communications and when we look at internet-based communications from email to app-based messaging, to social media, the code of conduct I think is too vague in what it's actually trying to do."

On the definition of electronic messages, she said: "Is this simply a definition of internet-based email providers such as Hotmail and Gmail?

"Or is this definition meant to include social media?

"If it is meant to include social media why doesn't it actually say that so it's very clear in the code of practice?"