Skip to content
Info disclosure Write-up Beginner

Cleartext password in LocalStorage (Writeup)

The application stored the user's cleartext password in browser LocalStorage as part of a marketing log history. An attacker who achieves XSS on the site could read the password and take over the account.

ruvlol Follow

Published on medium.com

Bounty$1,500 View original

{{media:0}}

ruvlol, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

The target was an application in one of the bug bounty programs the author was testing. The report does not name the program or the application. The feature at the centre of the finding is the site's use of browser LocalStorage: a key-value store that pages can read and write from JavaScript. The author describes the stored entry as log history kept for marketing purposes, a large JSON that recorded every action taken on the website.

Setup

The only precondition described is a normal login to the application. The author confirmed the behaviour by logging in through a blank browser and then inspecting storage. The tools were the browser's own developer tools, reached with F12, then Storage, then LocalStorage or SessionStorage. No special account, role or version is mentioned.

Finding it

The author decided to look inside LocalStorage on the off chance that API keys or tokens were being kept there. The reasoning is that LocalStorage is not a safe place for sensitive information because it is always reachable from JavaScript. Cookies can be given the HttpOnly flag so that scripts cannot read them, which protects them against XSS unless the value is reflected somewhere else. LocalStorage has no equivalent: access from JavaScript cannot be restricted, so any XSS on the target origin compromises its LocalStorage completely. SessionStorage is worth checking alongside it; the difference is that LocalStorage keys do not expire, while SessionStorage keys expire when the tab is closed, and stored XSS can read SessionStorage too.

Opening the storage panel showed a single row, the marketing log history.

Inside that large JSON, among the recorded actions, was an object with two fields:

Text
[{

“account.username” : “ruvlol”,

“account.password” : “redacted”

}]

The account password was sitting in cleartext in a store that any script on the origin can read. The author did not believe it at first. The behaviour was constant: logging in through a blank browser and looking at LocalStorage again gave exactly the same result.

Exploitation

Step 1: Read the stored JSON

The proof of concept reads the entry through localStorage.edited. The author's proof of concept parses it and prints the credentials:

JavaScript
var test = JSON.parse(localStorage.edited);

console.log(‘your username is: ‘ + test.edited.account.username + ‘ and your password is: ‘ + test.edited.account.password);

JSON.parse turns the stored string back into an object, and the two property reads pull the username and password out of the account object nested under edited. The output is the victim's username and cleartext password. The author notes that this much JavaScript is all that is required to obtain someone else's password.

Step 2: Deliver it through XSS

The snippet reads the credentials from LocalStorage in the browser console. The report does not describe how an attacker would get script into a victim's browser.

Root cause

The application wrote the user's account password, in cleartext, into a marketing log object that it persisted in LocalStorage. The design mistake is treating LocalStorage as a private store. It is readable by any JavaScript running on the origin, and there is no flag comparable to HttpOnly that can hide it from scripts. The existing defence against script access to credentials, marking cookies HttpOnly, does not apply here because the data never lived in a cookie.

Impact

Anyone who can run JavaScript on the target origin, for instance through an XSS vulnerability, can read the stored password of the logged-in user. The author's proof of concept shows the read working for the account that was logged in. The program rated the issue High severity under its policy and paid a $1500 bounty.

Fix

The clear fix is to stop writing the password into the marketing log at all, and to keep credentials out of LocalStorage and SessionStorage entirely, since neither can be protected from JavaScript the way an HttpOnly cookie can.

Variants to test

  1. Open LocalStorage and SessionStorage after logging in and search the values for password, passwd, token, secret and api. A positive result is a cleartext credential or token in a value that any script on the origin can read.
  2. Inspect marketing, analytics and logging objects specifically, since these often serialise whole application state. A positive result is a nested object containing account fields such as a username paired with a password.
  3. Repeat the login from a blank browser profile and check whether the same sensitive value reappears. A positive result is the same credential stored again, showing the behaviour is constant rather than a leftover from an earlier session.
  4. Look for XSS on the same origin and chain it with a read of the stored value, as in the proof of concept above. A positive result is script execution that returns the victim's credentials.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

