-
Notifications
You must be signed in to change notification settings - Fork 493
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
Validate current window origin and redirecturi origin to prevent mismatches #615
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -377,6 +377,7 @@ WebAuth.prototype.checkSession = function(options, cb) { | |
.merge(this.baseOptions, [ | ||
'clientID', | ||
'responseType', | ||
'redirectUri', | ||
'scope', | ||
'audience', | ||
'_csrf', | ||
|
@@ -387,7 +388,7 @@ WebAuth.prototype.checkSession = function(options, cb) { | |
.with(options); | ||
|
||
if (params.responseType === 'code') { | ||
return cb(new Error("responseType can't be `code`")); | ||
return cb({ error: 'error', error_description: "responseType can't be `code`" }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why has this changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it was wrong before. you couldn't catch the error because it was not using the standard error formatting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok good was wondering that |
||
} | ||
|
||
if (!options.nonce) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
var IframeHandler = require('../helper/iframe-handler'); | ||
var objectHelper = require('../helper/object'); | ||
var windowHelper = require('../helper/window'); | ||
|
||
function runWebMessageFlow(authorizeUrl, options, callback) { | ||
var handler = new IframeHandler({ | ||
|
@@ -11,8 +12,10 @@ function runWebMessageFlow(authorizeUrl, options, callback) { | |
timeout: options.timeout, | ||
eventValidator: { | ||
isValid: function(eventData) { | ||
return eventData.event.data.type === 'authorization_response' | ||
&& options.state === eventData.event.data.response.state; | ||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also prettier |
||
eventData.event.data.type === 'authorization_response' && | ||
options.state === eventData.event.data.response.state | ||
); | ||
} | ||
}, | ||
timeoutCallback: function() { | ||
|
@@ -33,6 +36,20 @@ WebMessageHandler.prototype.run = function(options, cb) { | |
var _this = this; | ||
options.responseMode = 'web_message'; | ||
options.prompt = 'none'; | ||
|
||
var currentOrigin = windowHelper.getOrigin(); | ||
var redirectUriOrigin = objectHelper.getOriginFromUrl(options.redirectUri); | ||
if (currentOrigin !== redirectUriOrigin) { | ||
return cb({ | ||
error: 'origin_mismatch', | ||
error_description: "The redirectUri's origin (" + | ||
redirectUriOrigin + | ||
") should match the window's origin (" + | ||
currentOrigin + | ||
').' | ||
}); | ||
} | ||
|
||
runWebMessageFlow(this.webAuth.client.buildAuthorizeUrl(options), options, function( | ||
err, | ||
eventData | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the new line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prettier auto formatting.