Verify state before using errors received from provider #144
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.
Summary
This avoids content spoofing attacks by crafting a URL with malicious messages, because the
state
param is only present in the session after a valid OAuth2 authentication flow.Background
This vulnerability was reported to GitLab in https://gitlab.com/gitlab-org/gitlab/-/issues/27241 and patched for the 14.3.1 security release in https://gitlab.com/gitlab-org/gitlab/-/commit/79457dafe55. We haven't encountered any problems with this change in our testing and usage.
An example URL to exploit this is https://gitlab.com/users/auth/bitbucket/callback?state=cae8687aa809fc45e00b2f8ed4a0ea124d5f9b8235cb2b2e&error_description=YOUR+ACCOUNT+WAS+LOCKED,PLEASE+GO+TO+https://evil.com+FOR+UNLOCKING+YOUR+ACCOUNT&error=access_denied, previously this would render the attacker's URL in the flash message (which IIRC is the default behaviour when using OmniAuth with Devise), but after this change we'll get the CSRF error instead.
The vulnerability is pretty minor overall, but the fix is also simple so I think this would be worth upstreaming 馃榾