Commit c0b3a4bd authored by nextime's avatar nextime

Fix password echo security issue in web terminal

- Add passwordMode flag to detect password prompts from SSH server
- Disable local echo when password prompts are detected (Password:, password:, etc.)
- Re-enable echo after password is submitted (on Enter key or new prompt)
- Reset passwordMode on disconnect for clean state
- Maintain security by not displaying passwords in plain text
- Preserve normal command echo for non-password input
parent 09245516
...@@ -34,6 +34,7 @@ let term = null; ...@@ -34,6 +34,7 @@ let term = null;
let connected = false; let connected = false;
let requestId = null; let requestId = null;
let pollInterval = null; let pollInterval = null;
let passwordMode = false;
document.getElementById('connectBtn').addEventListener('click', connect); document.getElementById('connectBtn').addEventListener('click', connect);
document.getElementById('disconnectBtn').addEventListener('click', disconnect); document.getElementById('disconnectBtn').addEventListener('click', disconnect);
...@@ -137,13 +138,20 @@ function connect() { ...@@ -137,13 +138,20 @@ function connect() {
if (data === '\r' || data === '\n') { if (data === '\r' || data === '\n') {
// Enter key - let server handle the command execution // Enter key - let server handle the command execution
term.write('\r\n'); term.write('\r\n');
// Exit password mode after enter
passwordMode = false;
} else if (data === '\x7f' || data === '\b') { } else if (data === '\x7f' || data === '\b') {
// Backspace - handle locally // Backspace - handle locally only if not in password mode
if (!passwordMode) {
term.write('\b \b'); term.write('\b \b');
}
} else if (data >= ' ' && data <= '~') { } else if (data >= ' ' && data <= '~') {
// Printable characters - echo locally // Printable characters - echo locally only if not in password mode
if (!passwordMode) {
term.write(data); term.write(data);
} }
// Stay in password mode for printable characters
}
// Send data to server // Send data to server
fetch('/terminal/{{ client_id }}/data', { fetch('/terminal/{{ client_id }}/data', {
...@@ -158,6 +166,7 @@ function connect() { ...@@ -158,6 +166,7 @@ function connect() {
function disconnect() { function disconnect() {
connected = false; connected = false;
passwordMode = false; // Reset password mode
document.getElementById('connectBtn').disabled = false; document.getElementById('connectBtn').disabled = false;
document.getElementById('disconnectBtn').disabled = true; document.getElementById('disconnectBtn').disabled = true;
document.getElementById('sshUsername').disabled = false; document.getElementById('sshUsername').disabled = false;
...@@ -189,6 +198,19 @@ function pollData() { ...@@ -189,6 +198,19 @@ function pollData() {
.then(response => response.text()) .then(response => response.text())
.then(data => { .then(data => {
if (data) { if (data) {
// Check for password prompts
if (data.toLowerCase().includes('password:') ||
data.toLowerCase().includes('password for') ||
data.toLowerCase().includes('enter passphrase')) {
passwordMode = true;
}
// Check for end of password prompt (new prompt or command output)
if (passwordMode && (data.includes('$ ') || data.includes('# ') ||
data.includes('> ') || data.includes('\n$') || data.includes('\n#'))) {
passwordMode = false;
}
// Ensure proper line ending handling // Ensure proper line ending handling
term.write(data.replace(/\n/g, '\r\n')); term.write(data.replace(/\n/g, '\r\n'));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment