Skip to content

Commit 1d5ce27

Browse files
committed
Do not store last valid token. Remove all previously stored tokens.
1 parent 83be3ad commit 1d5ce27

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jwt.io",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/jsonwebtoken/jsonwebtoken.github.io"

src/editor/index.js

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
2-
deferToNextLoop,
3-
safeLocalStorageSetItem
2+
deferToNextLoop
43
} from '../utils.js';
54
import { downloadPublicKeyIfPossible } from './public-key-download.js';
65
import { setupClaimsTooltip } from './claims-tooltip.js';
@@ -190,33 +189,6 @@ function markAsInvalidWithElement(element, clearTokenEditor = true) {
190189
}
191190
}
192191

193-
function saveAsLastToken() {
194-
const token = getTrimmedValue(tokenEditor);
195-
if(token && token.length > 0) {
196-
safeLocalStorageSetItem('lastToken', token);
197-
}
198-
199-
const publicKey = publicKeyTextArea.value;
200-
if(publicKey && publicKey.length > 0) {
201-
safeLocalStorageSetItem('lastPublicKey', publicKey);
202-
}
203-
}
204-
205-
function loadToken() {
206-
const lastToken = localStorage.getItem('lastToken');
207-
208-
if(lastToken) {
209-
setTokenEditorValue(lastToken);
210-
211-
const lastPublicKey = localStorage.getItem('lastPublicKey');
212-
if(lastPublicKey) {
213-
publicKeyTextArea.value = lastPublicKey;
214-
}
215-
} else {
216-
useDefaultToken('HS256');
217-
}
218-
}
219-
220192
function encodeToken() {
221193
deferToNextLoop(fixEditorHeight);
222194

@@ -251,7 +223,6 @@ function encodeToken() {
251223
sign(header, payload, key, secretBase64Checkbox.checked).then(encoded => {
252224
eventManager.withDisabledEvents(() => {
253225
tokenEditor.setValue(encoded);
254-
saveAsLastToken();
255226
});
256227
}).catch(e => {
257228
eventManager.withDisabledEvents(() => {
@@ -289,7 +260,6 @@ function decodeToken() {
289260
if(decoded.errors) {
290261
markAsInvalidWithElement(editorElement, false);
291262
} else {
292-
saveAsLastToken();
293263
verifyToken();
294264
}
295265
} catch(e) {
@@ -321,6 +291,15 @@ function verifyToken() {
321291
});
322292
}
323293

294+
// The last saved token functionality has been flagged as a security issue.
295+
// This function removes any locally stored tokens in the past.
296+
// Once a considerable amount of time has passed since this was put in place,
297+
// it may be safe to remove it. Enabled at: 2018-06-12.
298+
function removeSavedTokens() {
299+
localStorage.removeItem('lastToken');
300+
localStorage.removeItem('lastPublicKey');
301+
}
302+
324303
function setupTabEvents() {
325304
// These are relevant for portrait or mobile screens.
326305

@@ -390,8 +369,9 @@ export function setupTokenEditor() {
390369
disableUnsupportedAlgorithms();
391370
setupEvents();
392371
selectAlgorithm('HS256');
393-
loadToken();
372+
useDefaultToken('HS256');
394373
fixEditorHeight();
395374
setupSecretLengthTooltip();
396375
setupClaimsTooltip();
376+
removeSavedTokens();
397377
}

test/functional/editor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ describe('Editor', function() {
10871087
expect(invalid).to.be.true;
10881088
});
10891089

1090-
it('Saves last edited token', async function() {
1090+
it('Does NOT save the last edited token', async function() {
10911091
await this.page.select('#algorithm-select', 'HS256');
10921092

10931093
const secretInput = await this.page.$('input[name="secret"]');
@@ -1117,7 +1117,7 @@ describe('Editor', function() {
11171117
return JSON.parse(window.test.payloadEditor.getValue());
11181118
});
11191119

1120-
expect(storedPayload).to.deep.equal(payload);
1120+
expect(storedPayload).to.not.deep.equal(payload);
11211121
});
11221122

11231123
describe('JWT share button', function() {

0 commit comments

Comments
 (0)