Opened 3 weeks ago

Last modified 13 days ago

#36990 new Bug

Referrer header required for django.contrib.gis.forms.widgets.OSMWidget

Reported by: diestl Owned by:
Component: GIS Version: 6.0
Severity: Normal Keywords:
Cc: diestl Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The OSMWidget does not set the referrer header (or does not configure open layers to set the referrer header) when making tile requests to the OSM tile server. As per the OSM tile usage policy (https://operations.osmfoundation.org/policies/tiles/), these requests are being blocked.

The OSMWidget is the default widget used in the django admin interface when using the django.contrib.gis.admin.options.GISModelAdmin admin base class for geometry fields such as django.contrib.gis.db.models.PolygonField.

To reproduce this, you need a very simple model:

from django.contrib.gis.db import models


class TmpModel(models.Model):
    geometry = models.PolygonField(geography=True)

and admin:

from .models import TmpModel
from django.contrib.gis import admin


@admin.register(TmpModel)
class DatasetAdmin(admin.GISModelAdmin):
    pass

Attachments (1)

permission_denied_osm_scaled.png (102.6 KB ) - added by diestl 3 weeks ago.
Screenshot illustrating the issue in the admin interface

Download all attachments as: .zip

Change History (10)

comment:1 by diestl, 3 weeks ago

Cc: diestl added

by diestl, 3 weeks ago

Screenshot illustrating the issue in the admin interface

comment:2 by steph, 3 weeks ago

The referrer policy is fixed in OpenLayers 10.8 (see https://github.com/openlayers/openlayers/issues/17088). Within Django, the referenced js/css for OpenLayers needs to be updated. It is currently 7.2.2 (see https://github.com/django/django/blob/main/django/contrib/gis/forms/widgets.py#L78-L88).

I tested a update quickly and it seems to work but I don't have the ability to do a in-depth test of all related features to ensure the update has no side-effects.

in reply to:  2 comment:3 by diestl, 3 weeks ago

Replying to steph:

I tested a update quickly and it seems to work

Thank you for this, I wasn't sure if just upgrading was going to work or whether some additional configuration was going to be needed. I struggled following along with how even OSM end's up being used by the OSMWidget.

but I don't have the ability to do a in-depth test of all related features to ensure the update has no side-effects.

Is it a matter of testing that all the widget capabilities like drawing, deleting, editing and so on of geometries still works? I can't imagine that this change would have an impact beyond that. If so, I think I'm well placed to do that test, though you will just have to take my word for it.

comment:4 by diestl, 3 weeks ago

I can confirm at least that creating, editing and deleting features (Polygon and MultiPolygon in my case) works when using the OSMWidget, if openlayers is updated to 10.8 like so: https://github.com/django/django/compare/main...EnvSys:django:upgrade-openlayers

There is also a reference to OpenLayers 7.2.2 in https://github.com/django/django/blob/e3038897992d1c47f70ffb84ec1109b8d6a68bb9/js_tests/tests.html#L159-L159, which presumably should also be updated... I am not in a good position to test that.

comment:5 by David Smith, 3 weeks ago

Triage Stage: UnreviewedAccepted

I was also able to reproduce the issue. I also did a small test to upgrade to the latest version of OpenLayers and saw that the "access blocked" error no longer appear.

comment:6 by Vidhi Singh, 3 weeks ago

I would like to work on this ticket.

comment:7 by Vidhi Singh, 3 weeks ago

Cc: Vidhi Singh added
Owner: set to Vidhi Singh
Status: newassigned

comment:9 by Vidhi Singh, 2 weeks ago

Cc: Vidhi Singh removed
Owner: Vidhi Singh removed
Status: assignednew

Hi, I started working on this issue and set up a local environment to reproduce it. However, I’m currently facing some setup and environment challenges (especially around GIS dependencies and test configuration), and I won’t be able to continue working on this ticket right now.

I’m stepping back so someone else can take it forward.

Thank you!

comment:10 by Devarakondarishitha, 13 days ago

Hi, I would like to work on this issue. I will try updating OpenLayers version and test it.

Thanks!

Note: See TracTickets for help on using tickets.
Back to Top