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,13 +389,27 @@ function handleConnection(socket, config) {
function handleResize(stream, data) { function handleResize(stream, data) {
const { rows, cols } = data const { rows, cols } = data
if (stream) { if (stream) {
debug(`Resizing terminal to ${rows}x${cols}`) let resized = false
sessionState.rows = rows
sessionState.cols = cols if (rows != null && validator.isInt(rows.toString())) {
stream.setWindow(rows, cols) sessionState.rows = parseInt(rows, 10)
return 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")
} }
console.warn("handleResize: Attempted to resize closed connection")
} }
/** /**
@ -406,10 +420,14 @@ function handleConnection(socket, config) {
*/ */
function handleControl(socket, stream, data) { function handleControl(socket, stream, data) {
debug(`handleControl: Received control data: ${data}`) debug(`handleControl: Received control data: ${data}`)
if (data === "replayCredentials" && stream) { if (validator.isIn(data, ["replayCredentials", "reauth"]) && stream) {
replayCredentials(socket, stream) if (data === "replayCredentials" && stream) {
} else if (data === "reauth") { replayCredentials(socket, stream)
handleReauth(socket) } else if (data === "reauth") {
handleReauth(socket)
}
} else {
console.warn(`handleControl: Invalid control command received: ${data}`)
} }
} }
@ -420,12 +438,12 @@ function handleConnection(socket, config) {
sessionState.term = term sessionState.term = term
debug(`handleTerminal: Set term to ${sessionState.term}`) debug(`handleTerminal: Set term to ${sessionState.term}`)
} }
if (rows != null && validator.isInt(rows.toString())) { if (rows != null && validator.isInt(rows.toString())) {
sessionState.rows = parseInt(rows, 10) sessionState.rows = parseInt(rows, 10)
debug(`handleTerminal: Set rows to ${sessionState.rows}`) debug(`handleTerminal: Set rows to ${sessionState.rows}`)
} }
if (cols != null && validator.isInt(cols.toString())) { if (cols != null && validator.isInt(cols.toString())) {
sessionState.cols = parseInt(cols, 10) sessionState.cols = parseInt(cols, 10)
debug(`handleTerminal: Set cols to ${sessionState.cols}`) debug(`handleTerminal: Set cols to ${sessionState.cols}`)