Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
Add random padding to issue requests (#1195)
Browse files Browse the repository at this point in the history
* Add random padding to bulk upload requests

* move to static js file

* do it for regular issue

* fix ref
  • Loading branch information
whaught authored Nov 25, 2020
1 parent f2f8310 commit 9097a07
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
12 changes: 5 additions & 7 deletions cmd/server/assets/codes/bulk-issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
let tzOffset = new Date().getTimezoneOffset();
let randomString = getCookie("retryCode");
if (randomString == "") {
randomString = genCode();
randomString = genRandomString(12);
} else {
$rememberCode.prop("checked", true);
}
Expand Down Expand Up @@ -164,7 +164,7 @@

$newCode.on('click', function(event) {
event.preventDefault();
$retryCode.val(genCode());
$retryCode.val(genRandomString(12));
});

$form.on('submit', function(event) {
Expand Down Expand Up @@ -267,6 +267,9 @@
request["phone"] = $("<div>").text(cols[0].trim()).html();
request["testDate"] = (cols.length > 1) ? $("<div>").text(cols[1].trim()).html() : "";
request["symptomDate"] = (cols.length > 2) ? $("<div>").text(cols[2].trim()).html() : "";
// Request is padded with 5-15 random chars. These are ignored but vary the size of the request
// to prevent network traffic observation.
request["padding"] = btoa(genRandomString(5 + Math.floor(Math.random() * 15)));
if (request["phone"] == "") {
return "";
}
Expand Down Expand Up @@ -306,11 +309,6 @@
},
});
}

// generates a random 16 digit alphanumeric code
function genCode() {
return Math.random().toString(36).substr(2, 8) + Math.random().toString(36).substr(2, 8);
}
</script>
</body>

Expand Down
6 changes: 5 additions & 1 deletion cmd/server/assets/codes/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ <h1>{{t $.locale "header.create-verification-code"}}</h1>
// Clear and hide errors
flash.clear();

let data = {};
let data = {
// Request is padded with 5-15 random chars. These are ignored but vary the size of the request
// to prevent network traffic observation.
'padding': btoa(genRandomString(5 + Math.floor(Math.random() * 15))),
};
$($form.serializeArray()).each(function(i, obj) {
data[obj.name] = obj.value
});
Expand Down
13 changes: 13 additions & 0 deletions cmd/server/assets/static/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,16 @@ function loginScripts(hasCurrentUser, onLoginSuccess) {
$factors.append($li);
}
}

// generates a random alphanumeric code
function genRandomString(len) {
let i = len;
let s = "";
for (; i >= 6; i -= 6) {
s += Math.random().toString(36).substr(2, 8);
}
if (i > 0) {
s += Math.random().toString(36).substr(2, 2 + i);
}
return s;
}

0 comments on commit 9097a07

Please sign in to comment.