Legal or not, there is a simple fix I have used many times and it is safe!
First, get a length of heat shrink that is appropriately sized to fit over the cable
Then strip a couple of cm of shielding from each of the original and the extension cables
Solder the two together - make sure the solder joint is as perfect as you can get it, meaning all around and through both sections - not just on the surface
Slide the heat shrink over the joint, making sure it covers the joint completely, then apply heat to shrink it
Finally, just for security reasons, put the joined section into a good quality plastic box and screw on the box lid. (These boxes are readily available from most good hardware stores or any electrical supply shop)
Hope this helps