What happened, in plain words

A security researcher was testing a website that was part of a bug bounty program. A bug bounty program is an arrangement where a company invites people to look for security problems in its systems and pays them for reporting what they find. The report does not name the program or the website.

The researcher opened a part of the browser that most people never look at, called LocalStorage, and found the user's password sitting there in plain, unencrypted text. LocalStorage is a small storage area that every website can use inside your browser to keep information between visits. Because any script running on that website can read it, it is a bad place for secrets. The researcher reported the problem and was paid $1500; the program rated it High severity under its policy.

This article walks through the same story from the beginning, explaining each idea as it comes up.

The pieces you need to know

Before the steps make sense, here are the few browser concepts the whole finding rests on.

  • JavaScript: the programming language that web pages run inside your browser. It is what makes pages interactive, and it is also what an attacker abuses when a site has a scripting flaw.
  • LocalStorage: a key-value store built into browsers. Think of it as a small notebook that a website keeps for you inside your browser. The site writes entries as name and value pairs, and it can read them back later. The entries stay there until something deletes them, even after you close the browser.
  • SessionStorage: the same kind of notebook, but the pages are torn out when you close the tab. The report explains the difference directly: LocalStorage keys do not expire, while SessionStorage keys expire after the tab is closed.
  • Cookie: a small piece of data a website asks your browser to keep and send back with later requests. Cookies can be marked with a flag called HttpOnly, which tells the browser that scripts are not allowed to read them. That protects a cookie against XSS unless the value is reflected somewhere else.
  • XSS (cross-site scripting): a flaw where an attacker manages to get their own JavaScript to run inside someone else's browser on the target website. Once that happens, the attacker's script runs with the same access as the site's own code.
  • API key / token: a secret string that identifies a program or a user to a service, roughly like a password for software rather than for a person. Finding one in a readable place is a common bug bounty goal.
  • JSON: a text format for structured data, made of names and values in curly braces. It is how many websites store and exchange information. A large JSON is simply a big block of this text.

Why LocalStorage is the wrong place for secrets

The researcher's reasoning, in plain terms: it is not safe to use LocalStorage for sensitive information, because it is always accessible from JavaScript. There is no switch that hides it from scripts.

Compare that with cookies. When a site sets a cookie, it can add the HttpOnly flag, and the browser then refuses to let JavaScript read that cookie. That is a real barrier against XSS, unless the value is reflected somewhere else. LocalStorage has no equivalent flag: access from JavaScript cannot be restricted, so any XSS on the target origin compromises its LocalStorage completely.

SessionStorage deserves a look at the same time. Its keys expire when the tab closes, but if an XSS is stored (meaning the malicious script is saved on the server and served to later visitors), it can read SessionStorage keys too.

Setup

The only precondition described is a normal login to the application. No special account, role or version is mentioned. The tools were the browser's own developer tools, opened with F12, then Storage, then LocalStorage or SessionStorage. The researcher confirmed the behaviour by logging in through a blank browser and then inspecting storage, so the result was not a leftover from an earlier session.

Finding it

The researcher decided to look inside LocalStorage on the off chance that API keys or tokens were being kept there. That is a reasonable habit: if a site stores secrets in a place any script can read, the secrets are effectively public to anyone who can run a script on that site.

Opening the storage panel showed a single row. The report describes it as log history kept for marketing purposes: a large JSON that recorded every action taken on the website.

Inside that large JSON, among the recorded actions, was an object with two fields:

Text
[{

“account.username” : “ruvlol”,

“account.password” : “redacted”

}]

Line by line: the outer square brackets mean this is a list. The curly braces group one item in that list. Inside, account.username holds the account name and account.password holds the password. The password was sitting in cleartext, meaning not encrypted or hashed in any way, in a store that any script on the origin can read. The researcher did not believe it at first. The behaviour was constant: logging in through a blank browser and looking at LocalStorage again gave exactly the same result.

