Hi,
I still have issue, the new commit work partially.
test> cat admin.json
{
"listen": ":2019",
"origins": ["secret.admin.too"],
"enforce_origin": true
}
test> curl -X PATCH -H'Content-Type: application/json' http://172.21.20.8:2019/config/admin -d @admin.json
test> curl http://172.21.20.8:2019/config/ |jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 59 100 59 0 0 275 0 --:--:-- --:--:-- --:--:-- 275
{
"error": "client is not allowed to access from origin ''"
}
## No access
test> curl -X GET -H'Content-Type: application/json' -H'Origin: secret.admin.too' http://172.21.20.8:2019/config
{"error":"client is not allowed to access from origin 'secret.admin.too'"}
test>
## didn't work :(
I notice … that “secret.admin.too” is stored as “//secret.admin.too” on autosave.json.
You probably see //secret.admin.too in the log output:
INFO admin admin endpoint started {"address": "tcp/:2019", "enforce_origin": true, "origins": ["//secret.admin.too"]}
and that is normal/expected. The Origin header value is actually supposed to include a scheme by spec (but Caddy allows you to omit it for convenience to allow any scheme), so the origin is parsed as a URL, and when stringified, it prints // to separate scheme (empty) and host.
So, your request is invalid:
-H'Origin: secret.admin.too'
it must include either http:// or https://:
-H'Origin: https://secret.admin.too'
Please see the Origin header docs:
Notice that only a port is optional. Scheme is required.