It ended up being caused by my login link incorrectly passing on the referrer field. For some reason the field would get lost when I would enter my authentication code.
I have changed the method used for passing on the referrer field from my login links. I can no longer reproduce the problem. Thanks for your help. You definitely got me thinking on the right track for how to solve this problem.