From bb03298e6dad3339d5cb3d691e8812cc85fc1400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 1 Feb 2022 18:24:17 +0100 Subject: [PATCH] Add a warning to the console to discourage attacks and encourage contributing (#7673) --- src/components/structures/MatrixChat.tsx | 34 ++++++++++++++++++++++++ src/i18n/strings/en_EN.json | 3 +++ 2 files changed, 37 insertions(+) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index aff854b149..19fd89326d 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -23,6 +23,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { Screen as ScreenEvent } from "matrix-analytics-events/types/typescript/Screen"; import { defer, IDeferred, QueryDict } from "matrix-js-sdk/src/utils"; import { logger } from "matrix-js-sdk/src/logger"; +import { throttle } from "lodash"; // focus-visible is a Polyfill for the :focus-visible CSS pseudo-attribute used by _AccessibleButton.scss import 'focus-visible'; @@ -447,6 +448,10 @@ export default class MatrixChat extends React.PureComponent { } } + public componentDidMount(): void { + window.addEventListener("resize", this.onWindowResized); + } + componentDidUpdate(prevProps, prevState) { if (this.shouldTrackPageChange(prevState, this.state)) { const durationMs = this.stopPageChangeTimer(); @@ -467,6 +472,7 @@ export default class MatrixChat extends React.PureComponent { this.fontWatcher.stop(); UIStore.destroy(); this.state.resizeNotifier.removeListener("middlePanelResized", this.dispatchTimelineResize); + window.removeEventListener("resize", this.onWindowResized); if (this.accountPasswordTimer !== null) clearTimeout(this.accountPasswordTimer); } @@ -501,6 +507,34 @@ export default class MatrixChat extends React.PureComponent { }); } + private onWindowResized = (): void => { + // XXX: This is a very unreliable way to detect whether or not the the devtools are open + this.warnInConsole(); + }; + + private warnInConsole = throttle((): void => { + const largeFontSize = "50px"; + const normalFontSize = "15px"; + + const waitText = _t("Wait!"); + const scamText = _t( + "If someone told you to copy/paste something here, " + + "there is a high likelihood you're being scammed!", + ); + const devText = _t( + "If you know what you're doing, Element is open-source, " + + "be sure to check out our GitHub (https://github.com/vector-im/element-web/) " + + "and contribute!", + ); + + console.log( + `%c${waitText}\n%c${scamText}\n%c${devText}`, + `font-size:${largeFontSize}; color:blue;`, + `font-size:${normalFontSize}; color:red;`, + `font-size:${normalFontSize};`, + ); + }, 1000); + private getFallbackHsUrl(): string { if (this.props.serverConfig?.isDefault) { return this.props.config.fallback_hs_url; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 1de12aa124..a4bc83206a 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -3024,6 +3024,9 @@ "Private community": "Private community", "To view %(communityName)s, swap to communities in your preferences": "To view %(communityName)s, swap to communities in your preferences", "To join %(communityName)s, swap to communities in your preferences": "To join %(communityName)s, swap to communities in your preferences", + "Wait!": "Wait!", + "If someone told you to copy/paste something here, there is a high likelihood you're being scammed!": "If someone told you to copy/paste something here, there is a high likelihood you're being scammed!", + "If you know what you're doing, Element is open-source, be sure to check out our GitHub (https://github.com/vector-im/element-web/) and contribute!": "If you know what you're doing, Element is open-source, be sure to check out our GitHub (https://github.com/vector-im/element-web/) and contribute!", "Failed to reject invitation": "Failed to reject invitation", "Cannot create rooms in this community": "Cannot create rooms in this community", "You do not have permission to create rooms in this community.": "You do not have permission to create rooms in this community.",