Yes. European countries follow the regulations contained in the Agreement on Dangerous Goods by Road (ADR), which contains dozens of pages of regulations that do not apply to private individuals, provided that "measures have been taken to prevent any leakage of the contents under normal conditions of transport". You then simply have to comply with the Road Vehicles (Construction and Use) Regulations, which state, essentially, that the load must be secured so that it does not fall off. So, if you have a suitable container and strap it on properly, you're all set.
Predictably, most risks involve petrol leaking and turning you into a fireball.
Your container's seal leaks. This can happen through user error, but is often due to the fuel dissolving the lid seal because the container was not designed to carry fuel. The container leaks because the fuel has dissolved it.
The container isn't secured properly, causing you to lose control of the bike, or to go bumpy on the road and cause problems for others.
There are four options.
1) Strap a five litre petrol can to the back. This is the most basic option and is fine in an emergency, but the problem is that they are difficult to strap down securely. The shape is awkward, the straps can slip off and it's hard to keep them vertical (if you have doubts about the seal). If you can fit one in your tail pack, it's a viable long-term option.
2) Camping fuel bottles. These fuel bottles come in a variety of small sizes (e.g. 0.5 litres or 1 litre), which allows them to be stuffed into your basket. If you ride gently, a litre of fuel will get you at least 10-15 miles, which should get you off the motorway, though probably not to a petrol station. One litre in each basket is a better option. If you don't like to keep petrol next to your clothes, you can zip tie or clip them to the stays of your frame.
3) Stackable storage tanks. They can be bolted to the frame, rear rack or engine bars, and each tank will give you between 4 and 20 litres of extra fuel - and you can double them up for the full revelation spec.
4) Auxiliary fuel tank and larger main fuel tank. Auxiliary tanks are usually placed on the passenger seat and connected to the main fuel line - you can turn a tap to open them. Larger main fuel tanks are popular among off-roaders using smaller off-roaders, although some GS owners fit larger tanks from proper adventure models.