Here is one method:
simulate this circuit – Schematic created using CircuitLab
If the errant user leaves the +12 on there the resistor will see almost half a watt and the transistor a few hundred mW. You could increase R1 to a few hundred ohms to reduce both those numbers. Note that the input current is diverted to ground through Q1 rather than into the +5V supply. The latter can cause unwanted side effects.
This is still dependent on the characteristics of a PN junction so the clamp voltage will change with temperature and there will be some leakage as you approach the clamping voltage. You can play with R2/R3 ratio to change the clamping voltage and even try to make it temperature dependent with a thermistor or diode to a higher voltage source but it's far from perfect.
If you want something more precise, especially over temperature, you'd probably have to combine an active op-amp clamp with something like the above to handle fast transients.
Edit: As Jack Creasey mentioned in a comment, in this case R2 can be replaced with a diode or a transistor with collect tied to base (ideally in a dual NPN-PNP transistor array) to give better temperature compensation. You can add a small resistor in series to give a bit more headroom if you want to be able to go closer to the supply rail.