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

Add a warning to the console to discourage attacks and encourage contributing #7673

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 33 additions & 0 deletions src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
}
}

public componentDidMount(): void {
window.addEventListener("resize", this.onWindowResized);
}

componentDidUpdate(prevProps, prevState) {
if (this.shouldTrackPageChange(prevState, this.state)) {
const durationMs = this.stopPageChangeTimer();
Expand All @@ -467,6 +471,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
this.fontWatcher.stop();
UIStore.destroy();
this.state.resizeNotifier.removeListener("middlePanelResized", this.dispatchTimelineResize);
window.removeEventListener("resize", this.onWindowResized);

if (this.accountPasswordTimer !== null) clearTimeout(this.accountPasswordTimer);
}
Expand Down Expand Up @@ -501,6 +506,34 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
});
}

private onWindowResized = (): void => {
// XXX: This is a very unreliable way to detect whether or not the the devtools are open
this.warnInConsole();
};

private warnInConsole(): 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};`,
);
}

private getFallbackHsUrl(): string {
if (this.props.serverConfig?.isDefault) {
return this.props.config.fallback_hs_url;
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -3023,6 +3023,9 @@
"Private community": "Private community",
"To view %(communityName)s, swap to communities in your <a>preferences</a>": "To view %(communityName)s, swap to communities in your <a>preferences</a>",
"To join %(communityName)s, swap to communities in your <a>preferences</a>": "To join %(communityName)s, swap to communities in your <a>preferences</a>",
"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.",
Expand Down