Skip to content

Commit

Permalink
left pad names to hide size-based info leakage
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrose committed Dec 2, 2023
1 parent ad419b4 commit 4ddfed8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ function submitNames() {

var linkStub = window.location.origin + window.location.pathname + "who.html#";

var maxLen = Math.max(...names.map((n) => n.length));

links.innerHTML = names.map(
(gifter, i) => {
var link = composeLink(linkStub, gifter, newNames[i]);
var link = composeLink(linkStub, gifter, newNames[i], maxLen);
return "<li>" + gifter + ": <a href=\"" + link + "\">" + link + "</a></li>"
}
).join("\n");
}

function composeLink(stub, gifter, giftee) {
function composeLink(stub, gifter, giftee, maxLen) {
gifter = gifter.padStart(maxLen);
giftee = giftee.padStart(maxLen);
return stub + bytesToBase64(new TextEncoder().encode(gifter + "," + giftee))
}

Expand Down
4 changes: 2 additions & 2 deletions style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
body {
margin: 40px auto;
max-width: 650px;
max-width: 800px;
line-height: 1.6;
font-size: 20px;
color: #444;
Expand All @@ -13,7 +13,7 @@ input {
}

input[type="text"] {
width: 600px;
width: 800px;
height: 1.6;
}

Expand Down
2 changes: 2 additions & 0 deletions who.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ function main() {
var gifter
var giftee
[gifter, giftee] = new TextDecoder().decode(base64ToBytes(document.location.hash.split("#")[1])).split(",")
gifter = gifter.replace(/^\s+/g, '');
giftee = giftee.replace(/^\s+/g, '');
document.getElementById("who").innerHTML = "Hello, " + gifter + "! You are buying a gift for " + giftee + ".";
}

Expand Down

0 comments on commit 4ddfed8

Please sign in to comment.