There has never been any offence of undertaking, or to be more precise, it was removed from the statute books when the 1972 Road Traffic Act was introduced.
It was removed mainly because of the queues that formed close to junctions on multi lane roads such as motorways, where lanes 2 and 3 were solid but lane 1 was empty thereby allowing for traffic in that lane to continue. However, it also allowed for the numpties that still believe that we have slow fast and overtaking lanes and choose to sit in lane 2 on an empty motorway.
The only option is to report for either careless or dangerous driving, but to prove this offence, it has to be proved beyond all reasonable doubt that the standard of driving or riding fell well below that accepted of a reasonably safe and competent driver or rider.
The simple act of undertaking is insufficient to establish that offence.
So for example, if you are travelling in lane 1 on an empty Motorway and you have the idiot ahead is hogging lane 2 and you choose to go past on the nearside, no offence.
However, if you went past in lane 1 and then swerved into lane 3 and then back to lane 1, then that may be sufficient to prosecute for the section 3 careless driving offence.
If you go past in lane 1 and the idiot in lane 2 suddenly switches back to lane 1, then primary liability lies with the driver in lane 2 because they have a statutory duty of care to ensure that it is actually safe to return to the nearside lane.
Remember, the lane 2 hogger themselves commit the offence of careless driving, or specifically driving without reasonable consideration for other road users which is a sub section of careless driving.
Speed has no bearing. and there is no speed set in law that makes it legal or illegal, it is what is appropriate for the circumstances, it is a judgement call made at the time, and in fact in a couple of successful filtering cases the rider was filtering (overtaking) in excess of 50mph and was not found liable.
As far as the Highway Code is concerned, remember these are a set of rules and guidelines unless it states "Must Not" and is then supported by the appropriate traffic regulation or act. If it states "Should Not" it is advice and is not supported in law.
So, whilst not illegal, it is about making a judgement call, and you have to balance out that judgement with the possibility of being taken out by some blind careless idiot.
I got stopped by a traffic plod a few weeks ago for an undertake in the early hours of the morning. He started to tell me my fortune about how illegal it was, so I calmly asked him for the act and section that made it illegal? So I got the bluster about how he would ensure that my licence was taken and, and, and...........
So I asked again, what act and section, I simply wanted a simple answer to a simple question.... Again I got the bluster at which point I got fed up with his lack of knowledge and I asked him to report me and we could have our day in court and he could explain to the magistrates what offence he had reported me for.
I then got the puzzled look. So I explained the law to him
He said something along the lines of "You seem to know a lot about traffic law" I then told him a bit of my history. The look on his face was a picture
And this is half the problem these days. Poor policing standards from coppers who are themselves not properly trained anymore, and the fact that they can get away with giving members of the public a load of BS who are unable to defend their position because they themselves are non the wiser.
A couple of weeks later, I was followed through on the undertake in a different part of the country by a police car, and they promptly pulled the lane 2 hogger
So rest assured, undertaking is not illegal if done properly, and even in civil cases, it is being accepted that a rider or driver who is hit whilst undertaking may not be immediately or primarily liable.
Hope that helps.
It is better to arrive 30 seconds late in this world than 30 years early in the next