CORS Plugin issue with v1.0.3


#1

I’m trying to install the CORS plugin globally and keep hitting the following error:
{"message":"schema violation (config.methods: expected one of: HEAD, GET, POST, PUT, PATCH, DELETE)","name":"schema violation","fields":{"config":{"methods":"expected one of: HEAD, GET, POST, PUT, PATCH, DELETE"}},"code":2}
The methods are defined in the plugin syntax by this:
--data "config.methods=HEAD, GET, POST, PUT ,PATCH, DELETE"

The plugin works fine with a single method, but will not allow more than that. Under v.14, the plugin allowed multiple methods to be defined.


#2

@rossee Hi,

Are you using the proper syntax for arguments introduced in 0.13 for new endpoints (/routes, /services), and used in 1.0 for the /plugins endpoint? I have no problem specifying multiple methods in 1.0.3 with both application/x-www-form-urlencoded:

http -v :8001/services/323b5367-4a33-4872-83b3-1b803f9604b2/plugins 'name=cors' 'config.methods[]=GET' 'config.methods[]=HEAD' -f
POST /services/323b5367-4a33-4872-83b3-1b803f9604b2/plugins HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 60
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:8001
User-Agent: HTTPie/0.9.4

name=cors&config.methods%5B%5D=GET&config.methods%5B%5D=HEAD

HTTP/1.1 201 Created
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 351
Content-Type: application/json; charset=utf-8
Date: Tue, 19 Feb 2019 18:14:55 GMT
Server: kong/1.0.3

{
    "config": {
        ...
        "methods": [
            "GET",
            "HEAD"
        ],
    },
    ...
    "service": {
        "id": "323b5367-4a33-4872-83b3-1b803f9604b2"
    }
}

And application/json:

 http -v :8001/services/323b5367-4a33-4872-83b3-1b803f9604b2/plugins name=cors config:='{"methods":["GET", "HEAD"]}'       
POST /services/323b5367-4a33-4872-83b3-1b803f9604b2/plugins HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 56
Content-Type: application/json
Host: localhost:8001
User-Agent: HTTPie/0.9.4

{
    "config": {
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "name": "cors"
}

HTTP/1.1 201 Created
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 351
Content-Type: application/json; charset=utf-8
Date: Tue, 19 Feb 2019 18:18:40 GMT
Server: kong/1.0.3

{
    "config": {
        ...
        "methods": [
            "GET",
            "HEAD"
        ],
    },
    ...
    "service": {
        "id": "323b5367-4a33-4872-83b3-1b803f9604b2"
    }
}

#3

Hi,

same issue here

curl -X POST http://local:8001/services/stage-service/plugins --data “name=cors” --data “config.origins=https://stage.local” --data “config.methods=POST, GET” --data “config.headers=Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Auth-Token” --data “config.exposed_headers=X-Auth-Token” --data “config.credentials=true” --data “config.max_age=3600”

returns

{“message”:“schema violation (config.methods: expected one of: HEAD, GET, POST, PUT, PATCH, DELETE)”,“name”:“schema violation”,“fields”:{“config”:{“methods”:“expected one of: HEAD, GET, POST, PUT, PATCH, DELETE”}},“code”:2}


#4

@AlexanderGerasymenko Hi, and welcome!

Same issue: you are using the old array notation (comma-separated) which isn’t accepted anymore as of Kong 1.0. Please read my above reply which explains how to send arrays with both of Kong’s Admin
s accepted Content-Type.


#5

Hey @thibaultcha,

I followed this instruction https://docs.konghq.com/hub/kong-inc/cors/ for kong v. 1.0.x. Am I referring to a wrong documentation? Just so for me to know if I can proceed learning kong by it.


#6

I can confirm that this works via application/json. I think the issue is that the documentation has not been updated to deprecate the old array notation (comma-separated). Kong 1.0.x still shows this as a valid config. This tripped us up as well. Thanks!