Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b9ce614
fix: validate state in OAuth error responses
elvisroy27 Nov 10, 2026
40799d1
test: validate state in OAuth error responses
elvisroy27 Nov 10, 2026
001a32d
test: reject OAuth error response with mismatched state
elvisroy27 Nov 10, 2026
9647461
test: fix mismatched state test expectation
elvisroy27 Nov 10, 2026
7b642ac
test: align error response state fixture
elvisroy27 Nov 10, 2026
1ed4f4e
test: include state in Cordova error response
elvisroy27 Nov 10, 2026
42dd95d
style: fix OAuth error response validation formatting
elvisroy27 Nov 10, 2026
5cb7045
test: cover missing state in OAuth error responses
elvisroy27 Nov 10, 2026
692ca0a
fix: preserve OAuth errors without state context
elvisroy27 Nov 10, 2026
a792686
test: preserve OAuth errors without state context
elvisroy27 Nov 10, 2026
336d62b
test: fix missing-state transaction stub
elvisroy27 Nov 10, 2026
44869dc
fix: validate OAuth error state without token side effects
elvisroy27 Nov 10, 2026
6d91e5d
style: keep parseHash declarations at function scope
elvisroy27 Nov 10, 2026
df64c9a
fix: reject OAuth errors with missing state
elvisroy27 Nov 10, 2026
255c963
test: reject OAuth errors without state
elvisroy27 Nov 10, 2026
9fb1cb5
style: declare state validation variable at function scope
elvisroy27 Nov 10, 2026
024e5b4
fix: preserve transaction until error state is validated
elvisroy27 Nov 11, 2026
19065dc
fix: validate OAuth error state before clearing transaction
elvisroy27 Nov 11, 2026
ac24d8f
Merge upstream master into fix/error-response-state-validation
elvisroy27 Nov 11, 2026
3992970
test: cover OAuth error state edge cases
elvisroy27 Nov 11, 2026
2001cb0
test: reject OAuth error responses with empty state
elvisroy27 Nov 12, 2026
f1fd202
test: reject OAuth errors for expired transactions
elvisroy27 Nov 12, 2026
f10f606
test: reject replayed OAuth error responses
elvisroy27 Nov 12, 2026
d956273
fix: reject empty state in IdP-initiated responses
elvisroy27 Nov 12, 2026
6bf1891
test: prevent empty-state IdP initiated bypass
elvisroy27 Nov 12, 2026
f26ae2a
test: reject empty state in impersonation error responses
elvisroy27 Nov 12, 2026
42c82c5
test: cover transaction storage lifecycle integration
elvisroy27 Nov 12, 2026
3bd11dd
test: cover malformed OAuth state parameters
elvisroy27 Nov 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/web-auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ function WebAuth(options) {
WebAuth.prototype.parseHash = function (options, cb) {
var parsedQs;
var err;
var transaction;
var transactionState;
var shouldBypassStateChecking;

if (!cb && typeof options === 'function') {
cb = options;
Expand All @@ -263,6 +266,27 @@ WebAuth.prototype.parseHash = function (options, cb) {
err.state = parsedQs.state;
}

transaction = parsedQs.state
? this.transactionManager.getStoredTransaction(parsedQs.state, false)
: null;
transactionState = options.state || (transaction && transaction.state) || null;

shouldBypassStateChecking =
!parsedQs.hasOwnProperty('state') &&
!transactionState &&
(options.__enableIdPInitiatedLogin || options.__enableImpersonation);

if (!shouldBypassStateChecking && transactionState !== parsedQs.state) {
return cb({
error: 'invalid_token',
errorDescription: '`state` does not match.'
});
}

if (parsedQs.state) {
this.transactionManager.clearTransaction(parsedQs.state);
}

return cb(err);
}

Expand Down Expand Up @@ -342,7 +366,9 @@ WebAuth.prototype.validateAuthenticationResponse = function (
var transactionStateMatchesState = transactionState === state;

var shouldBypassStateChecking =
!state && !transactionState && options.__enableIdPInitiatedLogin;
!parsedHash.hasOwnProperty('state') &&
!transactionState &&
options.__enableIdPInitiatedLogin;

if (!shouldBypassStateChecking && !transactionStateMatchesState) {
return cb({
Expand Down
6 changes: 4 additions & 2 deletions src/web-auth/transaction-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ TransactionManager.prototype.generateTransaction = function(
};
};

TransactionManager.prototype.getStoredTransaction = function(state) {
TransactionManager.prototype.getStoredTransaction = function(state, clear) {
var transactionData;

transactionData = this.storage.getItem(this.namespace + state);
this.clearTransaction(state);
if (clear !== false) {
this.clearTransaction(state);
}
return transactionData;
};

Expand Down
5 changes: 3 additions & 2 deletions test/plugins/cordova.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ describe('auth0.plugins.cordova', function() {
function(err, result) {
expect(err).to.eql({
error: 'some_error',
errorDescription: 'with a description'
errorDescription: 'with a description',
state: 'foo'
});
expect(result).to.be(undefined);
expect(_this.events).to.eql({});
Expand All @@ -245,7 +246,7 @@ describe('auth0.plugins.cordova', function() {

this.events.loadstart({
url:
'https://wptest.auth0.com/mobile#error=some_error&error_description=with a description'
'https://wptest.auth0.com/mobile#error=some_error&error_description=with a description&state=foo'
});
});

Expand Down
70 changes: 70 additions & 0 deletions test/web-auth/transaction-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,74 @@ context('TransactionManager', function() {
);
});
});

context('transaction storage integration', function() {
beforeEach(function() {
var values = {};
windowHelper.getWindow.callsFake(function() {
return {
location: { host: 'myapp.com', protocol: 'https:' },
localStorage: {
getItem: function(key) {
return Object.prototype.hasOwnProperty.call(values, key)
? values[key]
: null;
},
setItem: function(key, value) {
values[key] = String(value);
},
removeItem: function(key) {
delete values[key];
}
}
};
});

this.storageBackedTm = new TransactionManager({
domain: 'myapp.auth0.com',
__tryLocalStorageFirst: true
});
});

it('persists a transaction through Storage and consumes it only once', function() {
var generated = this.storageBackedTm.generateTransaction(
'integration-app-state',
'integration-state',
'integration-nonce',
null,
true
);

expect(generated).to.be.eql({
state: 'integration-state',
nonce: 'integration-nonce'
});

var transaction = this.storageBackedTm.getStoredTransaction(
generated.state,
false
);
expect(transaction).to.be.eql({
nonce: 'integration-nonce',
appState: 'integration-app-state',
state: 'integration-state',
lastUsedConnection: null
});

var consumedTransaction = this.storageBackedTm.getStoredTransaction(
generated.state
);
expect(consumedTransaction).to.be.eql(transaction);
expect(
this.storageBackedTm.getStoredTransaction(generated.state)
).to.be(null);
});

it('returns no transaction when the stored state key is absent', function() {
expect(
this.storageBackedTm.getStoredTransaction('unknown-integration-state')
).to.be(null);
});
});

});
Loading