Skip to content

Commit

Permalink
get headers #12
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamjuliot committed Jul 30, 2020
1 parent 3e299ad commit ea1d59b
Showing 1 changed file with 43 additions and 25 deletions.
68 changes: 43 additions & 25 deletions creep.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,24 @@
return trusted ? val : sendToTrash(name, val)
}

// ip address
const getIP = async () => {
// headers
const getHeaders = async () => {
const promiseUndefined = new Promise(resolve => resolve(undefined))

try {
const api = 'https://api6.ipify.org/?format=json'
const api = 'https://www.cloudflare.com/cdn-cgi/trace'
const res = await fetch(api)
const json = await res.json()
return json
const text = await res.text()
const lines = text.match(/^(?:ip|uag|loc|tls)=(.*)$/igm)
const data = {}
lines.forEach(line => {
const key = line.split('=')[0]
const value = line.substr(line.indexOf('=') + 1)
data[key] = value
})
return data
}
catch (error) {
captureError(error, 'api6.ipify.org: failed or client blocked')
captureError(error, 'cloudflare.com: failed or client blocked')
return promiseUndefined
}
}
Expand Down Expand Up @@ -1306,14 +1312,14 @@
// await
const asyncValues = timer('')
const [
ipAddress,
headers,
voices,
mediaDevices,
highEntropy,
offlineAudio,
fonts
] = await Promise.all([
getIP(),
getHeaders(),
getVoices(),
getMediaDevices(),
highEntropyValues(),
Expand All @@ -1324,7 +1330,6 @@
})
asyncValues('Async computation complete')

const ipAddressComputed = !ipAddress ? undefined : ipAddress.ip
const voicesComputed = !voices ? undefined : voices.map(({ name, lang }) => ({ name, lang }))
const mediaDevicesComputed = !mediaDevices ? undefined : mediaDevices.map(({ kind }) => ({ kind })) // chrome randomizes groupId

Expand All @@ -1340,7 +1345,8 @@
// await hash values
const hashProcess = timer('')
const [
navHash, // order must match
headersHash, // order must match
navHash,
mimeTypesHash,
pluginsHash,
navVersionHash,
Expand All @@ -1364,6 +1370,7 @@
trashHash,
liesHash
] = await Promise.all([
hashify(headers),
hashify(navComputed),
hashify(mimeTypes),
hashify(plugins),
Expand Down Expand Up @@ -1399,7 +1406,7 @@
}

const fingerprint = {
ipAddress: [ipAddressComputed],
headers: [headers, headersHash],
nav: [navComputed, navHash],
highEntropy: [highEntropy, highEntropyHash],
window: [windowVersionComputed, windowVersionHash],
Expand Down Expand Up @@ -1560,19 +1567,6 @@
const data = `
<section>
<div id="fingerprint-data">
${
!fp.ipAddress[0] ? '': (() => {
const plural = pluralify(trashBin.length)
const [ ip ] = fp.ipAddress
return `
<div>
<strong>IP address</strong>
<div>${ip}</div>
</div>
`
})()
}
<div>
<strong>Fingerprint</strong>
Expand Down Expand Up @@ -1629,6 +1623,30 @@
})()
}
${
!fp.headers[0] ? `<div>headers: ${note.blocked}</div>`: (() => {
const [ headers, hash ] = fp.headers
return `
<div>
<div>headers: ${hash}</div>
${
Object.keys(headers).map(key => {
const value = headers[key]
key = (
key == 'ip' ? 'ip address' :
key == 'uag' ? 'user agent' :
key == 'loc' ? 'location' :
key == 'tls' ? 'tls version' :
key
)
return `<div>${key}: ${value}</div>`
}).join('')
}
</div>
`
})()
}
<div>canvas: ${identify(fp.canvas, 'identifyBrowser')}</div>
<div>
<div>webglDataURL: ${identify(fp.webglDataURL, 'identifyBrowser')}</div>
Expand Down

0 comments on commit ea1d59b

Please sign in to comment.