Fix XSRF protection.

This fix correctly extracts the XSRF token from the HTTP header and
raises exceptions if anything fails in the process.
Fix detection for already existing files.

The fix first builds absolute paths and then runs the check on it.
Besides, the fix adds meaningful error messages for raised exceptions.