notum-cz / strapi-plugin-location

This plugin allows users to create location inputs and store latitude and longitude values as geometry types in a PostGIS database. It also provides functionality to filter items based on their location.
MIT License
24 stars 13 forks source link

Map tiles do not load due to Content Security Policy #55

Closed kaechele closed 12 months ago

kaechele commented 1 year ago

Bug report

Describe the bug

When trying to view the map the OpenStreetMap tiles do not load due to being blocked by strapi's default Content Security Policy.

Steps to reproduce the behavior

  1. Click on "Map" button below coordinates
  2. The map shows only a grey background, no tiles

Expected behavior

Tiles are shown

Screenshots

N/A

Code snippets

The config/middlewares.ts needs to be adjusted to allow the browser to load the tiles from an external source. This configuration works for me:

export default [
  "strapi::errors",
  {
    name: "strapi::security",
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          "connect-src": ["'self'", "https:"],
          "img-src": [
            "'self'",
            "data:",
            "blob:",
            "https://market-assets.strapi.io",
            "https://tile.openstreetmap.org",
            "https://a.tile.openstreetmap.org",
            "https://b.tile.openstreetmap.org",
            "https://c.tile.openstreetmap.org",
          ],
          "media-src": ["'self'", "data:", "blob:"],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
  "strapi::cors",
  "strapi::poweredBy",
  "strapi::logger",
  "strapi::query",
  "strapi::body",
  "strapi::session",
  "strapi::favicon",
  "strapi::public",
];

System

Additional context

N/A

omikulcik commented 12 months ago

Hello @kaechele, yes you are right. I will put this into readme. Thank you!

omikulcik commented 12 months ago

Closed by #56