Clean up potentially unsafe external links (#139)

* Clean up potentially unsafe external links

* fix broken imports

* fix error in conditional

* fix one more typo
This commit is contained in:
Evan Simkowitz
2023-12-13 17:43:30 -08:00
committed by GitHub
parent 535fd0d7d9
commit 3b65e9941a
3 changed files with 24 additions and 21 deletions
+6 -6
View File
@@ -388,7 +388,7 @@ class TextField extends React.Component<TextFieldProps, TextFieldState> {
// Method to handle blur at the component level
@boundMethod
handleComponentBlur() {
if (this.inputRef.current && this.inputRef.current.contains(document.activeElement)) {
if (this.inputRef.current?.contains(document.activeElement)) {
this.inputRef.current.blur();
}
}
@@ -441,7 +441,7 @@ class TextField extends React.Component<TextFieldProps, TextFieldState> {
const { focused, internalValue, error } = this.state;
// Decide if the input should behave as controlled or uncontrolled
const inputValue = value !== undefined ? value : internalValue;
const inputValue = value ?? internalValue;
return (
<div
@@ -573,7 +573,7 @@ class PasswordField extends TextField {
render() {
const { decoration, className, placeholder, maxLength, label } = this.props;
const { focused, internalValue, error, passwordVisible } = this.state;
const inputValue = this.props.value !== undefined ? this.props.value : internalValue;
const inputValue = this.props.value ?? internalValue;
// The input should always receive the real value
const inputProps = {
@@ -798,7 +798,7 @@ class InfoMessage extends React.Component<{ width: number; children: React.React
function LinkRenderer(props: any): any {
let newUrl = "https://extern?" + encodeURIComponent(props.href);
return (
<a href={newUrl} target="_blank">
<a href={newUrl} target="_blank" rel={"noopener"}>
{props.children}
</a>
);
@@ -1032,7 +1032,7 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
const { label, options, value, placeholder, decoration, className, required } = this.props;
const { isOpen, internalValue, highlightedIndex, isTouched } = this.state;
const currentValue = value !== undefined ? value : internalValue;
const currentValue = value ?? internalValue;
const selectedOptionLabel =
options.find((option) => option.value === currentValue)?.label || placeholder || internalValue;
@@ -1165,7 +1165,7 @@ class Modal extends React.Component<ModalProps> {
}
render() {
return ReactDOM.createPortal(this.renderModal(), document.getElementById("app") as HTMLElement);
return ReactDOM.createPortal(this.renderModal(), document.getElementById("app") );
}
}
+8 -5
View File
@@ -11,12 +11,10 @@ import dayjs from "dayjs";
import localizedFormat from "dayjs/plugin/localizedFormat";
import { GlobalModel, GlobalCommandRunner, RemotesModel } from "../../../model/model";
import * as T from "../../../types/types";
import { Markdown } from "../common";
import { Markdown, Toggle, Modal, TextField, NumberField, InputDecoration, Dropdown, PasswordField, Tooltip, Button, Status } from "../common";
import * as util from "../../../util/util";
import * as textmeasure from "../../../util/textmeasure";
import { Toggle, Modal } from "../common";
import { ClientDataType } from "../../../types/types";
import { TextField, NumberField, InputDecoration, Dropdown, PasswordField, Tooltip, Button, Status } from "../common";
import { ReactComponent as WarningIcon } from "../../assets/icons/line/triangle-exclamation.svg";
import shield from "../../assets/icons/shield_check.svg";
@@ -279,7 +277,7 @@ class TosModal extends React.Component<{}, {}> {
</div>
</div>
<div className="item">
<a target="_blank" href={util.makeExternLink("https://discord.gg/XfvZ334gwU")}>
<a target="_blank" href={util.makeExternLink("https://discord.gg/XfvZ334gwU")} rel={"noopener"}>
<img src={help} alt="Help" />
</a>
<div className="item-inner">
@@ -288,7 +286,7 @@ class TosModal extends React.Component<{}, {}> {
Get help, submit feature requests, report bugs, or just chat with fellow
terminal enthusiasts.
<br />
<a target="_blank" href={util.makeExternLink("https://discord.gg/XfvZ334gwU")}>
<a target="_blank" href={util.makeExternLink("https://discord.gg/XfvZ334gwU")} rel={"noopener"}>
Join the Wave&nbsp;Discord&nbsp;Channel
</a>
</div>
@@ -298,6 +296,7 @@ class TosModal extends React.Component<{}, {}> {
<a
target="_blank"
href={util.makeExternLink("https://github.com/wavetermdev/waveterm")}
rel={"noopener"}
>
<img src={github} alt="Github" />
</a>
@@ -309,6 +308,7 @@ class TosModal extends React.Component<{}, {}> {
<a
target="_blank"
href={util.makeExternLink("https://github.com/wavetermdev/waveterm")}
rel={"noopener"}
>
Github&nbsp;(wavetermdev/waveterm)
</a>
@@ -416,6 +416,7 @@ class AboutModal extends React.Component<{}, {}> {
<a
className="wave-button wave-button-link color-standard"
href={util.makeExternLink("https://github.com/wavetermdev/waveterm")}
rel={"noopener"}
target="_blank"
>
<i className="fa-brands fa-github"></i>
@@ -424,6 +425,7 @@ class AboutModal extends React.Component<{}, {}> {
<a
className="wave-button wave-button-link color-standard"
href={util.makeExternLink("https://www.waveterm.dev/")}
rel={"noopener"}
target="_blank"
>
<i className="fa-sharp fa-light fa-globe"></i>
@@ -432,6 +434,7 @@ class AboutModal extends React.Component<{}, {}> {
<a
className="wave-button wave-button-link color-standard"
href={util.makeExternLink("https://github.com/wavetermdev/waveterm/blob/main/LICENSE")}
rel={"noopener"}
target="_blank"
>
<i className="fa-sharp fa-light fa-book-blank"></i>
+10 -10
View File
@@ -16,10 +16,10 @@ dayjs.extend(localizedFormat);
class InfoMsg extends React.Component<{}, {}> {
getAfterSlash(s: string): string {
if (s.startsWith("^/")) {
return s.substr(1);
return s.substring(1);
}
if (s.startsWith("^")) {
return s.substr(1);
return s.substring(1);
}
let slashIdx = s.lastIndexOf("/");
if (slashIdx == s.length - 1) {
@@ -28,7 +28,7 @@ class InfoMsg extends React.Component<{}, {}> {
if (slashIdx == -1) {
return s;
}
return s.substr(slashIdx + 1);
return s.substring(slashIdx + 1);
}
hasSpace(s: string): boolean {
@@ -55,12 +55,12 @@ class InfoMsg extends React.Component<{}, {}> {
let activeScreen = model.getActiveScreen();
return (
<div className="cmd-input-info" style={{ display: infoShow ? "block" : "none" }}>
<If condition={infoMsg && infoMsg.infotitle != null}>
<If condition={infoMsg?.infotitle}>
<div key="infotitle" className="info-title">
{titleStr}
</div>
</If>
<If condition={infoMsg && infoMsg.infomsg != null}>
<If condition={infoMsg?.infomsg}>
<div key="infomsg" className="info-msg">
<If condition={infoMsg.infomsghtml}>
<span dangerouslySetInnerHTML={{ __html: infoMsg.infomsg }} />
@@ -68,22 +68,22 @@ class InfoMsg extends React.Component<{}, {}> {
<If condition={!infoMsg.infomsghtml}>{infoMsg.infomsg}</If>
</div>
</If>
<If condition={infoMsg && infoMsg.websharelink && activeScreen != null}>
<If condition={infoMsg?.websharelink && activeScreen != null}>
<div key="infomsg" className="info-msg">
started sharing screen at{" "}
<a target="_blank" href={makeExternLink(activeScreen.getWebShareUrl())}>
<a target="_blank" href={makeExternLink(activeScreen.getWebShareUrl())} rel={"noopener"}>
[link]
</a>
</div>
</If>
<If condition={infoMsg && infoMsg.infolines != null}>
<If condition={infoMsg?.infolines}>
<div key="infolines" className="info-lines">
<For index="idx" each="line" of={infoMsg.infolines}>
<div key={idx}>{line == "" ? " " : line}</div>
</For>
</div>
</If>
<If condition={infoMsg && infoMsg.infocomps != null && infoMsg.infocomps.length > 0}>
<If condition={infoMsg?.infocomps?.length > 0}>
<div key="infocomps" className="info-comps">
<For each="istr" index="idx" of={infoMsg.infocomps}>
<div
@@ -105,7 +105,7 @@ class InfoMsg extends React.Component<{}, {}> {
</If>
</div>
</If>
<If condition={infoMsg && infoMsg.infoerror != null}>
<If condition={infoMsg?.infoerror}>
<div key="infoerror" className="info-error">
[error] {infoMsg.infoerror}
</div>