I'm not artist and don't know how to make those fancy computer drawings, so bear with me.
Looking at a flush fit on the right leg of the bed, I would add a block to the back of the ladder and secure it with a pin either into the rail of the bed, or by adding additional material along the bed rail that you can "pin" into. It would be removable, and the angle of the ladder will gain a little more support. The back side of the block should match the angle of the leaning ladder.
Due to the angle of the ladder above the block, it may not be possible to use a removable pin. You may need to just put in a small wooden dowel to protrude out of the underside of the block that would fit into holes on the rail or added cleat.
One concern with drilling pin holes into the rail would be that the rail itself is not very thick and removing material will weaken the rail itself. Adding a cleat to pin into would be ideal, but may not be very attractive, and I don't know if it would interfere with any doors/slides/etc.
Just an idea you might work around with a bit and see if it will work for you.
I guess you could just use a metal "L" bracket, bend it to the proper angle and insert a pin through it into the rail.. down n dirty style.