Skip to content

Commit 57c9a26

Browse files
committed
Password via url requires to be encoded in base64
1 parent b3c2094 commit 57c9a26

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

webssh/static/js/main.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ jQuery(function($){
103103
}
104104

105105

106+
function decode_password(encoded) {
107+
try {
108+
return window.atob(encoded);
109+
} catch (e) {
110+
console.error(e);
111+
}
112+
}
113+
114+
106115
function parse_url_data(string, form_map, opts_map) {
107116
var i, pair, key, val,
108117
arr = string.split('&');
@@ -112,6 +121,10 @@ jQuery(function($){
112121
key = pair[0].trim().toLowerCase();
113122
val = pair[1] && pair[1].trim();
114123

124+
if (key === 'password' && val) {
125+
val = decode_password(val);
126+
}
127+
115128
if (form_map[key] === '') {
116129
form_map[key] = val;
117130
} else if (opts_map[key] === '') {
@@ -762,18 +775,24 @@ jQuery(function($){
762775

763776
restore_items(fields);
764777

765-
initialize_map(fields.concat(['password']), url_form_data);
778+
initialize_map(fields.concat(['password', 'totp']), url_form_data);
766779
initialize_map(['bgcolor', 'title', 'encoding', 'command'], url_opts_data);
767780

768781
parse_url_data(
769782
decode_uri(window.location.search.substring(1)) + '&' + decode_uri(window.location.hash.substring(1)),
770783
url_form_data, url_opts_data
771784
);
772-
console.log(url_form_data);
773-
console.log(url_opts_data);
774-
775-
if (url_form_data.hostname && url_form_data.username) {
776-
connect(url_form_data);
785+
// console.log(url_form_data);
786+
// console.log(url_opts_data);
787+
788+
if (url_form_data.password === undefined) {
789+
log_status('Password via url must be encoded in base64.');
790+
} else {
791+
if (url_form_data.hostname && url_form_data.username) {
792+
connect(url_form_data);
793+
} else {
794+
log_status('Values of hostname and username are required.');
795+
}
777796
}
778797

779798
});

0 commit comments

Comments
 (0)