For example if I write a function in react which updates the password state to the password input value when the input field is on change, is it dangerous to do so ?
-
what would be the need for that? could you explain it? – WilsonPena Oct 19 '20 at 17:41
-
What makes you think this is dangerous? – ggorlen Oct 19 '20 at 17:41
-
@ggorlen, Because it is not hashed ? Idk, I'm new to web development and I want to make sure I am doing this things right – Noiseymur Oct 19 '20 at 17:44
-
@WilsonPena, Um, I don't know, is there another way around ? I don't know much about this – Noiseymur Oct 19 '20 at 17:46
-
@ggorlen, Yes, thank you vey much ! – Noiseymur Oct 19 '20 at 17:55
2 Answers
Not an issue is it doesn't persist.
Storing in state is a common practice,
I have seen amplify-js sign in code where they use a state for storing password. Which is a library used for Amazon Cognito.
It's really dangerous to store in local storage.
The use of the local storage to store session identifiers is never recommended as the data is always accessible by JavaScript.
Please use Cookies to mitigate this risk using the httpOnly flag or store the token for fetch calls if you are using Mobile or Vue/React.js
A single XSS (Cross Site Scripting) attack will be able to steal all the data in these objects and/or load malicious information, so don't consider the "local storage" to be trusted and less for a session identifier/hashed password.
https://cheatsheetseries.owasp.org/cheatsheets/HTML5_Security_Cheat_Sheet.html#Local_Storage
Also go through the remaining, so you Cheatsheet.
It's will answer most of the common queries.

- 892
- 1
- 8
- 23
-
1OP isn't asking about local storage, they're asking about React state. I assume it's going to be something like `const [password, setPassword] = useState("");` and some ` setPassword(e.target.value)} type="password">` sort of pattern. – ggorlen Oct 19 '20 at 18:16
-
1
There Is no problem, but the state must don't have public access.

- 7
- 1
-
Thanks, and what determines if a state is publicly accessible or not ? How can I make it unaccessible ? – Noiseymur Oct 19 '20 at 17:48
-
Anything running on the client is "public", although I'm not sure how you define that term. – ggorlen Oct 19 '20 at 17:51