The way your body detects foreign cells is the same way your body detects foreign cells. It detects anything that doesn't have your, specific, randomly-generated at conception, friend-or-foe markers.
Once you start looking at even more factors, you start reinventing a regular DNA-matching test.
[0] The "Birthday Paradox" makes the odds of confusion even higher with more siblings.