Oil on the back of brake pads? I noticed that the pistons on my hydraulic brakes (Shimano M365) leave traces of oil on the back of the pads. Is that ok or it is considered as a bad leak?

The quantity of oil is barely noticeable but it's there. The pads are not contaminated at all. 

I should note that the system needs a proper bleed.

Edit : I forgot to mention that the system features an "automatic compensation" for brake pad wear. I am guessing it just lets a little bit of air inside when the pistons extend too much, which could explain the leakage.
It's not good but it's a fairly common problem and there's nothing you can really do about it short of replacement. Shimano doesn't sell replacement caliper internal parts or rebuild kits. 

Oil there is capable of getting worked on to the pads or rotor, possibly causing sudden loss of braking power.

Pistons getting extended too far is something that should only happen by accident when the wheel is out. If it leaked some oil then and only then, that's not something to be alarmed about. Likewise, if it only leaks immediately following a bleed, or it had some leakage there when new but not again, that's annoying and not something it "should" do, but probably (and only probably) not an indication of bigger or imminent problems.

If it does it all the time in normal use, I'd recommend replacement.