Skip to content
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

Catch the error before the response is processed by goth. #20000

Merged
merged 16 commits into from
Jun 20, 2022
Merged

Catch the error before the response is processed by goth. #20000

merged 16 commits into from
Jun 20, 2022

Conversation

SteveTheEngineer
Copy link

@SteveTheEngineer SteveTheEngineer commented Jun 17, 2022

The code introduced by #18185 gets the error from response after it was processed by goth.

That is incorrect, as goth (and golang.org/x/oauth) doesn't really care about the error, and it sends a token request with an empty authorization code to the server anyway, which always results in a oauth2: cannot fetch token: 400 Bad Request error from goth.
It means that unless the "state" parameter is omitted from the error response (which is required to be present, according to RFC 6749, Section 4.1.2.1) or the page is reloaded (makes the session invalid), a 500 Internal Server Error page will be displayed.
This fixes it by handling the error before the request is passed to goth.

@6543 6543 added type/enhancement An improvement of existing functionality type/bug and removed type/enhancement An improvement of existing functionality labels Jun 17, 2022
@6543 6543 added this to the 1.17.0 milestone Jun 17, 2022
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Jun 18, 2022
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 18, 2022
Copy link
Contributor

@zeripath zeripath left a comment

Choose a reason for hiding this comment

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

Actually do we to tell goth that this request has failed and to cancel any data it has too?

@zeripath
Copy link
Contributor

(My review can be dismissed if we can get an answer on this.)

@SteveTheEngineer
Copy link
Author

Actually do we to tell goth that this request has failed and to cancel any data it has too?

Yes.

@wxiaoguang
Copy link
Contributor

IMO it's also fine for doing nothing in the error callback. Just like there is a network error occurring during the callback, Gitea even wont't get the response callback, then nothing happens, nothing wrong in the end.

And it's also fine to call the Logout to clear the data in session, just like what oauth2Source.Callback does (oauth2Source.Callback -> gothic.CompleteUserAuth -> Logout).

LGTM

@lunny lunny dismissed zeripath’s stale review June 18, 2022 14:18

It's ready to merge

@6543 6543 modified the milestones: 1.17.0, 1.18.0 Jun 18, 2022
@zeripath zeripath merged commit 1e2c2ed into go-gitea:main Jun 20, 2022
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jun 21, 2022
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Catch the error before the response is processed by goth. (go-gitea#20000)
  Adjust transaction handling via db.Context (go-gitea#20031)
  Add more linters to improve code readability (go-gitea#19989)
  [skip ci] Updated translations via Crowdin
  Disable federation by default (go-gitea#20045)
  Respond with a 401 on git push when password isn't changed yet (go-gitea#20026)
  Alter hook_task TEXT fields to LONGTEXT (go-gitea#20038)
  Simplify and fix migration 216 (go-gitea#20035)
  use quoted regexp instead of git fixed-value (go-gitea#20029)
  fix delete pull head ref for DeleteIssue (go-gitea#20032)
  User keypairs and HTTP signatures for ActivityPub federation using go-ap (go-gitea#19133)
  Backtick table name in generic orphan check (go-gitea#20019)
  Update document to clarify that ALLOWED_DOMAINS/BLOCKED_DOMAINS support wildcard (go-gitea#20016)
  Return 404 when tag is broken (go-gitea#20017)
  Dump should only copy regular files and symlink regular files (go-gitea#20015)
@6543
Copy link
Member

6543 commented Jun 23, 2022

please send a backport

@zeripath zeripath added the backport/done All backports for this PR have been created label Jun 23, 2022
lunny pushed a commit that referenced this pull request Jun 24, 2022
…20102)

The code introduced by #18185 gets the error from response after it was processed by goth.

That is incorrect, as goth (and golang.org/x/oauth) doesn't really care about the error, and it sends a token request with an empty authorization code to the server anyway, which always results in a `oauth2: cannot fetch token: 400 Bad Request` error from goth.
It means that unless the "state" parameter is omitted from the error response (which is required to be present, according to [RFC 6749, Section 4.1.2.1](https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1)) or the page is reloaded (makes the session invalid), a 500 Internal Server Error page will be displayed.
This fixes it by handling the error before the request is passed to goth.
vsysoev pushed a commit to IntegraSDL/gitea that referenced this pull request Aug 10, 2022
…0000)

The code introduced by go-gitea#18185 gets the error from response after it was processed by goth.

That is incorrect, as goth (and golang.org/x/oauth) doesn't really care about the error, and it sends a token request with an empty authorization code to the server anyway, which always results in a `oauth2: cannot fetch token: 400 Bad Request` error from goth.
It means that unless the "state" parameter is omitted from the error response (which is required to be present, according to [RFC 6749, Section 4.1.2.1](https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1)) or the page is reloaded (makes the session invalid), a 500 Internal Server Error page will be displayed.
This fixes it by handling the error before the request is passed to goth.
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants