Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 32343f3

Browse files
authored
Merge pull request #5698 from SimonBrandner/public-e2ee-warn
Add a warning on E2EE rooms if you try to make them public
2 parents 15c731d + 1b8aae9 commit 32343f3

File tree

4 files changed

+98
-2
lines changed

4 files changed

+98
-2
lines changed

res/css/_common.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ input[type=text]:focus, input[type=password]:focus, textarea:focus {
381381
font-size: $font-14px;
382382
color: $primary-fg-color;
383383
word-wrap: break-word;
384+
385+
a {
386+
color: $accent-color;
387+
cursor: pointer;
388+
}
384389
}
385390

386391
.mx_Dialog_buttons {

src/components/views/dialogs/CreateRoomDialog.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ interface IProps {
3939
defaultPublic?: boolean;
4040
defaultName?: string;
4141
parentSpace?: Room;
42+
defaultEncrypted?: boolean;
4243
onFinished(proceed: boolean, opts?: IOpts): void;
4344
}
4445

4546
interface IState {
4647
joinRule: JoinRule;
48+
isPublic: boolean;
4749
isEncrypted: boolean;
4850
name: string;
4951
topic: string;
@@ -74,8 +76,9 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
7476

7577
const config = SdkConfig.get();
7678
this.state = {
79+
isPublic: this.props.defaultPublic || false,
80+
isEncrypted: this.props.defaultEncrypted ?? privateShouldBeEncrypted(),
7781
joinRule,
78-
isEncrypted: privateShouldBeEncrypted(),
7982
name: this.props.defaultName || "",
8083
topic: "",
8184
alias: "",

src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import RoomUpgradeWarningDialog from '../../../dialogs/RoomUpgradeWarningDialog'
3737
import { upgradeRoom } from "../../../../../utils/RoomUpgrade";
3838
import { arrayHasDiff } from "../../../../../utils/arrays";
3939
import SettingsFlag from '../../../elements/SettingsFlag';
40+
import createRoom, { IOpts } from '../../../../../createRoom';
41+
import CreateRoomDialog from '../../../dialogs/CreateRoomDialog';
4042

4143
interface IProps {
4244
roomId: string;
@@ -129,7 +131,38 @@ export default class SecurityRoomSettingsTab extends React.Component<IProps, ISt
129131
if (refreshWhenTypes.includes(e.getType() as EventType)) this.forceUpdate();
130132
};
131133

132-
private onEncryptionChange = () => {
134+
private onEncryptionChange = async () => {
135+
if (this.state.joinRule == "public") {
136+
const dialog = Modal.createTrackedDialog('Confirm Public Encrypted Room', '', QuestionDialog, {
137+
title: _t('Are you sure you want to add encryption to this public room?'),
138+
description: <div>
139+
<p> { _t(
140+
"<b>It's not recommended to add encryption to public rooms.</b>" +
141+
"Anyone can find and join public rooms, so anyone can read messages in them. " +
142+
"You'll get none of the benefits of encryption, and you won't be able to turn it " +
143+
"off later. Encrypting messages in a public room will make receiving and sending " +
144+
"messages slower.",
145+
null,
146+
{ "b": (sub) => <b>{ sub }</b> },
147+
) } </p>
148+
<p> { _t(
149+
"To avoid these issues, create a <a>new encrypted room</a> for " +
150+
"the conversation you plan to have.",
151+
null,
152+
{ "a": (sub) => <a onClick={() => {
153+
dialog.close();
154+
this.createNewRoom(false, true);
155+
}}> { sub } </a> },
156+
) } </p>
157+
</div>,
158+
159+
});
160+
161+
const { finished } = dialog;
162+
const [confirm] = await finished;
163+
if (!confirm) return;
164+
}
165+
133166
Modal.createTrackedDialog('Enable encryption', '', QuestionDialog, {
134167
title: _t('Enable encryption?'),
135168
description: _t(
@@ -194,6 +227,41 @@ export default class SecurityRoomSettingsTab extends React.Component<IProps, ISt
194227
}
195228
}
196229

230+
if (
231+
this.state.encrypted &&
232+
this.state.joinRule !== JoinRule.Public &&
233+
joinRule === JoinRule.Public
234+
) {
235+
const dialog = Modal.createTrackedDialog('Confirm Public Encrypted Room', '', QuestionDialog, {
236+
title: _t("Are you sure you want to make this encrypted room public?"),
237+
description: <div>
238+
<p> { _t(
239+
"<b>It's not recommended to make encrypted rooms public.</b> " +
240+
"It will mean anyone can find and join the room, so anyone can read messages. " +
241+
"You'll get none of the benefits of encryption. Encrypting messages in a public " +
242+
"room will make receiving and sending messages slower.",
243+
null,
244+
{ "b": (sub) => <b>{ sub }</b> },
245+
) } </p>
246+
<p> { _t(
247+
"To avoid these issues, create a <a>new public room</a> for the conversation " +
248+
"you plan to have.",
249+
null,
250+
{
251+
"a": (sub) => <a onClick={() => {
252+
dialog.close();
253+
this.createNewRoom(true, false);
254+
}}> { sub } </a>,
255+
},
256+
) } </p>
257+
</div>,
258+
});
259+
260+
const { finished } = dialog;
261+
const [confirm] = await finished;
262+
if (!confirm) return;
263+
}
264+
197265
if (beforeJoinRule === joinRule && !restrictedAllowRoomIds) return;
198266

199267
const content: IContent = {
@@ -254,6 +322,20 @@ export default class SecurityRoomSettingsTab extends React.Component<IProps, ISt
254322
});
255323
};
256324

325+
private createNewRoom = async (defaultPublic: boolean, defaultEncrypted: boolean) => {
326+
const modal = Modal.createTrackedDialog<[boolean, IOpts]>(
327+
"Create Room",
328+
"Create room after trying to make an E2EE room public",
329+
CreateRoomDialog,
330+
{ defaultPublic, defaultEncrypted },
331+
);
332+
const [shouldCreate, opts] = await modal.finished;
333+
if (shouldCreate) {
334+
await createRoom(opts);
335+
}
336+
return shouldCreate;
337+
};
338+
257339
private onHistoryRadioToggle = (history: HistoryVisibility) => {
258340
const beforeHistory = this.state.history;
259341
if (beforeHistory === history) return;

src/i18n/strings/en_EN.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,9 +1450,15 @@
14501450
"Send %(eventType)s events": "Send %(eventType)s events",
14511451
"Permissions": "Permissions",
14521452
"Select the roles required to change various parts of the room": "Select the roles required to change various parts of the room",
1453+
"Are you sure you want to add encryption to this public room?": "Are you sure you want to add encryption to this public room?",
1454+
"<b>It's not recommended to add encryption to public rooms.</b>Anyone can find and join public rooms, so anyone can read messages in them. You'll get none of the benefits of encryption, and you won't be able to turn it off later. Encrypting messages in a public room will make receiving and sending messages slower.": "<b>It's not recommended to add encryption to public rooms.</b>Anyone can find and join public rooms, so anyone can read messages in them. You'll get none of the benefits of encryption, and you won't be able to turn it off later. Encrypting messages in a public room will make receiving and sending messages slower.",
1455+
"To avoid these issues, create a <a>new encrypted room</a> for the conversation you plan to have.": "To avoid these issues, create a <a>new encrypted room</a> for the conversation you plan to have.",
14531456
"Enable encryption?": "Enable encryption?",
14541457
"Once enabled, encryption for a room cannot be disabled. Messages sent in an encrypted room cannot be seen by the server, only by the participants of the room. Enabling encryption may prevent many bots and bridges from working correctly. <a>Learn more about encryption.</a>": "Once enabled, encryption for a room cannot be disabled. Messages sent in an encrypted room cannot be seen by the server, only by the participants of the room. Enabling encryption may prevent many bots and bridges from working correctly. <a>Learn more about encryption.</a>",
14551458
"This upgrade will allow members of selected spaces access to this room without an invite.": "This upgrade will allow members of selected spaces access to this room without an invite.",
1459+
"Are you sure you want to make this encrypted room public?": "Are you sure you want to make this encrypted room public?",
1460+
"<b>It's not recommended to make encrypted rooms public.</b> It will mean anyone can find and join the room, so anyone can read messages. You'll get none of the benefits of encryption. Encrypting messages in a public room will make receiving and sending messages slower.": "<b>It's not recommended to make encrypted rooms public.</b> It will mean anyone can find and join the room, so anyone can read messages. You'll get none of the benefits of encryption. Encrypting messages in a public room will make receiving and sending messages slower.",
1461+
"To avoid these issues, create a <a>new public room</a> for the conversation you plan to have.": "To avoid these issues, create a <a>new public room</a> for the conversation you plan to have.",
14561462
"To link to this room, please add an address.": "To link to this room, please add an address.",
14571463
"Private (invite only)": "Private (invite only)",
14581464
"Only invited people can join.": "Only invited people can join.",

0 commit comments

Comments
 (0)