|
| 1 | +function loadFromStorageAndCookies() { |
| 2 | + // Populate cookies/LocalStorage combobox |
| 3 | + function checkLoadJwtFromLength() { |
| 4 | + var optGroups = [ |
| 5 | + $('optgroup[label="Cookies"]'), |
| 6 | + $('optgroup[label="Web Storage"]') |
| 7 | + ]; |
| 8 | + |
| 9 | + optGroups.forEach(function(optGroup) { |
| 10 | + var hasJWTs = |
| 11 | + optGroup.children(':not(.load-from-no-jwts)').length > 0; |
| 12 | + if(hasJWTs) { |
| 13 | + optGroup.children('.load-from-no-jwts').remove(); |
| 14 | + } else { |
| 15 | + optGroup.empty(); |
| 16 | + optGroup.append($('<option/>', { |
| 17 | + 'class': 'load-from-no-jwts', |
| 18 | + 'text': 'No JWTs found', |
| 19 | + 'disabled': true |
| 20 | + })); |
| 21 | + } |
| 22 | + }); |
| 23 | + } |
| 24 | + |
| 25 | + function jwtMessage(message) { |
| 26 | + if(message.type !== 'cookies' && message.type !== 'storage') { |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + var elements = []; |
| 31 | + |
| 32 | + message.tokens.forEach(function(token) { |
| 33 | + if(!isToken(token.value)) { |
| 34 | + if(message.type === 'storage') { |
| 35 | + try { |
| 36 | + // Try again after parsing it first, some people do |
| 37 | + //localStorage.setItem('jwt', JSON.stringify(token)) |
| 38 | + token.value = JSON.parse(token.value); |
| 39 | + if(!isToken(token.value)) { |
| 40 | + return; |
| 41 | + } |
| 42 | + } catch(e) { |
| 43 | + return; |
| 44 | + } |
| 45 | + } else { |
| 46 | + return; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + var e = $('<option/>').text(token.name) |
| 51 | + .val(token.value) |
| 52 | + .data('type', token.type) |
| 53 | + if(token.cookie) { |
| 54 | + e.data('cookie', token.cookie); |
| 55 | + } |
| 56 | + elements.push(e); |
| 57 | + }); |
| 58 | + |
| 59 | + if(message.type === 'cookies') { |
| 60 | + $('optgroup[label="Cookies"]').append(elements); |
| 61 | + } else { |
| 62 | + $('optgroup[label="Web Storage"]').append(elements); |
| 63 | + } |
| 64 | + |
| 65 | + checkLoadJwtFromLength(); |
| 66 | + } |
| 67 | + |
| 68 | + chrome.runtime.onMessage.addListener(jwtMessage); |
| 69 | + |
| 70 | + chrome.tabs.executeScript({ |
| 71 | + file: 'js/webstorage.js', |
| 72 | + runAt: "document_idle" |
| 73 | + }); |
| 74 | + |
| 75 | + chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) { |
| 76 | + chrome.cookies.getAll({ |
| 77 | + url: tabs[0].url, |
| 78 | + }, function(cookies) { |
| 79 | + var result = cookies.map(function(cookie) { |
| 80 | + return { |
| 81 | + name: cookie.name, |
| 82 | + value: cookie.value, |
| 83 | + type: 'cookie', |
| 84 | + cookie: cookie |
| 85 | + } |
| 86 | + }); |
| 87 | + |
| 88 | + jwtMessage({ |
| 89 | + type: 'cookies', |
| 90 | + tokens: result |
| 91 | + }); |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + checkLoadJwtFromLength(); |
| 96 | +} |
| 97 | + |
| 98 | +export function setupTokenPageInspector() { |
| 99 | + |
| 100 | +} |
0 commit comments