Skip to content

Commit c4269e2

Browse files
martinjagodicclaude
andcommitted
fix(lib-auth): reject OAuth callbacks when no login was started
validateNonce compared the callback's state nonce with the one stored in sessionStorage without checking that one was stored. With no login in progress the stored side is null, so a crafted callback carrying state={"nonce":null} passed the check and signed the victim in with the attacker's token (login CSRF) on the implicit flow. Only accept a non-empty string nonce that matches the stored one. Fixes GHSA-h6vp-4qr8-gvh5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1a1d148 commit c4269e2

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎packages/decap-cms-lib-auth/src/__tests__/utils.spec.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ describe('auth utils', () => {
1313
expect(window.sessionStorage.getItem('decap-cms-auth')).toBeNull();
1414
});
1515

16+
it('should reject a callback when no login was started', () => {
17+
expect(validateNonce(null)).toBe(false);
18+
expect(validateNonce(undefined)).toBe(false);
19+
expect(validateNonce('')).toBe(false);
20+
});
21+
22+
it('should reject a null nonce when the stored nonce is not a string', () => {
23+
window.sessionStorage.setItem('decap-cms-auth', JSON.stringify({ nonce: null }));
24+
expect(validateNonce(null)).toBe(false);
25+
26+
window.sessionStorage.setItem('decap-cms-auth', JSON.stringify({}));
27+
expect(validateNonce(undefined)).toBe(false);
28+
});
29+
30+
it('should reject a mismatched nonce', () => {
31+
createNonce();
32+
33+
expect(validateNonce('other')).toBe(false);
34+
expect(validateNonce(null)).toBe(false);
35+
});
36+
1637
it('should not clear local storage nonce key', () => {
1738
window.localStorage.setItem('decap-cms-auth', 'local-only');
1839
const nonce = createNonce();

‎packages/decap-cms-lib-auth/src/utils.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export function validateNonce(check) {
88
const auth = window.sessionStorage.getItem('decap-cms-auth');
99
const valid = auth && JSON.parse(auth).nonce;
1010
window.sessionStorage.removeItem('decap-cms-auth');
11-
return check === valid;
11+
// With no login in progress `valid` is null, so a callback carrying
12+
// state={"nonce":null} would otherwise pass (login CSRF).
13+
return typeof valid === 'string' && valid.length > 0 && check === valid;
1214
}
1315

1416
export function isInsecureProtocol() {

0 commit comments

Comments
 (0)