|
1 | 1 | import { |
2 | | - deferToNextLoop, |
3 | | - safeLocalStorageSetItem |
| 2 | + deferToNextLoop |
4 | 3 | } from '../utils.js'; |
5 | 4 | import { downloadPublicKeyIfPossible } from './public-key-download.js'; |
6 | 5 | import { setupClaimsTooltip } from './claims-tooltip.js'; |
@@ -190,33 +189,6 @@ function markAsInvalidWithElement(element, clearTokenEditor = true) { |
190 | 189 | } |
191 | 190 | } |
192 | 191 |
|
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 | | - |
220 | 192 | function encodeToken() { |
221 | 193 | deferToNextLoop(fixEditorHeight); |
222 | 194 |
|
@@ -251,7 +223,6 @@ function encodeToken() { |
251 | 223 | sign(header, payload, key, secretBase64Checkbox.checked).then(encoded => { |
252 | 224 | eventManager.withDisabledEvents(() => { |
253 | 225 | tokenEditor.setValue(encoded); |
254 | | - saveAsLastToken(); |
255 | 226 | }); |
256 | 227 | }).catch(e => { |
257 | 228 | eventManager.withDisabledEvents(() => { |
@@ -289,7 +260,6 @@ function decodeToken() { |
289 | 260 | if(decoded.errors) { |
290 | 261 | markAsInvalidWithElement(editorElement, false); |
291 | 262 | } else { |
292 | | - saveAsLastToken(); |
293 | 263 | verifyToken(); |
294 | 264 | } |
295 | 265 | } catch(e) { |
@@ -321,6 +291,15 @@ function verifyToken() { |
321 | 291 | }); |
322 | 292 | } |
323 | 293 |
|
| 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 | + |
324 | 303 | function setupTabEvents() { |
325 | 304 | // These are relevant for portrait or mobile screens. |
326 | 305 |
|
@@ -390,8 +369,9 @@ export function setupTokenEditor() { |
390 | 369 | disableUnsupportedAlgorithms(); |
391 | 370 | setupEvents(); |
392 | 371 | selectAlgorithm('HS256'); |
393 | | - loadToken(); |
| 372 | + useDefaultToken('HS256'); |
394 | 373 | fixEditorHeight(); |
395 | 374 | setupSecretLengthTooltip(); |
396 | 375 | setupClaimsTooltip(); |
| 376 | + removeSavedTokens(); |
397 | 377 | } |
0 commit comments