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

Commit bb03298

Browse files
Add a warning to the console to discourage attacks and encourage contributing (#7673)
1 parent 9b0da55 commit bb03298

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/components/structures/MatrixChat.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
2323
import { Screen as ScreenEvent } from "matrix-analytics-events/types/typescript/Screen";
2424
import { defer, IDeferred, QueryDict } from "matrix-js-sdk/src/utils";
2525
import { logger } from "matrix-js-sdk/src/logger";
26+
import { throttle } from "lodash";
2627

2728
// focus-visible is a Polyfill for the :focus-visible CSS pseudo-attribute used by _AccessibleButton.scss
2829
import 'focus-visible';
@@ -447,6 +448,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
447448
}
448449
}
449450

451+
public componentDidMount(): void {
452+
window.addEventListener("resize", this.onWindowResized);
453+
}
454+
450455
componentDidUpdate(prevProps, prevState) {
451456
if (this.shouldTrackPageChange(prevState, this.state)) {
452457
const durationMs = this.stopPageChangeTimer();
@@ -467,6 +472,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
467472
this.fontWatcher.stop();
468473
UIStore.destroy();
469474
this.state.resizeNotifier.removeListener("middlePanelResized", this.dispatchTimelineResize);
475+
window.removeEventListener("resize", this.onWindowResized);
470476

471477
if (this.accountPasswordTimer !== null) clearTimeout(this.accountPasswordTimer);
472478
}
@@ -501,6 +507,34 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
501507
});
502508
}
503509

510+
private onWindowResized = (): void => {
511+
// XXX: This is a very unreliable way to detect whether or not the the devtools are open
512+
this.warnInConsole();
513+
};
514+
515+
private warnInConsole = throttle((): void => {
516+
const largeFontSize = "50px";
517+
const normalFontSize = "15px";
518+
519+
const waitText = _t("Wait!");
520+
const scamText = _t(
521+
"If someone told you to copy/paste something here, " +
522+
"there is a high likelihood you're being scammed!",
523+
);
524+
const devText = _t(
525+
"If you know what you're doing, Element is open-source, " +
526+
"be sure to check out our GitHub (https://github.com/vector-im/element-web/) " +
527+
"and contribute!",
528+
);
529+
530+
console.log(
531+
`%c${waitText}\n%c${scamText}\n%c${devText}`,
532+
`font-size:${largeFontSize}; color:blue;`,
533+
`font-size:${normalFontSize}; color:red;`,
534+
`font-size:${normalFontSize};`,
535+
);
536+
}, 1000);
537+
504538
private getFallbackHsUrl(): string {
505539
if (this.props.serverConfig?.isDefault) {
506540
return this.props.config.fallback_hs_url;

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,6 +3024,9 @@
30243024
"Private community": "Private community",
30253025
"To view %(communityName)s, swap to communities in your <a>preferences</a>": "To view %(communityName)s, swap to communities in your <a>preferences</a>",
30263026
"To join %(communityName)s, swap to communities in your <a>preferences</a>": "To join %(communityName)s, swap to communities in your <a>preferences</a>",
3027+
"Wait!": "Wait!",
3028+
"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!",
3029+
"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!",
30273030
"Failed to reject invitation": "Failed to reject invitation",
30283031
"Cannot create rooms in this community": "Cannot create rooms in this community",
30293032
"You do not have permission to create rooms in this community.": "You do not have permission to create rooms in this community.",

0 commit comments

Comments
 (0)