Reflected XSS in OAuth complete endpoints
The OAuth completion endpoints reflect the redirect_to value taken from the state query parameter into the page without sanitising it. An attacker could craft a link that runs JavaScript in the victim's browser and make requests on the victim's behalf.
Originally disclosed on HackerOne
- Disclosed after 19 months
Summary:
The following endpoints are vulnerable to reflected XSS:
GET /oauth/{service:[A-Za-z0-9]+}/complete
GET /api/v3/oauth/{service:[A-Za-z0-9]+}/complete
GET /signup/{service:[A-Za-z0-9]+}/complete
GET /login/{service:[A-Za-z0-9]+}/complete
The vulnerability exists due to the lack of sanitizing redirect_to field in state query param here.
Steps To Reproduce:
- Setup local mattermost instance e.g. on address http://localhost:8065 (server guide, webapp guide)
- Enable gitlab auth at Enable gitlab auth at http://localhost:8065/admin_console/authentication/gitlab. (There may be other ways to enable OAuth, this one seemed the easiest to me)
- Open the following link: http://mattermost:8065/login/gitlab/complete?code=x&state=eyJhY3Rpb24iOiJtb2JpbGUiLCJyZWRpcmVjdF90byI6InRlc3RcIj48c2NyaXB0PmFsZXJ0KGRvY3VtZW50LmRvbWFpbik8L3NjcmlwdD4ifQ==. This link contains base64-encoded payload in
stateparam:{"action":"mobile","redirect_to":"test\"><script>alert(document.domain)</script>"} - Get javascript alert with current domain.
Impact
An attacker can distribute a link in a chat with malicious javascript code. This code can send ajax requests on behalf of the user.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the redirect_to value decoded from the state parameter is written into the response without output encoding or validation.
Impact
An attacker could send a link in a chat that runs JavaScript in the victim's browser, which could then send requests on the victim's behalf.
What the attacker needed
A Mattermost instance with an OAuth provider enabled; victim clicks a crafted link
How it was found
- Set up a local Mattermost instance.
- Enable GitLab authentication in the admin console.
- Open a login completion link whose state parameter carries a crafted redirect_to value.
- Observe the JavaScript alert showing the current domain.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you log in with another service such as GitLab, the site passes a small piece of data called state back and forth to remember where to send you afterwards. This report shows that the site put part of that data straight into the web page without cleaning it, so a crafted link could make the page run code written by the attacker. That code runs as the logged-in user and can act on their behalf.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.