Alex Rivera | Logout

Should I verify HTTP Referer in OAuth 2 Callback?

Asked 2012-03-29T20:06:04.170
8

I am successfully able to authenticate Facebook and Google accounts using my Oauth2 servlets. I am using state with a timer and a session cookie to try to verify that it is indeed a legitimate Oauth callback.

  1. Is there any benefit if I also examine the HTTP Referer header to ensure that I was redirected from the provider's OAuth page?

  2. If no benefit, could there be a problem if I also examine the HTTP Referer field?

Edit
Report

1 Answer

-1

Plain security was not a concern of the question because the state parameter is being used.

The main concerns I had in mind were:

  1. Whether it is the same browser that my app sent to Facebook that's coming back to present a candidate token?
  2. Whether the agent (browser-like agent) or agents are repeatedly doing OAuth requests and presenting me with bad OAuth tokens that cause my app to repeatedly contact Facebook with bad tokens leading to potentially adverse treatment by Facebook.

The only possible solution to the first problem is to also set a cookie in addition to using state. referer would help if most providers weren't using https.

The second problem has a nuance. The mis-behaving agents need not be directly controlled by a malicious entity. They may be normal users browsers redirected via some indirect means (a popular hijacked website, social engineering).

Because of the nuance there is a chance that the referer header may not be forged. However, https precludes any meaningful benefit.

Cookies definitely help in the second case also because if you are setting cookies in a POST no third-party website can cause them to be set and you cannot be flooded with bad OAuth responses due to hacked websites redirecting users en masse to OAuth you.

This is not a clear answer (or question) but hopefully this shows the nuances behind the question.

answered 2012-04-09T17:58:24.650

Your Answer