Conversation
|
Isn't the solution to add that option to the OSM layer in https://github.com/openstreetmap/leaflet-osm/? I don't think hard coding something based on the host here is reasonable... |
I'll also PR the change there, but would be good to get this upstreamed directly. Alternative might be to improve the examples. |
|
Starting to think we should be splitting out OSM specific logic out of Additionally, this is likely something we want to backport to 1.x? |
|
@Firefishy I'm going over https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy and https://w3c.github.io/webappsec-referrer-policy/#referrer-policy , and according to those, all browsers should be already using a default value of Or is there any scenario (or browser) in which Leaflet, using defaults, does not send referrer on the tile image requests?? I'd be more comfortable changing the default value at... Leaflet/src/layer/tile/TileLayer.js Line 87 in 0eee377 strict-origin-when-cross-origin (which should cover unruly user agents) and still letting JS devs change behaviour if they want.
@jonkoops I stand by what I said at #9228 (comment) . If we had four different tile providers with four different hacks for each one, I'd be in favour of refactoring; but with only OSM I'd leave it be. |
Update: To clarify, I suspect most of the 10% are setting the |
That is fair, let's leave it as-is. |
|
I don’t think it’s a good idea to force the referrer header. I suggest closing this PR |
|
@Falke-Design The alternative acceptable? - Updating all leaflet examples that use OpenStreetMap to include explicitly setting |
|
@Firefishy what if OSM doesn't enable this rule? 😉 How are other libs like OpenLayers are handling this? The fact is that Leaflet is not only used for providing OSM tiles, and adding more and more custom OSM-specific code should not be our goal. |
|
I am part of the OpenStreetMap sysadmin team. We are going to enforce the Yes, there other libraries, but leaflet is the most common when using OpenStreetMap tiles. |
That was what I meant, just don't enforce it 😉 Just joking, but I'm still not sure if it should be really in the core library. @mourner thoughts? |
After excluding app specific UAs, ~ 10% / ~ 126,000 GB/month of our tile.openstreetmap.org traffic is unidentified "anonymous" traffic where the referer is missing. Month by month the figure grows. It isn't sustainable. |
|
I am not against landing this in Leaflet per-se, especially if it will be a future requirement for using OSM on the web. Do note that Leaflet has a long history, so there are likely a lot of applications out there that will never upgrade to a version that will include these changes. @Firefishy one thing I am confused about, is that it seems the default value from browsers is already |
|
|
Got it (sorry I skimmed over the comments above too fast), in that case, this all LGTM logic wise. If you could address the review comment I had about code duplication in the review, I have no objection against merging this. |
b21770a to
1f4d50a
Compare
|
@jonkoops Refactored as requested to remove duplication. Hopefully suitable now. |
|
| if (options.attribution === null) { | ||
| options.attribution = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'; | ||
| } | ||
| if (options.referrerPolicy === false) { |
There was a problem hiding this comment.
We should probably update the documentation of this field to state that it will default to strict-origin-when-cross-origin for OSM hosts, and that it cannot be disabled for those.
There was a problem hiding this comment.
The automatic option value can be disabled by setting the option referrerpolicy.
There was a problem hiding this comment.
I mean to say, currently the following documentation provides no information to the user that for OSM URLs the default behavior will be different when defaulting to false:
There was a problem hiding this comment.
I'm happy to PR the addition. How about?
"OpenStreetMap special case: If the tile URL host is tile.openstreetmap.org and referrerPolicy is unset, Leaflet automatically applies "strict-origin-when-cross-origin" so that a valid Referer is sent, complying with the OpenStreetMap Tile Usage Policy. Set referrerPolicy explicitly if you need a different value."
There was a problem hiding this comment.
Or a shorter version:
"Note: When the tile URL host is tile.openstreetmap.org and this option is not explicitly set, Leaflet will default referrerPolicy to "strict-origin-when-cross-origin" to ensure a valid Referer is sent in line with the OpenStreetMap Tile Usage Policy."
There was a problem hiding this comment.
Or shortest:
"If using tile.openstreetmap.org and unset, this defaults to strict-origin-when-cross-origin to comply with the OSM Tile Usage Policy."
Sets the default value of the TileLayer referrerPolicy to `strict-origin-when-cross-origin` (which should already be the default anyway). This is an alternative to #9883 Signed-off-by: Iván Sánchez Ortega <ivan@sanchezortega.es>
|
@Firefishy By any chance, do you have a drill-down of tile requests with no referrer set, split by HTTP vs HTTPS? I'm wondering if HTTPS sites are using HTTP tiles, and the downgrade is what's making the browser not set the referrer header. |
Unfortunately I don't have those details to hand. Our CDN does the redirects. I don't think setting an "unsecure" Referrer Policy would be a good idea. |
@Firefishy I'm not thinking about that. I'm thinking that, if the user is doing Bit of extra context: I've done a quick test in here (Linux+Firefox 141, "HTTPS only" mode off), in the https://leafletjs.com/edit . If I set the tile url to And, what's more, setting the Seems that there's a weird exception to the cross-origin referrer policy when there's automatic HTTP→HTTPS upgrades going on. |
I can not believe that ~10% of Leaflet deployments out there are messing with the See 3050929 |
|
I actually using leaflet with OSM and have error message 'Access blocked refere is required by tile usage policy of OpenStreetMap's volunteer-run servers osm.wiki/Blocked' since last week (20/03/2026) I did the modifications on the html source code, I also tried to add the option 'referrerPolicy' in TileLayer, but the problem still remain the same. To reproduce the problem, I use the code of the example showed on the leaflet website https://leafletjs.com/examples/custom-icons/example-one-icon.html where I did the following modifications: => Added line '<meta name="referrer" content="strict-origin-when-cross-origin>' When I load the HTML file which contain the modified source code, with a navigator (Edge, Chrome...), Il still have the error message when I zoom on the map. What can I do to avoid this error message ? Thanks |
|
Some anti-trackers (like bitdefender Anti-tracker) remove the Referer header from the tile request to tile.openstreetmap.org, so it leads to this annoying "403r - Access blocked - Referer is required" error. |
see Leaflet/Leaflet#9883 for context
This may not help you, but it could possibly help others. But I'm developer of a React app which we serve through as a webapp and Electron. For the webversion it was enough the add |
I'm also a developer of an Electron app using OSM tiles in Leaflet. Some of our users have reported tiles occasionally being blocked with the 403r message stating a Referer is required. Although our app already includes a |
|
This issue is just about Leaflet's default referrerPolicy. If you've got other questions as to why you're getting blocked, you can email operations at osmfoundation.org with technical details including headers being sent. |
|
An interesting Node-RED case study about this problem, in Wordmap module: https://discourse.nodered.org/t/worldmap-access-blocked-error-r403/100759 |
Ref Leaflet/Leaflet#9883 because they aren't doing it.
|
The Brave Browser causes troubles too |
|
Superceded by #9897 |
The OpenStreetMap Foundation recently tightened referer enforcement on their raster tile server: requests with no Referer header now get a 403r 'Access blocked' placeholder tile instead of the real one (valid PNG, HTTP 200, so it doesn't look like an error). Leaflet loads tiles as plain <img> tags, which inherit the embedding page's Referrer- Policy - Home Assistant's varies by deployment (reverse proxy, Nabu Casa remote, browser privacy settings), so some setups end up sending no referer at all while others do, explaining why this didn't reproduce for everyone. Home Assistant's own core team hit the identical problem in their native map card one day before this was reported and fixed it by moving to self-hosted vector tiles (home-assistant/frontend#53816) - too large a change for this card. Instead, set Leaflet's per-layer referrerPolicy option to "origin" on the OSM tile layer, which overrides the page's policy for just this layer so it always sends at least the HA instance's origin, matching Leaflet's own recommended fix for this exact problem (Leaflet/Leaflet#9883). Verified live: fetching a real OSM tile with a realistic browser User- Agent, with vs without a Referer header, and nothing else different, reproduces the exact 403r block (identical 6987-byte placeholder) only when the Referer is missing. Bump version to 1.19.48.
OpenStreetMap.org's tile use policy requires a valid HTTP Referer, but sites often set a
Referrer-Policy=no-referrerorReferrer-Policy=same-originwhich stops the browser sending a HTTP Referer.This change ensures that the tile fetches send a referer when fetching tiles from tile.openstreetmap.org.
Currently approximately 10% of tile.openstreetmap.org's tile traffic is from sites which are not sending a HTTP Referer.
Disclosure: I am part of the OpenStreetMap.org Operations Team who are responsible for technically enforcing the tile usage policy.
Fixes: #10156