Skip to content

Instantly share code, notes, and snippets.

@richsoni
Last active May 28, 2019 15:07
Show Gist options
  • Save richsoni/4650832fed0bf00e85d23d2ac769e855 to your computer and use it in GitHub Desktop.
Save richsoni/4650832fed0bf00e85d23d2ac769e855 to your computer and use it in GitHub Desktop.
Cookie Management Background
// Can be pasted in a Chrome console to overflow the client's cookie
sizeof = (str) => (new TextEncoder('utf-8').encode(str)).length
logSize = (str, label) => console.log('sizeof ', label || str, ' ', sizeof(str))
cookieChar='🍪';
repeat = 1000;
totalLimit=3000;
cookieVal = cookieChar.repeat(repeat);
logSize(cookieChar);
logSize(cookieVal, cookieChar+' '+'(repeat '+repeat+'X)')
keyPrefix = 1;
while(sizeof(document.cookie) < totalLimit && keyPrefix < 10){
cookieName = '_hp2.'+keyPrefix
console.log('adding ', cookieName)
document.cookie=cookieName+'='+cookieVal
logSize(document.cookie, 'document.cookie')
keyPrefix++;
}
// Can be pasted in a Chrome console to overflow the client's cookie
const https = require('https');
const cookieChar = "C";
const repeat = 8200;
cookie = "_hp2.blahh="+cookieChar.repeat(repeat)
console.log(cookie)
const options = {
hostname: 'members.wework.com',
port: 443,
path: '/',
method: 'GET',
headers: {
'Set-Cookie': cookie
}
}
console.log("cookieSize: ", Buffer.byteLength(cookie, 'utf8'), "bytes")
const req = https.request(options, (res) => {
console.log(`statusCode: ${res.statusCode}`)
})
req.on('error', (error) => {
console.error(error)
})
req.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment