raven-python icon indicating copy to clipboard operation
raven-python copied to clipboard

Lack of origin variable in sentry_data causing X-Sentry-Error:Missing required Origin or Referer header

Open SizeSeeker opened this issue 12 years ago • 9 comments

I'm an intermediate programmer so I apologize if this is in error! I'm getting Missing required Origin or Referer header as part of a 400 response, even though I've set SENTRY_ALLOW_ORIGIN = "*" in my settings.py file. I think the issue is that my sentry_data query string only sends a referer variable, not an origin variable. In raven-python/raven/contrib/django/views.py, line 48, origin = request.META.get('HTTP_ORIGIN') returns nothing for me. I was looking at the source in sentry/src/sentry/web/api.py and there they put

def get_request_origin(self, request): """ Returns either the Origin or Referer value from the request headers. """ return request.META.get('HTTP_ORIGIN', request.META.get('HTTP_REFERER'))

which defaults to the referer variable if the origin variable isn't present (as in my case). Does it make sense to add that line on line 148 here? Thanks for your time, I couldn't find a way to include the HTTP_ORIGIN variable in my query string so decided to post here, sorry if this isn't a correct issue!

SizeSeeker avatar Oct 07 '14 09:10 SizeSeeker

I would actually avoiding using the undocumented proxy views contained in raven-python.

dcramer avatar Oct 08 '14 04:10 dcramer

Actually I think this ticket is invalid so I'm going to close it out.

The header/origin are HTTP variables (not the sentry headers), and these come from the JS client.

dcramer avatar Oct 14 '14 13:10 dcramer

I still think this is an issue. I just spend several hours trying to figure out why 7.1.4 won't accept any requests. I then did the following:

  • Started completely from scratch (removed everything related to Sentry)
  • Installed 6.4.4
  • Configured Raven.JS with the correct API key
  • Saw it actually made an event in Sentry
  • Shut down Sentry, upgrade to 7.1.4
  • Made sure the config.py was setup correctly (like before the upgrade)
  • Start up again, get the message "Missing required Origin or Referer header"

I didn't change the API key, but suddenly it doesn't work. I can see in the request that doesn't send the Origin header, only the Referer. But that didn't change from before the upgrade. By the way, the http status is 200, not 400 (at least in my case).

grbrigsted avatar Feb 04 '15 13:02 grbrigsted

We test both Origin and Referrer. If it's sending it, then the server is declining it based on some other reason.

dcramer avatar Feb 04 '15 15:02 dcramer

Do you have any suggestions on what to do from here? It works on 6.4.4, but not on 7.1.4, even though nothing changed (except Sentry, of course). There's only one place in the code where that statement can come from (web/api.py). This means that origin is None (and not is_valid_origin), even though Access-Control-Allow-Origin is set to the exact same string as Referer on the request. I would like to poke around and debug some more, but I'm really not that good with python.

grbrigsted avatar Feb 04 '15 20:02 grbrigsted

Can you confirm the exact headers sent and received? Specifically Referer and X-Sentry-Error.

dcramer avatar Feb 04 '15 20:02 dcramer

I'm sorry, I'm an idiot. To save time, I didn't start celery. Which probably meant that the events were queued, but never processed. When I disabled celery, it worked.

grbrigsted avatar Feb 05 '15 08:02 grbrigsted

Just saw this again - my problem was actually that I upgraded my site with an SSL certificate, and therefore needed to start pulling the https version on the cdn. I.e.,

'sentry_public_dsn': get_client().get_public_dsn('https')

SizeSeeker avatar Feb 09 '15 19:02 SizeSeeker

Hi SizeSeeker, could you please tell me where you put that line ? I am having the exact same issue

maxcanada avatar Feb 12 '16 14:02 maxcanada