From 0a525629ee8ac2f6bb92d713df17b7a066367da6 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 24 Jan 2020 17:10:42 +1100 Subject: [PATCH] Prevent illegal username and passwords --- js/views/scroll_down_button_view.js | 3 +- preload.js | 5 ++++ stylesheets/_session.scss | 12 +++++--- ts/components/EditProfileDialog.tsx | 9 +++--- .../session/LeftPaneSettingSection.tsx | 29 ------------------- ts/components/session/RegistrationTabs.tsx | 3 ++ ts/components/session/SessionInput.tsx | 4 ++- .../session/SessionPasswordModal.tsx | 6 ++++ ts/components/session/SessionScrollButton.tsx | 14 ++++----- .../session/settings/SessionSettings.tsx | 3 +- ts/global.d.ts | 1 + 11 files changed, 40 insertions(+), 49 deletions(-) diff --git a/js/views/scroll_down_button_view.js b/js/views/scroll_down_button_view.js index 9c7ab215c..941ad814a 100644 --- a/js/views/scroll_down_button_view.js +++ b/js/views/scroll_down_button_view.js @@ -15,7 +15,7 @@ this.count += count; this.render(); }, - + render() { this.scrollButtonView = new Whisper.ReactWrapperView({ className: 'module-scroll-down', @@ -29,5 +29,4 @@ return this; }, }); - })(); diff --git a/preload.js b/preload.js index 341d08f3c..338143a47 100644 --- a/preload.js +++ b/preload.js @@ -59,6 +59,11 @@ window.isBeforeVersion = (toCheck, baseVersion) => { } }; +window.CONSTANTS = { + maxPasswordLength: 32, + maxUsernameLength: 20, +}; + window.versionInfo = { environment: window.getEnvironment(), version: window.getVersion(), diff --git a/stylesheets/_session.scss b/stylesheets/_session.scss index 96861e548..9bf8a4372 100644 --- a/stylesheets/_session.scss +++ b/stylesheets/_session.scss @@ -32,8 +32,12 @@ } @keyframes fadein { - from {opacity: 0;} - to {opacity: 1;} + from { + opacity: 0; + } + to { + opacity: 1; + } } // Session Colors @@ -154,7 +158,7 @@ div.spacer-lg { } $session-transition-duration: 0.25s; -$session-fadein-duration: 0.10s; +$session-fadein-duration: 0.1s; $session-icon-size-sm: 15px; $session-icon-size-md: 20px; @@ -1375,7 +1379,7 @@ input { animation: fadein $session-fadein-duration; bottom: 15px; - .session-icon-button{ + .session-icon-button { display: flex; justify-content: center; align-items: center; diff --git a/ts/components/EditProfileDialog.tsx b/ts/components/EditProfileDialog.tsx index e9c683075..959601298 100644 --- a/ts/components/EditProfileDialog.tsx +++ b/ts/components/EditProfileDialog.tsx @@ -208,6 +208,7 @@ export class EditProfileDialog extends React.Component { value={this.state.profileName} placeholder={placeholderText} onChange={this.onNameEdited} + maxLength={window.CONSTANTS.maxUsernameLength} tabIndex={0} required={true} aria-required={true} @@ -260,10 +261,10 @@ export class EditProfileDialog extends React.Component { ); } - private onNameEdited(e: any) { - e.persist(); + private onNameEdited(event: any) { + event.persist(); - const newName = e.target.value.replace(window.displayNameRegex, ''); + const newName = event.target.value.replace(window.displayNameRegex, ''); this.setState(state => { return { @@ -301,7 +302,7 @@ export class EditProfileDialog extends React.Component { private onClickOK() { const newName = this.state.profileName.trim(); - if (newName === '') { + if (newName.length === 0 || newName.length > window.CONSTANTS.maxUsernameLength) { return; } diff --git a/ts/components/session/LeftPaneSettingSection.tsx b/ts/components/session/LeftPaneSettingSection.tsx index 0e07c9285..d97a67537 100644 --- a/ts/components/session/LeftPaneSettingSection.tsx +++ b/ts/components/session/LeftPaneSettingSection.tsx @@ -218,33 +218,4 @@ export class LeftPaneSettingSection extends React.Component { settingCategory: category, }); } - - // public updateSearch(searchTerm: string) { - // const { updateSearchTerm, clearSearch } = this.props; - - // if (!searchTerm) { - // clearSearch(); - - // return; - // } - // // reset our pubKeyPasted, we can either have a pasted sessionID or a sessionID got from a search - // this.setState({ pubKeyPasted: '' }, () => { - // window.Session.emptyContentEditableDivs(); - // }); - - // if (updateSearchTerm) { - // updateSearchTerm(searchTerm); - // } - - // if (searchTerm.length < 2) { - // return; - // } - - // const cleanedTerm = cleanSearchTerm(searchTerm); - // if (!cleanedTerm) { - // return; - // } - - // this.debouncedSearch(cleanedTerm); - // } } diff --git a/ts/components/session/RegistrationTabs.tsx b/ts/components/session/RegistrationTabs.tsx index 4824de3b5..cd1adc7e7 100644 --- a/ts/components/session/RegistrationTabs.tsx +++ b/ts/components/session/RegistrationTabs.tsx @@ -449,6 +449,7 @@ export class RegistrationTabs extends React.Component<{}, State> { type="text" placeholder={window.i18n('enterDisplayName')} value={this.state.displayName} + maxLength={window.CONSTANTS.maxUsernameLength} onValueChanged={(val: string) => { this.onDisplayNameChanged(val); }} @@ -462,6 +463,7 @@ export class RegistrationTabs extends React.Component<{}, State> { error={this.state.passwordErrorString} type="password" placeholder={window.i18n('enterOptionalPassword')} + maxLength={window.CONSTANTS.maxPasswordLength} onValueChanged={(val: string) => { this.onPasswordChanged(val); }} @@ -475,6 +477,7 @@ export class RegistrationTabs extends React.Component<{}, State> { error={passwordsDoNotMatch} type="password" placeholder={window.i18n('optionalPassword')} + maxLength={window.CONSTANTS.maxPasswordLength} onValueChanged={(val: string) => { this.onPasswordVerifyChanged(val); }} diff --git a/ts/components/session/SessionInput.tsx b/ts/components/session/SessionInput.tsx index 5c74762c5..ab892a5d0 100644 --- a/ts/components/session/SessionInput.tsx +++ b/ts/components/session/SessionInput.tsx @@ -9,6 +9,7 @@ interface Props { type: string; value?: string; placeholder: string; + maxLength?: number; enableShowHide?: boolean; onValueChanged?: any; onEnterPressed?: any; @@ -33,7 +34,7 @@ export class SessionInput extends React.PureComponent { } public render() { - const { placeholder, type, value, enableShowHide, error } = this.props; + const { placeholder, type, value, maxLength, enableShowHide, error } = this.props; const { forceShow } = this.state; const correctType = forceShow ? 'text' : type; @@ -46,6 +47,7 @@ export class SessionInput extends React.PureComponent { type={correctType} placeholder={placeholder} value={value} + maxLength={maxLength} onChange={e => { this.updateInputValue(e); }} diff --git a/ts/components/session/SessionPasswordModal.tsx b/ts/components/session/SessionPasswordModal.tsx index 637276226..c939cbfcb 100644 --- a/ts/components/session/SessionPasswordModal.tsx +++ b/ts/components/session/SessionPasswordModal.tsx @@ -58,12 +58,14 @@ export class SessionPasswordModal extends React.Component { type="password" id="password-modal-input" placeholder={placeholders[0]} + maxLength={window.CONSTANTS.maxPasswordLength} /> {action !== PasswordAction.Remove && ( )} @@ -118,6 +120,10 @@ export class SessionPasswordModal extends React.Component { $('#password-modal-input-confirm').val() ); + if (enteredPassword.length === 0 || enteredPasswordConfirm.length === 0){ + return; + } + // Check passwords enntered if ( enteredPassword.length === 0 || diff --git a/ts/components/session/SessionScrollButton.tsx b/ts/components/session/SessionScrollButton.tsx index 05292bee0..39644e0d6 100644 --- a/ts/components/session/SessionScrollButton.tsx +++ b/ts/components/session/SessionScrollButton.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { SessionIconButton, SessionIconType, SessionIconSize } from './icon'; interface Props { - count: number, + count: number; } export class SessionScrollButton extends React.PureComponent { @@ -12,14 +12,12 @@ export class SessionScrollButton extends React.PureComponent { } public render() { - console.log(`My count is: ${this.props.count}`); - return ( - + ); } } diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index f7ca1d6d6..9b3168911 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -15,6 +15,7 @@ export enum SessionSettingCategory { Permissions = 'permissions', Notifications = 'notifications', Devices = 'devices', + Blocked = 'blocked', } export enum SessionSettingType { @@ -396,7 +397,7 @@ export class SettingsView extends React.Component { id: 'media-permissions', title: window.i18n('mediaPermissionsTitle'), description: window.i18n('mediaPermissionsDescription'), - hidden: false, + hidden: true, // Hidden until feature works type: SessionSettingType.Toggle, category: SessionSettingCategory.Permissions, setFn: window.toggleMediaPermissions, diff --git a/ts/global.d.ts b/ts/global.d.ts index 246bfcb39..0a426177f 100644 --- a/ts/global.d.ts +++ b/ts/global.d.ts @@ -1,4 +1,5 @@ interface Window { + CONSTANTS: any; versionInfo: any; Events: any;