increase max websocket read limit. protect frontend from exceeding the read limit. limit input size to 10k characters. (#606)

This commit is contained in:
Mike Sawka 2024-04-25 15:07:41 -07:00 committed by GitHub
parent 6e28151dad
commit 21d0dd076b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 14 additions and 4 deletions

View File

@ -47,6 +47,8 @@ export const TabIcons = [
"file", "file",
]; ];
export const MaxWebSocketSendSize = 64 * 1024 - 100;
// @ts-ignore // @ts-ignore
export const VERSION = __WAVETERM_VERSION__; export const VERSION = __WAVETERM_VERSION__;
// @ts-ignore // @ts-ignore

View File

@ -13,6 +13,7 @@ import { getMonoFontSize } from "@/util/textmeasure";
import * as appconst from "@/app/appconst"; import * as appconst from "@/app/appconst";
type OV<T> = mobx.IObservableValue<T>; type OV<T> = mobx.IObservableValue<T>;
const MaxInputLength = 10 * 1024;
function pageSize(div: any): number { function pageSize(div: any): number {
if (div == null) { if (div == null) {
@ -616,7 +617,7 @@ class TextAreaInput extends React.Component<{ screen: Screen; onHeightChange: ()
<CmdInputKeybindings inputObject={this}></CmdInputKeybindings> <CmdInputKeybindings inputObject={this}></CmdInputKeybindings>
</If> </If>
<If condition={renderHistoryKeybindings}> <If condition={renderHistoryKeybindings}>
<HistoryKeybindings inputObject={this}></HistoryKeybindings> <HistoryKeybindings></HistoryKeybindings>
</If> </If>
<If condition={!util.isBlank(shellType)}> <If condition={!util.isBlank(shellType)}>
@ -637,6 +638,7 @@ class TextAreaInput extends React.Component<{ screen: Screen; onHeightChange: ()
onChange={this.onChange} onChange={this.onChange}
onSelect={this.onSelect} onSelect={this.onSelect}
placeholder="Type here..." placeholder="Type here..."
maxLength={MaxInputLength}
className={cn("textarea", { "display-disabled": auxViewFocused })} className={cn("textarea", { "display-disabled": auxViewFocused })}
></textarea> ></textarea>
<input <input

View File

@ -5,6 +5,7 @@ import * as mobx from "mobx";
import { sprintf } from "sprintf-js"; import { sprintf } from "sprintf-js";
import { boundMethod } from "autobind-decorator"; import { boundMethod } from "autobind-decorator";
import dayjs from "dayjs"; import dayjs from "dayjs";
import * as appconst from "@/app/appconst";
class WSControl { class WSControl {
wsConn: any; wsConn: any;
@ -171,7 +172,13 @@ class WSControl {
if (!this.open.get()) { if (!this.open.get()) {
return; return;
} }
this.wsConn.send(JSON.stringify(data)); let msg = JSON.stringify(data);
const byteSize = new Blob([msg]).size;
if (byteSize > appconst.MaxWebSocketSendSize) {
console.log("ws message too large", byteSize, data.type, msg.substring(0, 100));
return;
}
this.wsConn.send(msg);
} }
pushMessage(data: any) { pushMessage(data: any) {

View File

@ -990,7 +990,6 @@ func doShutdown(reason string) {
} }
func configDirHandler(w http.ResponseWriter, r *http.Request) { func configDirHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("running?")
configPath := r.URL.Path configPath := r.URL.Path
configFullPath := path.Join(scbase.GetWaveHomeDir(), configPath) configFullPath := path.Join(scbase.GetWaveHomeDir(), configPath)
dirFile, err := os.Open(configFullPath) dirFile, err := os.Open(configFullPath)

View File

@ -119,7 +119,7 @@ func (ws *WSShell) ReadPump() {
defer func() { defer func() {
ws.Conn.Close() ws.Conn.Close()
}() }()
ws.Conn.SetReadLimit(4096) ws.Conn.SetReadLimit(64 * 1024)
ws.Conn.SetReadDeadline(time.Now().Add(readWait)) ws.Conn.SetReadDeadline(time.Now().Add(readWait))
for { for {
_, message, err := ws.Conn.ReadMessage() _, message, err := ws.Conn.ReadMessage()