There are various solutions to this problem. They range from diy circuits to IC's built for this specific purpose.
The most basic circuit uses series diodes with every supply rail. This does mean you lose power in the diodes as they have a voltage drop. It might not be a problem for you if you are dealing with very low-power devices that draw almost no current and power is not a constraint.
You can also use a parallel diode with a very small series resistor. This parallel diode would be reverse biased in normal operation, but become forward biased on reverse-power condition. In this case, the diode will shunt the rails. This does mean there will still be the forward voltage of this diode on your rails, and this could still pose an issue.
The better methods is to use series MOSFETs. They will turn on if the power is connected correctly, and turn off when it is reverse. The advantage is that they can have a far lower voltage drop. You can use a simple resistor devider or such to wire this up, but there are also ICs that can do this for you.
Simple example of the series FET would be like in the example on this hackaday page:

More information can be found in this TI appnote