How can you stop your missile locking onto a friendly target? In the modern day we have advanced planes, and advanced missile systems, however, how can you stop your missile firing at a friendly aircraft?

In planes like the F22 Raptor you can turn on sight lock, which is when you look at a plane through your helmet, the computer registers that there is a plane there, and it locks onto the plane with a missile.

However, let's say a friendly aircraft were to fly in front of you when you had sight lock turned on; would the missile fire at the friendly aircraft, or is there a piece of technology in the friendly aircraft which registers that it's with you? If so, could that potentially be used against you in modern day aerial warfare?
First off, very rarely will you shoot at an unidentified aircraft.  Most engagements require a visual ID, or a hostile action, prior to engagement. However, you will also program your aircraft with specific ROE logic that will indicate that certain aircraft are friendly, as identified by IFF transponders, Link 16, etc.

You can still lock up friendly aircraft, and we frequently do to facilitate rendezvous with friendly aircraft and to clear ourselves from traffic, but if your master switch goes to ARM and you have a friendly locked up, there's a good chance you won't be flying again for awhile, if ever.

When we lock up an aircraft, 99% of the time, it does not indicate an intention to shoot.  By using our radar and "locking up" a target we get target aircraft altitude, speed, range, target aspect, heading, $Vc$, etc, all useful things that come in handy for routine events.