fix post data

This commit is contained in:
zefie
2021-08-10 19:06:15 -04:00
parent 7e8e9208e0
commit 12d50f6e1c
2 changed files with 41 additions and 29 deletions

View File

@@ -274,7 +274,9 @@ async function processURL(socket, request_headers) {
} }
if (request_headers.post_data) { if (request_headers.post_data) {
var post_data_string = request_headers.post_data.toString(CryptoJS.enc.Utf8).replace("\0", ""); var post_data_string = '';
try {
post_data_string = request_headers.post_data.toString(CryptoJS.enc.Utf8).replace("\0", ""); // if not text this will probably throw an exception
if (isUnencryptedString(post_data_string)) { if (isUnencryptedString(post_data_string)) {
if (post_data_string.indexOf('=')) { if (post_data_string.indexOf('=')) {
if (post_data_string.indexOf('&')) { if (post_data_string.indexOf('&')) {
@@ -297,6 +299,9 @@ async function processURL(socket, request_headers) {
} }
} }
} }
} catch (e) {
socket_sessions[socket.id].expecting_post_data = true;
}
} }
if ((shortURL.indexOf("http") != 0 && shortURL.indexOf("ftp") != 0 && shortURL.indexOf(":") > 0 && shortURL.indexOf(":/") == -1)) { if ((shortURL.indexOf("http") != 0 && shortURL.indexOf("ftp") != 0 && shortURL.indexOf(":") > 0 && shortURL.indexOf(":/") == -1)) {
@@ -748,7 +753,7 @@ async function sendToClient(socket, headers_obj, data) {
if (socket_sessions[socket.id].post_data) delete socket_sessions[socket.id].post_data; if (socket_sessions[socket.id].post_data) delete socket_sessions[socket.id].post_data;
if (socket_sessions[socket.id].post_data_length) delete socket_sessions[socket.id].post_data_length; if (socket_sessions[socket.id].post_data_length) delete socket_sessions[socket.id].post_data_length;
if (socket_sessions[socket.id].post_data_percents_shown) delete socket_sessions[socket.id].post_data_percents_shown; if (socket_sessions[socket.id].post_data_percents_shown) delete socket_sessions[socket.id].post_data_percents_shown;
socket.setTimeout(minisrv_config.config.socket_timeout * 1000);
if (socket_sessions[socket.id].close_me) socket.end(); if (socket_sessions[socket.id].close_me) socket.end();
if (headers_obj["Connection"]) { if (headers_obj["Connection"]) {
if (headers_obj["Connection"].toLowerCase() == "close" && wtv_connection_close == "true") { if (headers_obj["Connection"].toLowerCase() == "close" && wtv_connection_close == "true") {
@@ -1094,6 +1099,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
// handle POST // handle POST
if (headers['request']) { if (headers['request']) {
if (headers['request'].substring(0, 4) == "POST") { if (headers['request'].substring(0, 4) == "POST") {
socket.setTimeout(minisrv_config.config.post_data_socket_timeout * 1000);
if (typeof socket_sessions[socket.id].post_data == "undefined") { if (typeof socket_sessions[socket.id].post_data == "undefined") {
if (socket_sessions[socket.id].post_data_percents_shown) delete socket_sessions[socket.id].post_data_percents_shown; if (socket_sessions[socket.id].post_data_percents_shown) delete socket_sessions[socket.id].post_data_percents_shown;
socket_sessions[socket.id].post_data_length = headers['Content-length'] || headers['Content-Length'] || 0; socket_sessions[socket.id].post_data_length = headers['Content-length'] || headers['Content-Length'] || 0;
@@ -1313,8 +1319,9 @@ async function handleSocket(socket) {
socket_sessions[socket.id] = []; socket_sessions[socket.id] = [];
socket.minisrv_pc_mode = false; socket.minisrv_pc_mode = false;
socket.setEncoding('hex'); //set data encoding (Text: 'ascii', 'utf8' ~ Binary: 'hex', 'base64' (do not trust 'binary' encoding)) socket.setEncoding('hex'); //set data encoding (Text: 'ascii', 'utf8' ~ Binary: 'hex', 'base64' (do not trust 'binary' encoding))
socket.setTimeout(10800000); // 3 hours socket.setTimeout(minisrv_config.config.socket_timeout * 1000);
socket.on('data', function (data_hex) { socket.on('data', function (data_hex) {
if (socket_sessions[socket.id]) {
if (!socket_sessions[socket.id].secure && !socket_sessions[socket.id].expecting_post_data) { if (!socket_sessions[socket.id].secure && !socket_sessions[socket.id].expecting_post_data) {
// buffer unencrypted data until we see the classic double-newline, or get blank // buffer unencrypted data until we see the classic double-newline, or get blank
if (!socket_sessions[socket.id].header_buffer) socket_sessions[socket.id].header_buffer = ""; if (!socket_sessions[socket.id].header_buffer) socket_sessions[socket.id].header_buffer = "";
@@ -1329,6 +1336,9 @@ async function handleSocket(socket) {
if (socket_sessions[socket.id].header_buffer) delete socket_sessions[socket.id].header_buffer; if (socket_sessions[socket.id].header_buffer) delete socket_sessions[socket.id].header_buffer;
processRequest(this, data_hex); processRequest(this, data_hex);
} }
} else {
cleanupSocket(socket);
}
}); });
socket.on('timeout', function () { socket.on('timeout', function () {

View File

@@ -13,6 +13,8 @@
"hide_ssid_in_logs": true, "hide_ssid_in_logs": true,
"post_percentages": [ 0, 25, 50, 100 ], "post_percentages": [ 0, 25, 50, 100 ],
"verbosity": 2, "verbosity": 2,
"socket_timeout": 10800,
"post_data_socket_timeout": 30,
"error_log_file": "errors.log", "error_log_file": "errors.log",
"catchall_file_name": "catchall.js", "catchall_file_name": "catchall.js",
"enable_lzpf_compression": false, "enable_lzpf_compression": false,