Skip to content

Commit 1e184e8

Browse files
authored
fix: sanitize URLs used for OAuth auth flow (via #5190)
* fix: sanitize URLs used for OAuth auth flow * embetter test case * fix linter issue
1 parent d9f460f commit 1e184e8

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/core/oauth2-authorize.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import win from "core/window"
2-
import { btoa } from "core/utils"
2+
import { btoa, sanitizeUrl } from "core/utils"
33

44
export default function authorize ( { auth, authActions, errActions, configs, authConfigs={} } ) {
55
let { schema, scopes, name, clientId } = auth
@@ -74,8 +74,9 @@ export default function authorize ( { auth, authActions, errActions, configs, au
7474
}
7575
}
7676

77-
let authorizationUrl = schema.get("authorizationUrl")
78-
let url = [authorizationUrl, query.join("&")].join(authorizationUrl.indexOf("?") === -1 ? "?" : "&")
77+
const authorizationUrl = schema.get("authorizationUrl")
78+
const sanitizedAuthorizationUrl = sanitizeUrl(authorizationUrl)
79+
let url = [sanitizedAuthorizationUrl, query.join("&")].join(authorizationUrl.indexOf("?") === -1 ? "?" : "&")
7980

8081
// pass action authorizeOauth2 and authentication data through window
8182
// to authorize with oauth2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
swagger: '2.0'
2+
securityDefinitions:
3+
a:
4+
type: oauth2
5+
authorizationUrl: javascript:alert(document.domain)//
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
describe("XSS: OAuth2 authorizationUrl sanitization", () => {
2+
it("should filter out a javascript URL", () => {
3+
cy.visit("/?url=/documents/xss/oauth2.yaml")
4+
.window()
5+
.then(win => {
6+
let args = null
7+
const stub = cy.stub(win, "open", (...callArgs) => {
8+
args = callArgs
9+
}).as("windowOpen")
10+
11+
cy.get(".authorize")
12+
.click()
13+
.get(".modal-btn.authorize")
14+
.click()
15+
.wait(100)
16+
.then(() => {
17+
console.log(args)
18+
expect(args[0]).to.match(/^about:blank/)
19+
})
20+
21+
})
22+
})
23+
})

0 commit comments

Comments
 (0)