Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add protection against insecure passwords #2088

Merged
merged 5 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { viewExternalUrl } from '../utils/url-utils';

type OwnProps = {
authPending: boolean;
hasInsecurePassword: boolean;
hasInvalidCredentials: boolean;
hasLoginError: boolean;
login: (username: string, password: string) => any;
Expand Down Expand Up @@ -76,6 +77,28 @@ export class Auth extends Component<Props> {
{!this.state.onLine && (
<p className="login__auth-message is-error">Offline</p>
)}
{this.props.hasInsecurePassword && (
<p
className="login__auth-message is-error"
data-error-name="invalid-login"
>
Your password is insecure and must be{' '}
<a
className="login__reset"
href={
'https://app.simplenote.com/reset/?email=' +
encodeURIComponent(get(this.usernameInput, 'value'))
}
target="_blank"
rel="noopener noreferrer"
onClick={this.onForgot}
>
reset
</a>
. Passwords must be between 8 and 64 characters long and may not
include your email address, new lines, or tabs.
</p>
)}
{this.props.hasInvalidCredentials && (
<p
className="login__auth-message is-error"
Expand Down
7 changes: 7 additions & 0 deletions lib/boot-without-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render } from 'react-dom';
import { Auth as AuthApp } from './auth';
import { Auth as SimperiumAuth } from 'simperium';
import analytics from './analytics';
import { validatePassword } from './utils/validate-password';

import getConfig from '../get-config';

Expand All @@ -16,6 +17,7 @@ type State = {
authStatus:
| 'unsubmitted'
| 'submitting'
| 'insecure-password'
| 'invalid-credentials'
| 'unknown-error';
};
Expand All @@ -42,6 +44,10 @@ class AppWithoutAuth extends Component<Props, State> {
auth
.authorize(username, password)
.then((user: User) => {
if (!validatePassword(password, username)) {
this.setState({ authStatus: 'insecure-password' });
return;
}
if (!user.access_token) {
throw new Error('missing access token');
}
Expand Down Expand Up @@ -96,6 +102,7 @@ class AppWithoutAuth extends Component<Props, State> {
<div className={`app theme-${systemTheme}`}>
<AuthApp
authPending={this.state.authStatus === 'submitting'}
hasInsecurePassword={this.state.authStatus === 'insecure-password'}
hasInvalidCredentials={
this.state.authStatus === 'invalid-credentials'
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.