Skip to content

oauth: Increase the max size of Provider to 255 #28664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

oauth: Increase the max size of Provider to 255 #28664

wants to merge 1 commit into from

Conversation

algernon
Copy link
Contributor

There are legit reasons why a Provider ("Authentication Name") can be longer than 25 characters, so lets increase that limit substantially to 255.

To do so, we need a migration too, and AuthenticationForm needs to have the maximum size of its Name field increased similarly.

Fixes #24891, at least for the Provider case.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 30, 2023
There are legit reasons why a Provider ("Authentication Name") can be
longer than 25 characters, so lets increase that limit substantially to
255.

To do so, we need a migration too, and `AuthenticationForm` needs to
have the maximum size of its `Name` field increased similarly.

Fixes #24891, at least for the Provider case.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 30, 2023
@delvh delvh added the type/enhancement An improvement of existing functionality label Dec 30, 2023
Copy link
Member

@KN4CK3R KN4CK3R left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: Following may be wrong. Checking it again. Still don't know why we need that field.

I don't understand why we even have this field. Provider is a copy of the name of the login source.

gitea/models/auth/source.go

Lines 112 to 115 in cb10f27

type Source struct {
ID int64 `xorm:"pk autoincr"`
Type Type
Name string `xorm:"UNIQUE"`

There we don't have a length limit.

It's only used here

if len(opts.Provider) > 0 {
cond = cond.And(builder.Eq{"provider": opts.Provider})
}

to support a name search. And that should just be a sql join to the login_source table.

Therefore I'm against this change. We should just remove that field.

@@ -16,7 +16,7 @@ import (
type AuthenticationForm struct {
ID int64
Type int `binding:"Range(2,7)"`
Name string `binding:"Required;MaxSize(30)"`
Name string `binding:"Required;MaxSize(255)"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This field is not used for the Provider field extended in this PR.

@KN4CK3R
Copy link
Member

KN4CK3R commented Dec 31, 2023

Ok, I was wrong. The field is still used by the migration. For that you have to create a login source for GitHub as example. Then have a user link their local account with that login source. This will create an external login user entry with github in the Provider field because that's the name of the provider given by goth (https://github.com/markbates/goth/blob/f347ee3e9478c9dee76c03d842220a14715cb3e6/providers/github/github.go#L54) Then if you migrate a repo from GitHub the Gitea uploader searchs the external login user table for the external user id and the provider equal to the migration source. This name is provided by the following code. Here we find a warning:

// WARNNING: the name have to be equal to that on goth's library
func (gt GitServiceType) Name() string {
return strings.ToLower(gt.Title())
}

That logic is fragile³

Anyway: The provider name is provided by goth and goth does not use names > 16 characters, so the current 25 characters are enough. The changes to AuthenticationForm are fine for me.

@algernon
Copy link
Contributor Author

Well, the reason this PR was made because in #24891, it was discovered and shown that there is a legit issue with the length of the field, that happens in real installations, and increasing the limit made that problem disappear.

It is not the best solution, it's a band aid, based on findings in the original bug report. I do not have the time or resources to dive deeper than that, so I suppose the way forward is to close this one out.

@algernon algernon closed this Jan 10, 2024
@algernon algernon deleted the for-gitea/b/oauth/field-size-fixes branch January 10, 2024 06:43
@KN4CK3R
Copy link
Member

KN4CK3R commented Jan 10, 2024

No, the comment in #24891 (comment) explains that the access_token, access_token_secret and refresh_token are only 255 characters long but should be much longer.

In #24891 (comment) you can see that the problem is solved and the provider field is still only 25 characters long.

@algernon
Copy link
Contributor Author

And indeed it is so. I misread the original report then! All the more reason to move this to the bin.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/migrations type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Azure AD/Oauth2 - Link External Account operation fails due to MS SQL database error.
4 participants