feat: validate handleResize

feat: validate handleControl
This commit is contained in:
Bill Church 2024-08-17 14:25:44 +00:00
parent aab1a35bc9
commit b4cbfb4b46
No known key found for this signature in database

View file

@ -389,14 +389,28 @@ function handleConnection(socket, config) {
function handleResize(stream, data) {
const { rows, cols } = data
if (stream) {
debug(`Resizing terminal to ${rows}x${cols}`)
sessionState.rows = rows
sessionState.cols = cols
stream.setWindow(rows, cols)
return
let resized = false
if (rows != null && validator.isInt(rows.toString())) {
sessionState.rows = parseInt(rows, 10)
resized = true
}
if (cols != null && validator.isInt(cols.toString())) {
sessionState.cols = parseInt(cols, 10)
resized = true
}
if (resized) {
debug(`Resizing terminal to ${sessionState.rows}x${sessionState.cols}`)
stream.setWindow(sessionState.rows, sessionState.cols)
} else {
debug("handleResize: No valid resize dimensions provided")
}
} else {
console.warn("handleResize: Attempted to resize closed connection")
}
}
/**
* Handles control commands from the client
@ -406,11 +420,15 @@ function handleConnection(socket, config) {
*/
function handleControl(socket, stream, data) {
debug(`handleControl: Received control data: ${data}`)
if (validator.isIn(data, ["replayCredentials", "reauth"]) && stream) {
if (data === "replayCredentials" && stream) {
replayCredentials(socket, stream)
} else if (data === "reauth") {
handleReauth(socket)
}
} else {
console.warn(`handleControl: Invalid control command received: ${data}`)
}
}
function handleTerminal(socket, conn, data) {