Fix panic when an invalid oauth2 name is passed (#20820)#20900
Merged
techknowlogick merged 3 commits intoAug 22, 2022
Conversation
Backport go-gitea#20820 When trying to access an invalid oauth2 link, we get an internal server error and can see a panic stack-trace in logs Example: Try to go to this url for a gitea installation https://<gitea_url>/user/oauth2/DoesNotExist?redirect_to= It causes an internal server error Stack trace in log ``` 2022/08/17 01:26:50 routers/web/base.go:134:1() [E] [62fc43da] PANIC: runtime error: invalid memory address or nil pointer dereference /usr/local/go/src/runtime/panic.go:220 (0x453095) /usr/local/go/src/runtime/signal_unix.go:818 (0x453065) /source/routers/web/auth/oauth.go:1100 (0x20f6ef7) /source/routers/web/auth/oauth.go:785 (0x20f4684) /source/modules/web/wrap_convert.go:47 (0x1f45196) /source/modules/web/wrap.go:41 (0x1f433c9) /usr/local/go/src/net/http/server.go:2084 (0x93cace) <clipped> ``` Root cause: In this [line](https://github.com/go-gitea/gitea/blob/a4e91c4197483c94f13e623c962b6b011494e949/models/auth/oauth2.go#L516) here, err is nil. The caller assumes no error and tries to access a `nil *Source`
jolheiser
approved these changes
Aug 21, 2022
lunny
approved these changes
Aug 21, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport #20820
When trying to access an invalid oauth2 link, we get an internal server error and can see a panic stack-trace in logs
Example:
Try to go to this url for a gitea installation
https://<gitea_url>/user/oauth2/DoesNotExist?redirect_to=
It causes an internal server error
Stack trace in log
Root cause:
In this line here, err is nil. The caller assumes no error and tries to access a
nil *Source