Exploitation

Step 1: Read the stored JSON

The proof of concept reads the entry through localStorage.edited. The researcher's proof of concept parses it and prints the credentials:

JavaScript
var test = JSON.parse(localStorage.edited);

console.log(‘your username is: ‘ + test.edited.account.username + ‘ and your password is: ‘ + test.edited.account.password);

Line by line:

  1. var test = JSON.parse(localStorage.edited); reads the entry named edited from LocalStorage. That entry is text, so JSON.parse turns the text back into a structured object, and the result is kept in a variable called test.
  2. console.log(...) prints a message to the browser's console, the text output panel in the developer tools.
  3. test.edited.account.username walks into the object: first to edited, then to account, then to the username field. The same pattern with .password pulls out the password.
  4. The two pieces are joined with + into one sentence, so the output is the victim's username and cleartext password.

The researcher notes that this much JavaScript is all that is required to obtain someone else's password.

Step 2: Deliver it through XSS

The snippet reads the credentials from LocalStorage in the browser console. The report does not describe how an attacker would get script into a victim's browser.

Root cause

The application wrote the user's account password, in cleartext, into a marketing log object that it persisted in LocalStorage. The design mistake is treating LocalStorage as a private store. It is readable by any JavaScript running on the origin, and there is no flag comparable to HttpOnly that can hide it from scripts. The usual defence against script access to credentials, marking cookies HttpOnly, does not apply here because the data never lived in a cookie.

Impact

Anyone who can run JavaScript on the target origin, for instance through an XSS vulnerability, can read the stored password of the logged-in user. The proof of concept shows the read working for the account that was logged in. The program rated the issue High severity under its policy and paid a $1500 bounty.

Fix

The clear fix is to stop writing the password into the marketing log at all, and to keep credentials out of LocalStorage and SessionStorage entirely, since neither can be protected from JavaScript the way an HttpOnly cookie can.

Variants to test

  1. Open LocalStorage and SessionStorage after logging in and search the values for password, passwd, token, secret and api. A positive result is a cleartext credential or token in a value that any script on the origin can read.
  2. Inspect marketing, analytics and logging objects specifically, since these often serialise whole application state. A positive result is a nested object containing account fields such as a username paired with a password.
  3. Repeat the login from a blank browser profile and check whether the same sensitive value reappears. A positive result is the same credential stored again, showing the behaviour is constant rather than a leftover from an earlier session.
  4. Look for XSS on the same origin and chain it with a read of the stored value, as in the proof of concept above. A positive result is script execution that returns the victim's credentials.

Glossary

  • Bug bounty program: an arrangement where a company invites people to find security problems and pays for valid reports.
  • LocalStorage: a key-value store in browsers that pages can read and write from JavaScript; entries do not expire.
  • SessionStorage: a similar browser store whose entries expire when the tab is closed.
  • Key-value store: a storage model where each entry has a name (the key) and a piece of data (the value).
  • JavaScript: the programming language that web pages run in the browser.
  • Cookie: a small piece of data a site asks the browser to keep and send back with later requests.
  • HttpOnly: a cookie flag that stops JavaScript from reading that cookie.
  • XSS (cross-site scripting): a flaw that lets an attacker's JavaScript run inside a victim's browser on the target site.
  • Stored XSS: an XSS where the malicious script is saved on the server and served to later visitors.
  • Origin: the combination of scheme, host and port that identifies a website; scripts from one origin cannot normally read another's data.
  • API key / token: a secret string that identifies software or a user to a service.
  • JSON: a text format for structured data made of names and values.
  • Cleartext: data stored or sent without encryption or hashing, readable as-is.
  • Developer tools: the built-in browser panel, opened with F12, for inspecting a page, including its storage.
  • Proof of concept (PoC): a small piece of code that demonstrates a vulnerability works.
  • Payload: the code an attacker runs to carry out an attack.
  • Severity: a rating of how serious a vulnerability is, often set by the program's policy.

More by ruvlol

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.