Skip to content

In Strapi 4.4.4 CORS strategy doesn't work anymore and throws 500 error #14675

@kwiat1990

Description

@kwiat1990

Setup

  • Node.js version: 16.14.2
  • NPM version: 8.13.2
  • Strapi version: 4.4.4
  • Database: postgres
  • Operating system: MacOS Monterey 12.6

Describe the bug

After recently update from 4.4.3 to 4.4.4 responses with the following error while visiting localhost:1337 or any other related URL:

{
  "data": null,
  "error": {
    "status": 500,
    "name": "InternalServerError",
    "message": "undefined is not a valid origin"
  }
}

I have a custom CORS policy in middleware.js (see "step to reproduce" for the code), which did worked with previous versions. After update to 4.4.4 it seems to be broken. Using standard CORS config as 'strapi::cors' fix the issue.

Steps to reproduce the behavior

  1. Update Strapi to 4.4.4
  2. Make sure to have custom CORS policy in middleware.js, e.g.:
{
      name: "strapi::cors",
      config: {
        enabled: true,
        headers: "*",
        origin: env.array("ALLOWED_ORIGINS_URL"), // for example: http://localhost:3000,http://localhost:1337
      },
    },

Expected behavior

Strapi works normally without any errors. Admin panel can be visited.

Metadata

Metadata

Assignees

Labels

issue: bugIssue reporting a bugseverity: highIf it breaks the basic use of the productsource: core:strapiSource is core/strapi packagestatus: confirmedConfirmed by a Strapi Team member or multiple community members

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions