But this example works and, I assume, is intended to work over localhost. How would cross origin detection work in this case?
I understand that the generic answer will be along the lines: "well, if you have local access, you're never safe", but there is zero protection here. Anything local can connect to it and impersonate the "front end".