Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

CORS and websocket origin allowlists match unanchored, so 'https://example.com' also allows 'https://example.com.evil.net'

Chiusa
#1,052 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go
Ambito
api, security

Direzione di ricerca

Start with auth/cors.go:45 and api/stream/stream.go:183, tracing compileAllowedCORSOrigins and compileAllowedWebSocketOrigins to their AllowOriginFunc and Upgrader.CheckOrigin callers. Run the existing CORS and websocket tests if present, then add coverage showing the configured origin is accepted while a hostname with an appended suffix is rejected in both paths. Done means the chosen behavior is tested and any required configuration documentation or release note is updated.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

a:bug

Both origin allowlists compile config entries with regexp.MustCompile and match with MatchString, which is a substring match unless the operator remembers to anchor:

  • auth/cors.go:45 → compileAllowedCORSOrigins, used by AllowOriginFunc
  • api/stream/stream.go:183 → compileAllowedWebSocketOrigins, used by Upgrader.CheckOrigin

So a natural-looking value matches any hostname that merely contains it:

$ GOTIFY_SERVER_CORS_ALLOWORIGINS='https://gotify.example.com' gotify serve

$ curl -sD- -o/dev/null -H 'Origin: https://gotify.example.com' localhost:8792/version
Access-Control-Allow-Origin: https://gotify.example.com
$ curl -sD- -o/dev/null -H 'Origin: https://gotify.example.com.evil.net' localhost:8792/version
Access-Control-Allow-Origin: https://gotify.example.com.evil.net      # <-- allowed
$ curl -sD- -o/dev/null -H 'Origin: http://evil.net' localhost:8792/version
(no ACAO header)

Impact is limited — AllowCredentials is never set, so the cookie is not sent cross-origin, and an attacker still needs a token to read anything — but the allowlist does not mean what an operator reading the env var name would assume, and the same footgun applies to GOTIFY_SERVER_STREAM_ALLOWEDORIGINS on the websocket.

Options, in rough order of preference:

  1. Anchor automatically: wrap each entry as ^(?:…)$ before compiling (breaks any existing config that relies on a trailing .*, so it would need a release note).
  2. Keep the regex but warn at startup when an entry is not anchored.
  3. Document the anchoring requirement in the config docs, at minimum.

Happy to send a PR for whichever you prefer.

Lingua principale
Go
Stelle
16k
Fork
891
Merge medio
2g 11h
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di gotify/server

Tutte le issue di gotify/server

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.