How to calculate rotation for a decal on a surface?

It’s a first person game, and the player can place things in the map. These things should be placed on the surface the player looks at. Kind of like how it works in Rust, but I just need a decal, not a ghost mesh (at 0:49):

?v=9N3cyurLf70

I am able to correctly position and rotate the decal, so that it is on the surface that the player is looking at:


However the rotation around the surface normal is not how I want it:


Imagine, that cube in the last picture would rotate around the Z axis. I’d like the decal to rotate with it, and always be aligned to the cube’s edges. Just like in the first image.

I hope this makes the problem more clear and thanks for trying to help!