Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

fix(oidc): widen users.avatar and skip non-URL picture claims (#796)

Gaurav Vijay Jadhavf4976beb9b18
diff --git a/backend/app/migrations/000021_users_avatar_text.down.sql b/backend/app/migrations/000021_users_avatar_text.down.sql
new file mode 100644
index 00000000..c3989a85
--- /dev/null
+++ b/backend/app/migrations/000021_users_avatar_text.down.sql
@@ -0,0 +1 @@
+ALTER TABLE `users` MODIFY `avatar` VARCHAR(150) NULL; -- Values longer than 150 characters make this fail in strict SQL mode
diff --git a/backend/app/migrations/000021_users_avatar_text.up.sql b/backend/app/migrations/000021_users_avatar_text.up.sql
new file mode 100644
index 00000000..0159e2b3
--- /dev/null
+++ b/backend/app/migrations/000021_users_avatar_text.up.sql
@@ -0,0 +1 @@
+ALTER TABLE `users` MODIFY `avatar` TEXT NULL; -- OIDC providers can send long picture URLs (see issue #775)
diff --git a/backend/services/oidc.service.go b/backend/services/oidc.service.go
index b6653b30..284b4aee 100644
--- a/backend/services/oidc.service.go
+++ b/backend/services/oidc.service.go
@@ -311,6 +311,22 @@ func (s *oidcService) createSession(user *models.User, ip, userAgent string) (*m
return session, nil
}
+// maxAvatarURLLength keeps the value well inside the users.avatar TEXT column.
+const maxAvatarURLLength = 2048
+
+// avatarFromPicture returns the OIDC picture claim when it is an http(s) URL of a sane length.
+// Providers such as Authentik send a base64 data URI by default; the frontend only renders
+// http(s) avatars or CDN uploads, so those values are skipped instead of stored.
+func avatarFromPicture(picture *string) *string {
+ if picture == nil || len(*picture) > maxAvatarURLLength {
+ return nil
+ }
+ if !strings.HasPrefix(*picture, "https://") && !strings.HasPrefix(*picture, "http://") {
+ return nil
+ }
+ return picture
+}
+
func (s *oidcService) createUserFromOIDC(userInfo *oidc.UserInfo) (*models.User, error) {
userID := s.snowflake.Generate()
@@ -331,9 +347,7 @@ func (s *oidcService) createUserFromOIDC(userInfo *oidc.UserInfo) (*models.User,
if userInfo.FamilyName != nil && *userInfo.FamilyName != "" {
user.Lastname = userInfo.FamilyName
}
- if userInfo.Picture != nil && *userInfo.Picture != "" {
- user.Avatar = userInfo.Picture
- }
+ user.Avatar = avatarFromPicture(userInfo.Picture)
createdUser, err := s.userRepo.Create(user)
if err != nil {