Skip to content

Instantly share code, notes, and snippets.

@SmugZombie
Last active February 8, 2023 23:43
Show Gist options
  • Save SmugZombie/c908e7a0926ff2294c94a465cdec3280 to your computer and use it in GitHub Desktop.
Save SmugZombie/c908e7a0926ff2294c94a465cdec3280 to your computer and use it in GitHub Desktop.
Riskwatch HAR Decoder
const fs = require('fs');
fs.readFile('path/to/your/har/file.har', 'utf8', (err, data) => {
if (err) throw err;
let har;
try {
har = JSON.parse(data);
} catch (e) {
console.error('Error parsing the input file as JSON:', e.message);
return;
}
const requests = har.log.entries
.map(entry => {
const { method, url } = entry.request;
const { queryString, postData } = entry;
const headers = entry.request.headers;
let bearerTokenUsed = false;
headers.forEach(header => {
if (header.name.toLowerCase() === 'authorization' && header.value.startsWith('Bearer ')) {
bearerTokenUsed = true;
}
});
return {
method,
url,
queryString,
postData,
bearerTokenUsed,
};
})
.filter(request => request.url.includes('riskwatch.com') && !request.url.match(/\.(js|css|gif|png)$/i) && request.bearerTokenUsed)
.reduce((acc, request) => {
if (!acc.find(r => r.url === request.url)) {
acc.push(request);
}
return acc;
}, []);
console.log(requests);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment