Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot login through caddy reverse proxy (403) #746

Open
8 tasks
nodeam opened this issue Dec 3, 2024 · 7 comments
Open
8 tasks

Cannot login through caddy reverse proxy (403) #746

nodeam opened this issue Dec 3, 2024 · 7 comments
Labels
in:server question Further information is requested

Comments

@nodeam
Copy link

nodeam commented Dec 3, 2024

Can the issue be reproduced with the latest available release? (y/n)
yes

Which one is the environment gotify server is running in?

  • Docker
  • [*] Linux machine
  • Windows machine
Docker startup command or config file here (please mask sensitive information)
uname -a    
Linux pgotify 6.8.12-4-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-4 (2024-11-06T15:04Z) x86_64 GNU/Linux
lsb_release -a
Distributor ID: Debian
Description:    Debian GNU/Linux 12 (bookworm)
Release:        12
Codename:       bookworm

It is a Proxmox LXC Container

cat /etc/systemd/system/gotify.service 
[Unit]
Description=Gotify
Requires=network.target
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/opt/gotify
ExecStart=/opt/gotify/./gotify-linux-amd64
StandardOutput=append:/var/log/gotify/gotify.log
StandardError=append:/var/log/gotify/gotify-error.log
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
cat /opt/gotify/config.yml 
# Example configuration file for the server.
# Save it to `config.yml` when edited

server:
  keepaliveperiodseconds: 0 # 0 = use Go default (15s); -1 = disable keepalive; set the interval in which keepalive packets will be sent. Only change this value if you know what you are doing.
  listenaddr: "" # the address to bind on, leave empty to bind on all addresses. Prefix with "unix:" to create a unix socket. Example: "unix:/tmp/gotify.sock".
  port: 80 # the port the HTTP server will listen on

  ssl:
    enabled: true # if https should be enabled
    redirecttohttps: true # redirect to https if site is accessed by http
    listenaddr: "" # the address to bind on, leave empty to bind on all addresses. Prefix with "unix:" to create a unix socket. Example: "unix:/tmp/gotify.sock".
    port: 443 # the https port
    certfile: /etc/ssl/gotify/foo.bar.lan.crt # the cert file (leave empty when using letsencrypt)
    certkey: /etc/ssl/gotify/foo.bar.lan.key # the cert key (leave empty when using letsencrypt)
    letsencrypt:
      enabled: false # if the certificate should be requested from letsencrypt

  trustedproxies:
     - 127.0.0.1
     - 192.168.8.0/24
     - ::1

/etc/ssl/gotify/foo.bar.lan.crt generated by custom root-CA for the name and ip. Custom root-ca added to system certs.

ip a
...
inet 192.168.8.159/24 brd 192.168.8.255 scope global eth0
...

Do you have an reverse proxy installed in front of gotify server? (Please select None if the problem can be reproduced without the presense of a reverse proxy)

  • None
  • Nginx
  • Apache
  • [*] Caddy
Reverse proxy configuration (please mask sensitive information)
cat /etc/caddy/Caddyfile 
{
        email [email protected]
        crowdsec {
                api_key MfPxxxxxxxxxxxxxxxxxxxxxx
                api_url http://192.168.8.173:8080/
        }
}
import sites-enabled/*

cat /etc/caddy/sites-enabled/gotify-ssl-ip 
foo.bar.tld {
        reverse_proxy https://192.168.8.159:443 {
        header_up Host {upstream_hostport}
        header_up X-Real-IP {remote_host}
        }
        log {
        output file /var/log/caddy/foo.bar.tld-access.log
        }
}

On which client do you experience problems? (Select as many as you can see)

  • [*] WebUI
  • gotify-cli
  • Android Client
  • 3rd-party API call (Please include your code)

What did you do?
Trying to login into WebUI on FQDN foo.bar.tld:443 getting "Login failed" and nothing in gotify logs while using any browser I own. Tested Firefox, Opera and Safari on debian, macos and android.

Loging into WebUI on local domain foo.bar.lan:443 or on 192.168.8.159:443 without any issue.
Correct logins and simulated incorrect logins appear in /var/log/gotify/gotify.log. I never saw anything in /var/log/gotify/gotify-error.log

Is there anyway to set loglevel?

Loging in with Android Client works on both fqdn and local domain.

What did you expect to see?
Successful login.
I have identical caddy configurations for vaultwarden, nextcloudpi, photoprism and roundcube. All working without any problems.

What did you see instead? (Include screenshots, android logcat/request dumps if possible)
Failed login

@nodeam nodeam added the a:bug Something isn't working label Dec 3, 2024
@eternal-flame-AD
Copy link
Member

eternal-flame-AD commented Dec 3, 2024

Thanks for the ticket.

It seems like you have a working WebUI but not a login and none of your requests hit gotify?

Can you look at the network and console tab in the devtools and upload what is intuitively not right?

Also a good idea might be to enable the access log on caddy and see how caddy route the request.

I will retag this as question for now because I think the fact that local access have logs written but the not working remote access has not which strongly suggests the requests did not even hit gotify.

@eternal-flame-AD eternal-flame-AD added question Further information is requested in:server and removed a:bug Something isn't working labels Dec 3, 2024
@nodeam
Copy link
Author

nodeam commented Dec 3, 2024

Caddy log for gotify

Hitting WebUI on fqdn:443

178.13.x.x - - [03/Dec/2024:14:33:55 +0000] "GET / HTTP/2.0" 200 1456
178.13.x.x  - - [03/Dec/2024:14:33:55 +0000] "GET /static/css/2.0f3898ba.chunk.css HTTP/2.0" 200 2467
178.13.x.x  - - [03/Dec/2024:14:33:55 +0000] "GET /static/js/main.ca03a2c1.chunk.js HTTP/2.0" 200 16490
178.13.x.x  - - [03/Dec/2024:14:33:55 +0000] "GET /static/js/2.64bfa034.chunk.js HTTP/2.0" 200 260550
178.13.x.x  - - [03/Dec/2024:14:33:56 +0000] "GET /static/favicon-32x32.png HTTP/2.0" 200 1942
178.13.x.x  - - [03/Dec/2024:14:33:56 +0000] "GET /static/favicon-196x196.png HTTP/2.0" 200 15750

Entering credentials

178.13.x.x - - [03/Dec/2024:14:34:24 +0000] "POST /client HTTP/2.0" 403 0

Edit:
Console tab in the devtools says nothing especially because using the same browser instance on:

  • local domain:433 - login is ok
  • fqdn:443 - I get 403

@eternal-flame-AD
Copy link
Member

This is highly unlikely to be a genuine gotify response because the only place 403 is returned is if you used an application token for a client operation or vice versa, and you should see a JSON error message indicating the error on the browser devtools if you look at the corresponding request, I assume the 0 at the end mean content-length 0 but a genuine error message should have a non zero content-length.

If it helps I use Caddy too and here is my config and it just works, can you try simplify your setup (like use HTTP for the caddy <-> gotify part) and gradually try add back the additional options?

https://gotify.yumechi.jp {
    reverse_proxy :4101
    import /etc/caddy/include.d/tls // just TLS config
}

@eternal-flame-AD
Copy link
Member

Also just to not miss the obvious have you tried looking at the log of Caddy itself?

@jmattheis
Copy link
Member

FYI: Gotify does return 403 with empty response when there is a failed server side cors request.
image

@eternal-flame-AD eternal-flame-AD changed the title No browser can login through caddy reverse proxy Cannot login through caddy reverse proxy (403) Dec 4, 2024
@nodeam
Copy link
Author

nodeam commented Dec 5, 2024

Well I see only brackets... I attached my caddyfile.json and gotify-caddy-log.json. Every reverse_proxy host in my caddyfile.json work as it suppose to. As for gotify the android client is working. I'm using gotify only for proxmox notifications as a backup channel when mailserver gets updates and need to restart. I don't know to fix it so if you are willing to share your insights hot to enable server side CORS...

Edit:
I found something about gotify and cors: bastienwirtz/homer#822

Logs

Log while sending credentials

{
  "level": "info",
  "ts": 1733423132.8591142,
  "logger": "http.log.access.log0",
  "msg": "handled request",
  "request": {
    "remote_ip": "178.13.xx.xx",
    "remote_port": "60464",
    "client_ip": "178.13.xx.xx",
    "proto": "HTTP/2.0",
    "method": "POST",
    "host": "gotify.foo.de",
    "uri": "/client",
    "headers": {
      "Content-Type": [
        "application/json"
      ],
      "Sec-Fetch-Mode": [
        "cors"
      ],
      "Priority": [
        "u=0"
      ],
      "Te": [
        "trailers"
      ],
      "User-Agent": [
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:133.0) Gecko/20100101 Firefox/133.0"
      ],
      "Accept-Language": [
        "de"
      ],
      "Origin": [
        "https://gotify.foo.de"
      ],
      "Sec-Fetch-Dest": [
        "empty"
      ],
      "Sec-Gpc": [
        "1"
      ],
      "Sec-Fetch-Site": [
        "same-origin"
      ],
      "Accept-Encoding": [
        "gzip, deflate, br, zstd"
      ],
      "Referer": [
        "https://gotify.foo.de/"
      ],
      "Authorization": [
        "REDACTED"
      ],
      "Content-Length": [
        "26"
      ],
      "Accept": [
        "application/json, text/plain, */*"
      ],
      "Dnt": [
        "1"
      ]
    },
    "tls": {
      "resumed": false,
      "version": 772,
      "cipher_suite": 4865,
      "proto": "h2",
      "server_name": "gotify.foo.de"
    }
  },
  "bytes_read": 26,
  "user_id": "",
  "duration": 0.003471511,
  "size": 0,
  "status": 403,
  "resp_headers": {
    "Content-Type": [
      "application/json"
    ],
    "Content-Length": [
      "0"
    ],
    "Date": [
      "Thu, 05 Dec 2024 18:25:32 GMT"
    ],
    "Server": [
      "Caddy"
    ],
    "Alt-Svc": [
      "h3=\":443\"; ma=2592000"
    ]
  }
}

caddyfile.json

{
    "logging": {
        "logs": {
            "default": {
                "exclude": [
                    "http.log.access.log0",
                    "http.log.access.log1",
                    "http.log.access.log2",
                    "http.log.access.log3",
                    "http.log.access.log4",
                    "http.log.access.log5",
                    "http.log.access.log6"
                ]
            },
            "log0": {
                "writer": {
                    "filename": "/var/log/caddy/gotify-access.log",
                    "output": "file"
                },
                "include": [
                    "http.log.access.log0"
                ]
            },
            "log1": {
                "writer": {
                    "filename": "/var/log/caddy/local-access.log",
                    "output": "file"
                },
                "include": [
                    "http.log.access.log1"
                ]
            },
            "log2": {
                "writer": {
                    "filename": "/var/log/caddy/mail-access.log",
                    "output": "file"
                },
                "include": [
                    "http.log.access.log2"
                ]
            },
            "log3": {
                "writer": {
                    "filename": "/var/log/caddy/nextcloud-access.log",
                    "output": "file"
                },
                "include": [
                    "http.log.access.log3"
                ]
            },
            "log4": {
                "writer": {
                    "filename": "/var/log/caddy/notify-access.log",
                    "output": "file"
                },
                "include": [
                    "http.log.access.log4"
                ]
            },
            "log5": {
                "writer": {
                    "filename": "/var/log/caddy/prism-access.log",
                    "output": "file"
                },
                "include": [
                    "http.log.access.log5"
                ]
            },
            "log6": {
                "writer": {
                    "filename": "/var/log/caddy/vaultwarden-access.log",
                    "output": "file"
                },
                "include": [
                    "http.log.access.log6"
                ]
            }
        }
    },
    "apps": {
        "crowdsec": {
            "api_url": "http://192.168.168.173:8080/",
            "api_key": "REDACTED",
            "ticker_interval": "10s",
            "enable_streaming": true,
            "enable_hard_fails": false
        },
        "http": {
            "servers": {
                "srv0": {
                    "listen": [
                        ":443"
                    ],
                    "routes": [
                        {
                            "match": [
                                {
                                    "host": [
                                        "bitwarden.foo.de"
                                    ]
                                }
                            ],
                            "handle": [
                                {
                                    "handler": "subroute",
                                    "routes": [
                                        {
                                            "handle": [
                                                {
                                                    "handler": "error",
                                                    "status_code": 403
                                                }
                                            ],
                                            "match": [
                                                {
                                                    "not": [
                                                        {
                                                            "maxmind_geolocation": {
                                                                "allow_asn": null,
                                                                "allow_countries": [
                                                                    "AD",
                                                                    "AL",
                                                                    "AT",
                                                                    "AX",
                                                                    "BA",
                                                                    "BE",
                                                                    "BG",
                                                                    "CH",
                                                                    "CZ",
                                                                    "DE",
                                                                    "DK",
                                                                    "EE",
                                                                    "ES",
                                                                    "FI",
                                                                    "FR",
                                                                    "GB",
                                                                    "GG",
                                                                    "GI",
                                                                    "GR",
                                                                    "HR",
                                                                    "HU",
                                                                    "IE",
                                                                    "IM",
                                                                    "IT",
                                                                    "JE",
                                                                    "LI",
                                                                    "LT",
                                                                    "LU",
                                                                    "LV",
                                                                    "MC",
                                                                    "MD",
                                                                    "ME",
                                                                    "MK",
                                                                    "MT",
                                                                    "NL",
                                                                    "NO",
                                                                    "PL",
                                                                    "PT",
                                                                    "RO",
                                                                    "RS",
                                                                    "SE",
                                                                    "SI",
                                                                    "SK",
                                                                    "SM",
                                                                    "TR",
                                                                    "VA",
                                                                    "CA",
                                                                    "US",
                                                                    "UNK"
                                                                ],
                                                                "allow_metro_codes": null,
                                                                "allow_subdivisions": null,
                                                                "db_path": "/var/lib/GeoIP/GeoLite2-Country.mmdb",
                                                                "deny_asn": null,
                                                                "deny_countries": null,
                                                                "deny_metro_codes": null,
                                                                "deny_subdivisions": null
                                                            }
                                                        },
                                                        {
                                                            "remote_ip": {
                                                                "ranges": [
                                                                    "178.13.xx.xx"
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "handle": [
                                                {
                                                    "handler": "crowdsec"
                                                },
                                                {
                                                    "handler": "reverse_proxy",
                                                    "headers": {
                                                        "request": {
                                                            "set": {
                                                                "Host": [
                                                                    "{http.reverse_proxy.upstream.hostport}"
                                                                ],
                                                                "X-Real-Ip": [
                                                                    "{http.request.remote.host}"
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    "transport": {
                                                        "protocol": "http",
                                                        "tls": {}
                                                    },
                                                    "upstreams": [
                                                        {
                                                            "dial": "192.168.168.158:8000"
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ],
                            "terminal": true
                        },
                        {
                            "match": [
                                {
                                    "host": [
                                        "gotify.foo.de"
                                    ]
                                }
                            ],
                            "handle": [
                                {
                                    "handler": "subroute",
                                    "routes": [
                                        {
                                            "handle": [
                                                {
                                                    "handler": "error",
                                                    "status_code": 403
                                                }
                                            ],
                                            "match": [
                                                {
                                                    "not": [
                                                        {
                                                            "maxmind_geolocation": {
                                                                "allow_asn": null,
                                                                "allow_countries": [
                                                                    "AD",
                                                                    "AL",
                                                                    "AT",
                                                                    "AX",
                                                                    "BA",
                                                                    "BE",
                                                                    "BG",
                                                                    "CH",
                                                                    "CZ",
                                                                    "DE",
                                                                    "DK",
                                                                    "EE",
                                                                    "ES",
                                                                    "FI",
                                                                    "FR",
                                                                    "GB",
                                                                    "GG",
                                                                    "GI",
                                                                    "GR",
                                                                    "HR",
                                                                    "HU",
                                                                    "IE",
                                                                    "IM",
                                                                    "IT",
                                                                    "JE",
                                                                    "LI",
                                                                    "LT",
                                                                    "LU",
                                                                    "LV",
                                                                    "MC",
                                                                    "MD",
                                                                    "ME",
                                                                    "MK",
                                                                    "MT",
                                                                    "NL",
                                                                    "NO",
                                                                    "PL",
                                                                    "PT",
                                                                    "RO",
                                                                    "RS",
                                                                    "SE",
                                                                    "SI",
                                                                    "SK",
                                                                    "SM",
                                                                    "TR",
                                                                    "VA",
                                                                    "CA",
                                                                    "US",
                                                                    "UNK"
                                                                ],
                                                                "allow_metro_codes": null,
                                                                "allow_subdivisions": null,
                                                                "db_path": "/var/lib/GeoIP/GeoLite2-Country.mmdb",
                                                                "deny_asn": null,
                                                                "deny_countries": null,
                                                                "deny_metro_codes": null,
                                                                "deny_subdivisions": null
                                                            }
                                                        },
                                                        {
                                                            "remote_ip": {
                                                                "ranges": [
                                                                    "178.13.xx.xx"
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "handle": [
                                                {
                                                    "handler": "crowdsec"
                                                },
                                                {
                                                    "handler": "reverse_proxy",
                                                    "headers": {
                                                        "request": {
                                                            "set": {
                                                                "Host": [
                                                                    "{http.reverse_proxy.upstream.hostport}"
                                                                ],
                                                                "X-Real-Ip": [
                                                                    "{http.request.remote.host}"
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    "transport": {
                                                        "protocol": "http",
                                                        "tls": {}
                                                    },
                                                    "upstreams": [
                                                        {
                                                            "dial": "192.168.168.159:443"
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ],
                            "terminal": true
                        },
                        {
                            "match": [
                                {
                                    "host": [
                                        "notify.foo.de"
                                    ]
                                }
                            ],
                            "handle": [
                                {
                                    "handler": "subroute",
                                    "routes": [
                                        {
                                            "handle": [
                                                {
                                                    "handler": "error",
                                                    "status_code": 403
                                                }
                                            ],
                                            "match": [
                                                {
                                                    "not": [
                                                        {
                                                            "maxmind_geolocation": {
                                                                "allow_asn": null,
                                                                "allow_countries": [
                                                                    "AD",
                                                                    "AL",
                                                                    "AT",
                                                                    "AX",
                                                                    "BA",
                                                                    "BE",
                                                                    "BG",
                                                                    "CH",
                                                                    "CZ",
                                                                    "DE",
                                                                    "DK",
                                                                    "EE",
                                                                    "ES",
                                                                    "FI",
                                                                    "FR",
                                                                    "GB",
                                                                    "GG",
                                                                    "GI",
                                                                    "GR",
                                                                    "HR",
                                                                    "HU",
                                                                    "IE",
                                                                    "IM",
                                                                    "IT",
                                                                    "JE",
                                                                    "LI",
                                                                    "LT",
                                                                    "LU",
                                                                    "LV",
                                                                    "MC",
                                                                    "MD",
                                                                    "ME",
                                                                    "MK",
                                                                    "MT",
                                                                    "NL",
                                                                    "NO",
                                                                    "PL",
                                                                    "PT",
                                                                    "RO",
                                                                    "RS",
                                                                    "SE",
                                                                    "SI",
                                                                    "SK",
                                                                    "SM",
                                                                    "TR",
                                                                    "VA",
                                                                    "CA",
                                                                    "US",
                                                                    "UNK"
                                                                ],
                                                                "allow_metro_codes": null,
                                                                "allow_subdivisions": null,
                                                                "db_path": "/var/lib/GeoIP/GeoLite2-Country.mmdb",
                                                                "deny_asn": null,
                                                                "deny_countries": null,
                                                                "deny_metro_codes": null,
                                                                "deny_subdivisions": null
                                                            }
                                                        },
                                                        {
                                                            "remote_ip": {
                                                                "ranges": [
                                                                    "178.13.xx.xx"
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "handle": [
                                                {
                                                    "handler": "crowdsec"
                                                },
                                                {
                                                    "handler": "reverse_proxy",
                                                    "headers": {
                                                        "request": {
                                                            "set": {
                                                                "Host": [
                                                                    "{http.reverse_proxy.upstream.hostport}"
                                                                ],
                                                                "X-Real-Ip": [
                                                                    "{http.request.remote.host}"
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    "transport": {
                                                        "protocol": "http",
                                                        "tls": {}
                                                    },
                                                    "upstreams": [
                                                        {
                                                            "dial": "192.168.168.160:443"
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ],
                            "terminal": true
                        },
                        {
                            "match": [
                                {
                                    "host": [
                                        "prism.foo.de"
                                    ]
                                }
                            ],
                            "handle": [
                                {
                                    "handler": "subroute",
                                    "routes": [
                                        {
                                            "handle": [
                                                {
                                                    "handler": "error",
                                                    "status_code": 403
                                                }
                                            ],
                                            "match": [
                                                {
                                                    "not": [
                                                        {
                                                            "maxmind_geolocation": {
                                                                "allow_asn": null,
                                                                "allow_countries": [
                                                                    "AD",
                                                                    "AL",
                                                                    "AT",
                                                                    "AX",
                                                                    "BA",
                                                                    "BE",
                                                                    "BG",
                                                                    "CH",
                                                                    "CZ",
                                                                    "DE",
                                                                    "DK",
                                                                    "EE",
                                                                    "ES",
                                                                    "FI",
                                                                    "FR",
                                                                    "GB",
                                                                    "GG",
                                                                    "GI",
                                                                    "GR",
                                                                    "HR",
                                                                    "HU",
                                                                    "IE",
                                                                    "IM",
                                                                    "IT",
                                                                    "JE",
                                                                    "LI",
                                                                    "LT",
                                                                    "LU",
                                                                    "LV",
                                                                    "MC",
                                                                    "MD",
                                                                    "ME",
                                                                    "MK",
                                                                    "MT",
                                                                    "NL",
                                                                    "NO",
                                                                    "PL",
                                                                    "PT",
                                                                    "RO",
                                                                    "RS",
                                                                    "SE",
                                                                    "SI",
                                                                    "SK",
                                                                    "SM",
                                                                    "TR",
                                                                    "VA",
                                                                    "CA",
                                                                    "US",
                                                                    "UNK"
                                                                ],
                                                                "allow_metro_codes": null,
                                                                "allow_subdivisions": null,
                                                                "db_path": "/var/lib/GeoIP/GeoLite2-Country.mmdb",
                                                                "deny_asn": null,
                                                                "deny_countries": null,
                                                                "deny_metro_codes": null,
                                                                "deny_subdivisions": null
                                                            }
                                                        },
                                                        {
                                                            "remote_ip": {
                                                                "ranges": [
                                                                    "178.13.xx.xx"
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "handle": [
                                                {
                                                    "handler": "crowdsec"
                                                },
                                                {
                                                    "handler": "reverse_proxy",
                                                    "headers": {
                                                        "request": {
                                                            "set": {
                                                                "Host": [
                                                                    "{http.reverse_proxy.upstream.hostport}"
                                                                ],
                                                                "X-Real-Ip": [
                                                                    "{http.request.remote.host}"
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    "transport": {
                                                        "protocol": "http",
                                                        "tls": {}
                                                    },
                                                    "upstreams": [
                                                        {
                                                            "dial": "192.168.168.153:2342"
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ],
                            "terminal": true
                        },
                        {
                            "match": [
                                {
                                    "host": [
                                        "mail.foo.de"
                                    ]
                                }
                            ],
                            "handle": [
                                {
                                    "handler": "subroute",
                                    "routes": [
                                        {
                                            "handle": [
                                                {
                                                    "handler": "error",
                                                    "status_code": 403
                                                }
                                            ],
                                            "match": [
                                                {
                                                    "not": [
                                                        {
                                                            "maxmind_geolocation": {
                                                                "allow_asn": null,
                                                                "allow_countries": [
                                                                    "AD",
                                                                    "AL",
                                                                    "AT",
                                                                    "AX",
                                                                    "BA",
                                                                    "BE",
                                                                    "BG",
                                                                    "CH",
                                                                    "CZ",
                                                                    "DE",
                                                                    "DK",
                                                                    "EE",
                                                                    "ES",
                                                                    "FI",
                                                                    "FR",
                                                                    "GB",
                                                                    "GG",
                                                                    "GI",
                                                                    "GR",
                                                                    "HR",
                                                                    "HU",
                                                                    "IE",
                                                                    "IM",
                                                                    "IT",
                                                                    "JE",
                                                                    "LI",
                                                                    "LT",
                                                                    "LU",
                                                                    "LV",
                                                                    "MC",
                                                                    "MD",
                                                                    "ME",
                                                                    "MK",
                                                                    "MT",
                                                                    "NL",
                                                                    "NO",
                                                                    "PL",
                                                                    "PT",
                                                                    "RO",
                                                                    "RS",
                                                                    "SE",
                                                                    "SI",
                                                                    "SK",
                                                                    "SM",
                                                                    "TR",
                                                                    "VA",
                                                                    "CA",
                                                                    "US",
                                                                    "UNK"
                                                                ],
                                                                "allow_metro_codes": null,
                                                                "allow_subdivisions": null,
                                                                "db_path": "/var/lib/GeoIP/GeoLite2-Country.mmdb",
                                                                "deny_asn": null,
                                                                "deny_countries": null,
                                                                "deny_metro_codes": null,
                                                                "deny_subdivisions": null
                                                            }
                                                        },
                                                        {
                                                            "remote_ip": {
                                                                "ranges": [
                                                                    "178.13.xx.xx"
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "handle": [
                                                {
                                                    "handler": "crowdsec"
                                                },
                                                {
                                                    "handler": "reverse_proxy",
                                                    "headers": {
                                                        "request": {
                                                            "set": {
                                                                "Host": [
                                                                    "{http.reverse_proxy.upstream.hostport}"
                                                                ],
                                                                "X-Real-Ip": [
                                                                    "{http.request.remote.host}"
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    "transport": {
                                                        "protocol": "http",
                                                        "tls": {}
                                                    },
                                                    "upstreams": [
                                                        {
                                                            "dial": "192.168.168.154:443"
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ],
                            "terminal": true
                        },
                        {
                            "match": [
                                {
                                    "host": [
                                        "nw.foo.de"
                                    ]
                                }
                            ],
                            "handle": [
                                {
                                    "handler": "subroute",
                                    "routes": [
                                        {
                                            "handle": [
                                                {
                                                    "handler": "error",
                                                    "status_code": 403
                                                }
                                            ],
                                            "match": [
                                                {
                                                    "not": [
                                                        {
                                                            "maxmind_geolocation": {
                                                                "allow_asn": null,
                                                                "allow_countries": [
                                                                    "AD",
                                                                    "AL",
                                                                    "AT",
                                                                    "AX",
                                                                    "BA",
                                                                    "BE",
                                                                    "BG",
                                                                    "CH",
                                                                    "CZ",
                                                                    "DE",
                                                                    "DK",
                                                                    "EE",
                                                                    "ES",
                                                                    "FI",
                                                                    "FR",
                                                                    "GB",
                                                                    "GG",
                                                                    "GI",
                                                                    "GR",
                                                                    "HR",
                                                                    "HU",
                                                                    "IE",
                                                                    "IM",
                                                                    "IT",
                                                                    "JE",
                                                                    "LI",
                                                                    "LT",
                                                                    "LU",
                                                                    "LV",
                                                                    "MC",
                                                                    "MD",
                                                                    "ME",
                                                                    "MK",
                                                                    "MT",
                                                                    "NL",
                                                                    "NO",
                                                                    "PL",
                                                                    "PT",
                                                                    "RO",
                                                                    "RS",
                                                                    "SE",
                                                                    "SI",
                                                                    "SK",
                                                                    "SM",
                                                                    "TR",
                                                                    "VA",
                                                                    "CA",
                                                                    "US",
                                                                    "UNK"
                                                                ],
                                                                "allow_metro_codes": null,
                                                                "allow_subdivisions": null,
                                                                "db_path": "/var/lib/GeoIP/GeoLite2-Country.mmdb",
                                                                "deny_asn": null,
                                                                "deny_countries": null,
                                                                "deny_metro_codes": null,
                                                                "deny_subdivisions": null
                                                            }
                                                        },
                                                        {
                                                            "remote_ip": {
                                                                "ranges": [
                                                                    "178.13.xx.xx"
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "handle": [
                                                {
                                                    "handler": "crowdsec"
                                                },
                                                {
                                                    "handler": "reverse_proxy",
                                                    "headers": {
                                                        "request": {
                                                            "set": {
                                                                "Host": [
                                                                    "{http.reverse_proxy.upstream.hostport}"
                                                                ],
                                                                "X-Real-Ip": [
                                                                    "{http.request.remote.host}"
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    "transport": {
                                                        "protocol": "http",
                                                        "tls": {}
                                                    },
                                                    "upstreams": [
                                                        {
                                                            "dial": "192.168.168.151:443"
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ],
                            "terminal": true
                        }
                    ],
                    "errors": {
                        "routes": [
                            {
                                "match": [
                                    {
                                        "host": [
                                            "bitwarden.foo.de"
                                        ]
                                    }
                                ],
                                "handle": [
                                    {
                                        "handler": "subroute",
                                        "routes": [
                                            {
                                                "handle": [
                                                    {
                                                        "body": "{http.error.status_code} {http.error.status_text}",
                                                        "handler": "static_response"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ],
                                "terminal": true
                            },
                            {
                                "match": [
                                    {
                                        "host": [
                                            "gotify.foo.de"
                                        ]
                                    }
                                ],
                                "handle": [
                                    {
                                        "handler": "subroute",
                                        "routes": [
                                            {
                                                "handle": [
                                                    {
                                                        "body": "{http.error.status_code} {http.error.status_text}",
                                                        "handler": "static_response"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ],
                                "terminal": true
                            },
                            {
                                "match": [
                                    {
                                        "host": [
                                            "notify.foo.de"
                                        ]
                                    }
                                ],
                                "handle": [
                                    {
                                        "handler": "subroute",
                                        "routes": [
                                            {
                                                "handle": [
                                                    {
                                                        "body": "{http.error.status_code} {http.error.status_text}",
                                                        "handler": "static_response"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ],
                                "terminal": true
                            },
                            {
                                "match": [
                                    {
                                        "host": [
                                            "prism.foo.de"
                                        ]
                                    }
                                ],
                                "handle": [
                                    {
                                        "handler": "subroute",
                                        "routes": [
                                            {
                                                "handle": [
                                                    {
                                                        "body": "{http.error.status_code} {http.error.status_text}",
                                                        "handler": "static_response"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ],
                                "terminal": true
                            },
                            {
                                "match": [
                                    {
                                        "host": [
                                            "mail.foo.de"
                                        ]
                                    }
                                ],
                                "handle": [
                                    {
                                        "handler": "subroute",
                                        "routes": [
                                            {
                                                "handle": [
                                                    {
                                                        "body": "{http.error.status_code} {http.error.status_text}",
                                                        "handler": "static_response"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ],
                                "terminal": true
                            },
                            {
                                "match": [
                                    {
                                        "host": [
                                            "nw.foo.de"
                                        ]
                                    }
                                ],
                                "handle": [
                                    {
                                        "handler": "subroute",
                                        "routes": [
                                            {
                                                "handle": [
                                                    {
                                                        "body": "{http.error.status_code} {http.error.status_text}",
                                                        "handler": "static_response"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ],
                                "terminal": true
                            }
                        ]
                    },
                    "logs": {
                        "logger_names": {
                            "bitwarden.foo.de": [
                                "log6"
                            ],
                            "gotify.foo.de": [
                                "log0"
                            ],
                            "mail.foo.de": [
                                "log2"
                            ],
                            "notify.foo.de": [
                                "log4"
                            ],
                            "nw.foo.de": [
                                "log3"
                            ],
                            "prism.foo.de": [
                                "log5"
                            ]
                        }
                    }
                },
                "srv1": {
                    "listen": [
                        ":80"
                    ],
                    "routes": [
                        {
                            "handle": [
                                {
                                    "handler": "vars",
                                    "root": "/usr/share/caddy"
                                }
                            ]
                        },
                        {
                            "match": [
                                {
                                    "not": [
                                        {
                                            "maxmind_geolocation": {
                                                "db_path": "/var/lib/GeoIP/GeoLite2-Country.mmdb",
                                                "allow_countries": [
                                                    "AD",
                                                    "AL",
                                                    "AT",
                                                    "AX",
                                                    "BA",
                                                    "BE",
                                                    "BG",
                                                    "CH",
                                                    "CZ",
                                                    "DE",
                                                    "DK",
                                                    "EE",
                                                    "ES",
                                                    "FI",
                                                    "FR",
                                                    "GB",
                                                    "GG",
                                                    "GI",
                                                    "GR",
                                                    "HR",
                                                    "HU",
                                                    "IE",
                                                    "IM",
                                                    "IT",
                                                    "JE",
                                                    "LI",
                                                    "LT",
                                                    "LU",
                                                    "LV",
                                                    "MC",
                                                    "MD",
                                                    "ME",
                                                    "MK",
                                                    "MT",
                                                    "NL",
                                                    "NO",
                                                    "PL",
                                                    "PT",
                                                    "RO",
                                                    "RS",
                                                    "SE",
                                                    "SI",
                                                    "SK",
                                                    "SM",
                                                    "TR",
                                                    "VA",
                                                    "CA",
                                                    "US",
                                                    "UNK"
                                                ],
                                                "deny_countries": null,
                                                "allow_subdivisions": null,
                                                "deny_subdivisions": null,
                                                "allow_metro_codes": null,
                                                "deny_metro_codes": null,
                                                "allow_asn": null,
                                                "deny_asn": null
                                            }
                                        },
                                        {
                                            "remote_ip": {
                                                "ranges": [
                                                    "178.13.xx.xx"
                                                ]
                                            }
                                        }
                                    ]
                                }
                            ],
                            "handle": [
                                {
                                    "handler": "error",
                                    "status_code": 403
                                }
                            ]
                        },
                        {
                            "handle": [
                                {
                                    "handler": "crowdsec"
                                },
                                {
                                    "handler": "file_server",
                                    "hide": [
                                        "/etc/caddy/Caddyfile",
                                        "/etc/caddy/sites-enabled/local-caddy"
                                    ]
                                }
                            ]
                        }
                    ],
                    "errors": {
                        "routes": [
                            {
                                "handle": [
                                    {
                                        "body": "{http.error.status_code} {http.error.status_text}",
                                        "handler": "static_response"
                                    }
                                ]
                            }
                        ]
                    },
                    "logs": {
                        "default_logger_name": "log1"
                    }
                }
            }
        },
        "tls": {
            "automation": {
                "policies": [
                    {
                        "subjects": [
                            "bitwarden.foo.de",
                            "gotify.foo.de",
                            "notify.foo.de",
                            "prism.foo.de",
                            "mail.foo.de",
                            "nw.foo.de"
                        ],
                        "issuers": [
                            {
                                "email": "[email protected]",
                                "module": "acme"
                            },
                            {
                                "ca": "https://acme.zerossl.com/v2/DV90",
                                "email": "[email protected]",
                                "module": "acme"
                            }
                        ]
                    }
                ]
            }
        }
    }
}

@eternal-flame-AD
Copy link
Member

eternal-flame-AD commented Dec 6, 2024

As @jmattheis pointed out, gotify must see a Host header consistent with the Origin header, if you access gotify using an address other than gotify.foo.de as configured, the browser will send an Origin header that is different from the Host header you have statically overridden (as shown in the original caddy file) and that is technically unexpected cross-origin request from the server point of view.

If you would like Gotify to accept additional alternative Origin headers you can add your other possible origins to the server.cors.alloworigins and server.stream.allowedorigins in the config file. (You have to add both, it was probably a design oversight the name is different.. )

You can also bypass this logic altogether by rolling your own logic on Caddy and removing or rewriting the Origin header, but that is more complicated and not warranted unless you have specific logics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:server question Further information is requested
Development

No branches or pull requests

3 participants