Should JWT be stored in localStorage or cookie? [duplicate]

I like the XSRF Double Submit Cookies method which mentioned in the article that @pkid169 said, but there is one thing that article doesn’t tell you. You are still not protected against XSS because what the attacker can do is inject script that reads your CSRF cookie (which is not HttpOnly) and then make a … Read more

How to find the size of localStorage

Execute this snippet in JavaScript console (one line version): var _lsTotal=0,_xLen,_x;for(_x in localStorage){ if(!localStorage.hasOwnProperty(_x)){continue;} _xLen= ((localStorage[_x].length + _x.length)* 2);_lsTotal+=_xLen; console.log(_x.substr(0,50)+” = “+ (_xLen/1024).toFixed(2)+” KB”)};console.log(“Total = ” + (_lsTotal / 1024).toFixed(2) + ” KB”); The same code in multiple lines for reading sake var _lsTotal = 0, _xLen, _x; for (_x in localStorage) { if (!localStorage.hasOwnProperty(_x)) … Read more

When is localStorage cleared?

localStorage is also known as Web Storage, HTML5 Storage, and DOM Storage (these all mean the same thing). localStorage is similar to sessionStorage, except that data stored in localStorage has no expiration time, while data stored in sessionStorage gets cleared when the browsing session ends (i.e. when the browser / browser tab is closed). Session … Read more

Chrome extension: accessing localStorage in content script

Update 2016: Google Chrome released the storage API: https://developer.chrome.com/docs/extensions/reference/storage/ It is pretty easy to use like the other Chrome APIs and you can use it from any page context within Chrome. // Save it using the Chrome extension storage API. chrome.storage.sync.set({‘foo’: ‘hello’, ‘bar’: ‘hi’}, function() { console.log(‘Settings saved’); }); // Read it using the storage … Read more

How to save an image to localStorage and display it on the next page?

To whoever also needs this problem solved: Firstly, I grab my image with getElementByID, and save the image as a Base64. Then I save the Base64 string as my localStorage value. bannerImage = document.getElementById(‘bannerImg’); imgData = getBase64Image(bannerImage); localStorage.setItem(“imgData”, imgData); Here is the function that converts the image to a Base64 string: function getBase64Image(img) { var … Read more

Can local storage ever be considered secure? [closed]

WebCrypto The concerns with cryptography in client-side (browser) javascript are detailed below. All but one of these concerns does not apply to the WebCrypto API, which is now reasonably well supported. For an offline app, you must still design and implement a secure keystore. Aside: If you are using Node.js, use the builtin crypto API. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)