Gitea: User settings -> security IconHTML error #19

Closed
opened 2023-12-20 15:29:41 +00:00 by cyclane · 2 comments
Owner

500 error on user settings -> security tab:

An error occurred:

Render failed, failed to render template: user/settings/security/security, error: template error: builtin(bindata):user/settings/security/accountlinks:32:20 : executing "user/settings/security/accountlinks" at <$providerData.IconHTML>: nil pointer evaluating oauth2.Provider.IconHTML
----------------------------------------------------------------------
					{{$providerData.IconHTML 20}}
					               ^
----------------------------------------------------------------------
500 error on user settings -> security tab: ``` An error occurred: Render failed, failed to render template: user/settings/security/security, error: template error: builtin(bindata):user/settings/security/accountlinks:32:20 : executing "user/settings/security/accountlinks" at <$providerData.IconHTML>: nil pointer evaluating oauth2.Provider.IconHTML ---------------------------------------------------------------------- {{$providerData.IconHTML 20}} ^ ---------------------------------------------------------------------- ```
cyclane added the
Kind/Bug
Priority
Medium
labels 2023-12-20 15:29:41 +00:00
cyclane added this to the Services project 2023-12-20 15:29:42 +00:00
Author
Owner

So it seems here a list is indexed by an ID (instead of looking up by the ID).

...
				{{$providerData := index $.OAuth2Providers $loginSource.Name}}
				<div class="flex-item-leading">
					{{$providerData.IconHTML 20}}
...

This means you can break it by:

  1. add a provider (ID 0)
    • len(providers) == 1
  2. add another provider (ID 1)
    • len(providers) == 2
  3. make a user using provider 2 (ID 1)
  4. remove provider 1 (ID 0)
    • len(providers) == 1
  5. this user will now see this error since providers[1] == nil

I guess I'll make a PR to gitea at some point 🤷.

So it seems [here](https://github.com/go-gitea/gitea/blob/cb10f2767c920fdbca6fc43e71dcc4c4b8c6e0d0/templates/user/settings/security/accountlinks.tmpl#L30-L32) a list is indexed by an ID (instead of looking up by the ID). ```gotmpl ... {{$providerData := index $.OAuth2Providers $loginSource.Name}} <div class="flex-item-leading"> {{$providerData.IconHTML 20}} ... ``` This means you can break it by: 1. add a provider (ID 0) - `len(providers) == 1` 2. add another provider (ID 1) - `len(providers) == 2` 3. make a user using provider 2 (ID 1) 4. remove provider 1 (ID 0) - `len(providers) == 1` 5. this user will now see this error since `providers[1] == nil` I guess I'll make a PR to gitea at some point :shrug:.
Author
Owner
  1. Above message is just completely wrong (though the basic area of the problem was somewhat right).
  2. Refer to gitea #28667, will be fixed in 1.22.
1. Above message is just completely wrong (though the basic area of the problem was somewhat right). 2. Refer to [gitea #28667](https://github.com/go-gitea/gitea/issues/28667), will be fixed in 1.22.
Sign in to join this conversation.
No description provided.