Ver código fonte

fix: sanitize URLs used for OAuth auth flow (via #5190)

* fix: sanitize URLs used for OAuth auth flow

* embetter test case

* fix linter issue
bubble
kyle 5 anos atrás
committed by GitHub
pai
commit
1e184e8e21
Nenhuma chave conhecida encontrada para esta assinatura no banco de dados ID da chave GPG: 4AEE18F83AFDEB23
3 arquivos alterados com 32 adições e 3 exclusões
  1. +4
    -3
      src/core/oauth2-authorize.js
  2. +5
    -0
      test/e2e-cypress/static/documents/xss/oauth2.yaml
  3. +23
    -0
      test/e2e-cypress/tests/features/xss/oauth2.js

+ 4
- 3
src/core/oauth2-authorize.js Ver arquivo

@@ -1,5 +1,5 @@
import win from "core/window"
import { btoa } from "core/utils"
import { btoa, sanitizeUrl } from "core/utils"

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

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

// pass action authorizeOauth2 and authentication data through window
// to authorize with oauth2


+ 5
- 0
test/e2e-cypress/static/documents/xss/oauth2.yaml Ver arquivo

@@ -0,0 +1,5 @@
swagger: '2.0'
securityDefinitions:
a:
type: oauth2
authorizationUrl: javascript:alert(document.domain)//

+ 23
- 0
test/e2e-cypress/tests/features/xss/oauth2.js Ver arquivo

@@ -0,0 +1,23 @@
describe("XSS: OAuth2 authorizationUrl sanitization", () => {
it("should filter out a javascript URL", () => {
cy.visit("/?url=/documents/xss/oauth2.yaml")
.window()
.then(win => {
let args = null
const stub = cy.stub(win, "open", (...callArgs) => {
args = callArgs
}).as("windowOpen")

cy.get(".authorize")
.click()
.get(".modal-btn.authorize")
.click()
.wait(100)
.then(() => {
console.log(args)
expect(args[0]).to.match(/^about:blank/)
})

})
})
})

Carregando…
Cancelar
Salvar