Lurker News
Back to discussion

Comment by enobrev

enobrev3 replies#
This is speculative as I haven't tested out this vulnerability or attempted to avoid it (yet), but I imagine this means it would be a good idea to make password fields "uncontrolled"[1] if you're using react.

1: https://reactjs.org/docs/uncontrolled-components.html

Semiapies#
That seems reasonable.

The apps I've worked on weren't full SPAs, so I just used plain HTML for the login form.

oblosys#
One option is to make the input component uncontrolled by removing the value={this.state.password} prop, but keeping the onChange handler to maintain the password in the state for validation & strength checking. Typically, the only time you need to programmatically change a password field is when clearing it, which can be done by setting the DOM attribute directly.
yuchi1 reply#
Or just use correctly defined CSP
enobrev#
I hadn't realized a CSP could protect against this sort of thing. Thanks for the tip!