Commit Graph

105 Commits

Author SHA1 Message Date
Jannis Mattheis
c256025b9f fix: return client id and elevatedUntil on /current/user 2026-04-19 19:24:18 +02:00
Jannis Mattheis
58677b32ef fix: add client elevatedUntil 2026-04-19 19:22:31 +02:00
Jannis Mattheis
410571dd18 fix: prevent duplicate requests for apps / clients 2026-04-19 19:22:30 +02:00
Jannis Mattheis
681b9e2d90 fix: unify authentication context
This uses a single struct for the authentication. This prevents further
re-requesting of the already requested data.
2026-04-19 19:22:03 +02:00
Jannis Mattheis
d432900486 fix: logout to /auth/logout and swagger docs
With session elevation, we cannot use DELETE /client as this requires
elevation. It should be possible to logout without an elevated session.

This makes the logout endpoint public api to be used by the android app.
2026-04-19 18:00:16 +02:00
Jannis Mattheis
2674f729eb fix: use decay map 2026-04-11 18:53:48 +02:00
Jannis Mattheis
fb6f90bf59 fix: don't store client name in state 2026-04-11 18:53:48 +02:00
Jannis Mattheis
491325b06f test: oidc tests
It's not easy to test this automatically without a real oidc server.
2026-04-11 18:53:48 +02:00
Jannis Mattheis
6d53859b77 feat: add external oidc flow
Add two new endpoints for native app OIDC authentication using the
PKCE relay pattern (similar to Vaultwarden's SSO implementation):

- POST /auth/oidc/external/authorize - accepts a PKCE code_challenge
from the client, forwards it to the IdP, and returns the authorize URL
- POST /auth/oidc/external/token - accepts the auth code and
code_verifier, relays them to the IdP for token exchange, and returns
a gotify client token

The server never generates its own PKCE pair for this flow. It then relays
the client's code_challenge to the IdP during authorization and the
code_verifier during token exchange. The IdP validates the binding.
Pending auth sessions are stored in memory with a 10-minute TTL.

CSRF protection is provided by the state parameter, which contains a
cryptographically random nonce and is validated on the token exchange.
The state is single-use (deleted from the pending session map on lookup),
preventing replay attacks. Even without single-use enforcement, replay
would be harmless since the IdP's authorization code can only be
exchanged once.
2026-04-11 18:53:48 +02:00
Jannis Mattheis
f130ebe194 fix: add /gotifyconfig endpoint 2026-04-11 18:53:48 +02:00
Jannis Mattheis
cfaddfe255 feat: oidc 2026-04-11 18:53:48 +02:00
Jannis Mattheis
57878e0574 fix: make secure cookie configurable 2026-04-11 18:53:48 +02:00
Jannis Mattheis
50d0572584 feat: implement /auth/local/{login,logout} 2026-04-11 18:53:48 +02:00
Jannis Mattheis
a1f83c5ef8 fix: enforce sort_key is unique per user 2026-01-28 18:46:21 +01:00
Jannis Mattheis
278b873b5b feat: add sort_key to backend 2026-01-24 13:28:40 +01:00
Laurence
883cc15bae fix: hide delete overlay for default app images 2025-11-16 11:27:28 +01:00
Laurence Jones
71e38b9824 Add file type restriction to image upload input using accept attribute (#872)
* Add file type restriction to image upload input using accept attribute

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

---------

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
Co-authored-by: eternal-flame-AD <yume@yumechi.jp>
2025-11-05 21:03:06 +00:00
饺子w (Yumechi)
496c166981 chore: Migrate github.com/jinzhu/gorm to gorm.io/gorm (#863)
* chore: Migrate github.com/jinzhu/gorm to gorm.io/gorm

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* chore: drop singleton connection limit on sqlite3 backend

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* enhance: database logging

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* Revert "chore: drop singleton connection limit on sqlite3 backend"

This reverts commit b494a3bd1f.

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* typo

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* rename unique_index -> uniqueIndex

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* drop uniqueIndex on primary key

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* migrate fully to new gorm tag format

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* specify unique index name

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* remove pluginConf duplicate index

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* disable auto migrate FK

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

---------

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
2025-10-29 22:23:10 +00:00
昨夜雨疏风骤
4bc42d2c1d Optimize uniq function for better performance (#852)
Improve the performance of the unique function by:
1. Pre-allocating map capacity with len(s) to avoid frequent map resizing
2. Pre-allocating result slice capacity with len(s) to reduce append overhead
3. Reducing the number of traversals performs well under the condition of a large number of elements

These changes maintain the original behavior (preserving element order) 
while reducing memory allocation operations, especially effective for 
large slices (100k+ elements) with benchmark showing ~25% speedup.

No breaking changes, the function signature and output order remain unchanged.
2025-10-03 01:17:47 +00:00
renovate[bot]
a0bad7bd5a chore(deps): update bump go dependencies (#751)
* chore(deps): update bump go dependencies

* Update golangci-lint

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* Update golangci config to reflect new format

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* remove deprecated ioutil package

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

---------

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: eternal-flame-AD <yume@yumechi.jp>
2025-01-17 05:51:08 +00:00
renovate[bot]
60bafd2b98 chore(deps): update module gopkg.in/yaml.v2 to v3 (#719)
* chore(deps): update module gopkg.in/yaml.v2 to v3

* fixup! chore(deps): update module gopkg.in/yaml.v2 to v3

---------

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: eternal-flame-AD <yume@yumechi.jp>
2024-11-07 17:34:22 -06:00
Eng Zer Jun
0bfa5ca4d9 perf: avoid allocations with (*regexp.Regexp).MatchString (#604)
We should use `(*regexp.Regexp).MatchString` instead of
`(*regexp.Regexp).Match([]byte(...))` when matching string to avoid
unnecessary `[]byte` conversions and reduce allocations.

Example benchmark:

var allowedOrigin = regexp.MustCompile(".*.example.com")

func BenchmarkMatch(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := allowedOrigin.Match([]byte("www.example.com")); !match {
			b.Fail()
		}
	}
}

func BenchmarkMatchString(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := allowedOrigin.MatchString("wwww.example.com"); !match {
			b.Fail()
		}
	}
}

goos: linux
goarch: amd64
pkg: github.com/gotify/server/v2/api/stream
cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
BenchmarkMatch-16          	 2076819	       647.7 ns/op	      16 B/op	       1 allocs/op
BenchmarkMatchString-16    	 2536326	       442.0 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/gotify/server/v2/api/stream	3.552s

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-10-23 15:57:15 +00:00
Jannis Mattheis
dec762f9ed fix: remove unused code 2023-09-16 21:06:54 +02:00
Jannis Mattheis
9592cc95c9 fix: update go-swagger 2023-09-16 21:06:54 +02:00
Jannis Mattheis
a3ce298729 Fix stream_test flakiness 2023-08-06 12:30:22 +02:00
eternal-flame-AD
7bf80ee6f1 Add last used to client & application 2023-08-06 12:30:22 +02:00
Jannis Mattheis
835adeec79 Fix test assertions 2023-07-30 15:39:19 +02:00
Jannis Mattheis
bda27946da Update deps 2023-07-30 15:39:15 +02:00
chrispruitt
72bd8c8ba6 Add default message priority for applications
Co-authored-by: Jannis Mattheis <contact@jmattheis.de>
2023-07-19 18:15:01 +00:00
Helmut K. C. Tessarek
5cd2d5411f Add delete application image endpoint 2023-05-28 13:59:49 +00:00
mateuscelio
f3d121bd61 Adds ClientParams strcut to handle creation and update params 2023-04-28 16:11:40 +02:00
Jannis Mattheis
33d86e41c2 Only serve image files on ./image
This is an addition to the existing XSS fix in the previous commit.
2022-12-29 12:46:41 +01:00
Jannis Mattheis
925fb7e2c9 Fix file upload XSS
The application image file upload allowed authenticated users to upload
malious .html files. Opening such a file like

https://push.gotify.net/image/ViaxrjzNowdgL-xnEfVV-Ggv5.html

would allow the attacker to execute client side scripts.

The application image upload will now only allow the upload of files
with the following extensions: .gif, .png, .jpg and .jpeg.
2022-12-28 20:13:35 +01:00
mateuscelio
0fb584d7f7 Update docs 2022-12-03 10:45:07 +01:00
Jannis Mattheis
fcd9b88bb7 Fix required mismatch in update & create user
This shouldn't break the api.
2022-09-10 16:47:22 +02:00
mateuscelio
f16ce59e6c Prevent setting id while inserting / updating applications 2022-07-24 08:48:14 +00:00
pigpig
c172590b92 Add registration
Can be enabled via the registration config flag. (disabled per default)

Fixes gotify/server#395

Co-authored-by: pigpig <pigpig@pig.pig>
Co-authored-by: Karmanyaah Malhotra <32671690+karmanyaahm@users.noreply.github.com>
Co-authored-by: Jannis Mattheis <contact@jmattheis.de>
2021-08-04 19:39:43 +02:00
Jannis Mattheis
3454dcd602 Use golangci-lint 2020-11-01 10:47:02 +01:00
Jannis Mattheis
909eeff406 Make keepalive period configurable 2020-09-10 16:22:04 +00:00
Richard Szolár
923030cf44 Update "github.com/go-yaml/yaml" import path to "gopkg.in/yaml.v2" as recommended per the project's documentation 2020-08-20 20:25:37 +02:00
Jannis Mattheis
d45e0da6a8 Allow delete for > uint32 ids
For ids uint is used, this is platform specific and either uint32
or uint64. The parsing for parameters in the api expected the ids to
have 32bit size.

I thought about changing all our ids to int64 but we sadly have one uint
usage in the plugin api:
b0e2eca8e3/plugin.go (L13-L14)
2020-07-01 19:44:06 +02:00
Jannis Mattheis
757fa17d26 Use int64 as input 2020-06-24 18:32:35 +02:00
Jannis Mattheis
a9249bbd28 Don't use id provided from POST /message api 2020-06-23 18:39:43 +02:00
Jannis Mattheis
7b90b8a8f5 Use v2 in package path 2020-05-08 10:43:17 +02:00
Jannis Mattheis
0a7a5cd619 Add logging to websocket errors 2019-11-28 21:39:47 +01:00
Jannis Mattheis
81c4a73df3 Add health api 2019-08-16 09:28:57 +02:00
饺子w
67493c643e Return 500 server error on database failures (#191) 2019-05-25 08:37:24 +02:00
GianOrtiz
e32359ed15 Add update client api and dialog (#164) 2019-03-16 11:18:51 +01:00
饺子w
efcf4ad13d Use crypto/rand for token generation (#161) 2019-03-16 11:10:28 +01:00
饺子w
178c76f410 Fix websocket allowed origin (#150) 2019-03-14 18:16:24 +01:00