Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix set trace attributes for django when host is not allowed #1026

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sirkonst
Copy link

request.get_host() raises DisallowedHost exception if request came with HOST witch not configured
in ALLOWED_HOSTS setting.

Django provides special methods request._get_raw_host() and request.get_raw_uri() to get values
like get_host() and build_absolute_uri() but without checking by ALLOWED_HOSTS.

Without fix error will be like:

ERROR    opencensus.ext.django.middleware:middleware.py:235 Failed to trace request
Traceback (most recent call last):
  File "/home/konst/develop/opencensus-python/contrib/opencensus-ext-django/opencensus/ext/django/middleware.py", line 211, in process_request
    attribute_value=request.get_host())
  File "/home/konst/develop/opencensus-python/.nox/unit-2-7/lib/python2.7/site-packages/django/http/request.py", line 113, in get_host
    raise DisallowedHost(msg)
DisallowedHost: Invalid HTTP_HOST header: 'notallowedhost'. You may need to add u'notallowedhost' to ALLOWED_HOSTS.

`request.get_host()` raises DisallowedHost exception if request came with HOST witch not configured
in ALLOWED_HOSTS setting.

Django provides special methods `request._get_raw_host()` and `request.get_raw_uri()` to get values
like `get_host()` and `build_absolute_uri()` but without checking by ALLOWED_HOSTS.

Without fix error will be like:

```
ERROR    opencensus.ext.django.middleware:middleware.py:235 Failed to trace request
Traceback (most recent call last):
  File "/home/konst/develop/opencensus-python/contrib/opencensus-ext-django/opencensus/ext/django/middleware.py", line 211, in process_request
    attribute_value=request.get_host())
  File "/home/konst/develop/opencensus-python/.nox/unit-2-7/lib/python2.7/site-packages/django/http/request.py", line 113, in get_host
    raise DisallowedHost(msg)
DisallowedHost: Invalid HTTP_HOST header: 'notallowedhost'. You may need to add u'notallowedhost' to ALLOWED_HOSTS.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant