Make response headers configurable
Could be used for setting an Access-Control-Allow-Origin-header.
Any news here? :)
We need this for several different sub-domains, and want just one single gotify instance for all of them - like
- gotify.example.com
- sub1.example.com
- sub2.example.com
- etc
This is currently only available if we run in dev-mode - but... ;)
@Nicolai- probably this week or next one, why do you need this feature for having different subdomains? You could use a nginx proxy to handle more than one domain.
@jmattheis I work with @Nicolai- We currently have many subdomains (each of our customers have their own subdomain), and would like all of them to talk to the same gotify instance (instead of having one instance per subdomain).
When testing now, and trying to connect from sub.example.com to gotify.example.com, we get a 403 Access Denied/Not authorized. Our best guess is, that it's because of CORS issues (the issue linked in this one #67).
@fMads @Nicolai- What exactly do you mean with
trying to connect from sub.example.com to gotify.example.com
Are all (sub) domains are hosted on one server? Do you using the Gotify UI or do you manually call the API of Gotify?
When you receive a 403 unauthorize and its logged in Gotify then its likely not an issue with missing CORS headers. When the CORS headers are missing there should be only an "OPTIONS" request logged in Gotify and the browser console should show something like this (from chrome):
Access to XMLHttpRequest at 'http://localhost/version' from origin 'http://localhost:3001' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
@jmattheis The subdomains are spread over multiple servers - and all subdomains are running in their own docker-container - gotify is also running in it's own container.
Hmm, I think you're right about the CORS. What we tried were
- Open Gotify UI
- Break in javascript where it creates the websocet connection (MessageAction.ts:76)
- Copy the url (including the token)
- Run in Chrome Devtools on one of the other domains
The error we get are: "WebSocket connection to 'wss://gotify.example.com/stream?token=CQ.bCn8b6Y.2ZYh' failed: Error during WebSocket handshake: Unexpected response code: 403"
@fMads Do you use an nginx proxy or something similar or do you directly connecting to Gotify. Does the rest of the application work and only the websocket connection is failing?
@jmattheis Yes, we use nginx proxy (also running in container).
The Gotify UI works perfectly fine - and we are able to connect with rest and post messages (which shows up in Gotify UI - loaded by websocket).
So yes - everything works perfectly fine - except for creating websocket from other domains.
@fMads Have you added websocket upgrade headers to your nginx configuration?
This is my proxy configuration: Both upgrade and connection headers are necessary for websockets to work.
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:6666/;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;
}
@jmattheis We don't have anything about the Upgrade Header, no. But since Gotify UI actually works (even with the Websocket), it must work? :)
Also - if I give an invalid toten (or no token at all) from a different subdomain I get the following error: "WebSocket connection to 'wss://gotify.example.com/stream?token=AHnSXR8aN131E0J' failed: HTTP Authentication failed; no valid credentials available".
Doesn't that mean, that an actually connection is made to the Gotify Server? (now I'm actually getting different error messages base on valid/invalid token)
What? The websocket works now? When I omit the headers I get the following error in the browser console:
MessageAction.ts:70 WebSocket connection to 'wss://push.mydomain.de/stream?token=mytoken failed: Error during WebSocket handshake: Unexpected response code: 400
Yeah the connection should work fine even if you get a 403 error, tho the 403 error could come from the nginx proxy and not from Gotify. Are there 403 Log entries in the Gotify log?
@jmattheis Gotify UI has worked all along - also with websocet. It's only connection to websocket from different domain, that fails..
And I just found the Upgrade-config in our nginx proxy - so that is configured correctly.
Here are the Gotify log (the first line is when I tried to authenticate in DevTools while on Gotify UI-page - the second line is when I tried the same from a different domain)
[GIN] 2018/11/13 - 21:40:14 | 200 | 775.322µs | 192.168.1.11 | GET /stream?token=CZ0gZuNeZSi3w1K
[GIN] 2018/11/13 - 21:40:30 | 403 | 198.033µs | 192.168.1.11 | GET /stream?token=CZ0gZuNeZSi3w1K
@jmattheis @Nicolai- Just pointed out for me, that the issue may be in checkSameOrigin in stream.go.
That looks very much like the issue we have here :) Should I create a new issue for doing something about that? Maybe have a list of accepted domains or a regex for checking?
@fMads This should also be fixed in this issue.
@jmattheis Can we close this issue ?
@madding there is still this todo.
Same origin should always be allowed. Also an additional config property should be added, something like websocket allowed origins. This could be an regex or a list of domains, I'm still unsure what's better.
@jmattheis something like this ?
Well that would work for us, this is what we want.
But I also see it as a major change in how the server works, as now suddenly all sub domains are allowed. If this is not how it is going to be, then I would vote for an regex config.
I think subdomains must be allowed by default, but we can add opition in configuration for this.
@madding Allowing all subdomains seems like a security risk. F.ex. some hosting services give customers a free subdomain, with your change every other customer on that platform could access Gotify.
I'd prefer a list of regexes, something like this
server:
stream:
allowedorigins:
- ".+\\.example\\.de"
- "otherdomain\\.de"
Same origin should always be allowed.
Fixed in v1.2.1. Thanks @madding!