mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-26 23:50:15 +03:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5c4e5d026 |
No files matched your search
Vendored
+2
-3
@@ -15,7 +15,6 @@ declare module '@vue/runtime-core' {
|
||||
AsciiTextDrawer: typeof import('./src/tools/ascii-text-drawer/ascii-text-drawer.vue')['default']
|
||||
'Base.layout': typeof import('./src/layouts/base.layout.vue')['default']
|
||||
Base64FileConverter: typeof import('./src/tools/base64-file-converter/base64-file-converter.vue')['default']
|
||||
Base64HexConverter: typeof import('./src/tools/base64-hex-converter/base64-hex-converter.vue')['default']
|
||||
Base64StringConverter: typeof import('./src/tools/base64-string-converter/base64-string-converter.vue')['default']
|
||||
BasicAuthGenerator: typeof import('./src/tools/basic-auth-generator/basic-auth-generator.vue')['default']
|
||||
Bcrypt: typeof import('./src/tools/bcrypt/bcrypt.vue')['default']
|
||||
@@ -83,6 +82,7 @@ declare module '@vue/runtime-core' {
|
||||
FormatTransformer: typeof import('./src/components/FormatTransformer.vue')['default']
|
||||
GitMemo: typeof import('./src/tools/git-memo/git-memo.vue')['default']
|
||||
'GitMemo.content': typeof import('./src/tools/git-memo/git-memo.content.md')['default']
|
||||
HarSanitizer: typeof import('./src/tools/har-sanitizer/har-sanitizer.vue')['default']
|
||||
HashText: typeof import('./src/tools/hash-text/hash-text.vue')['default']
|
||||
HmacGenerator: typeof import('./src/tools/hmac-generator/hmac-generator.vue')['default']
|
||||
'Home.page': typeof import('./src/pages/Home.page.vue')['default']
|
||||
@@ -134,8 +134,8 @@ declare module '@vue/runtime-core' {
|
||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||
NGrid: typeof import('naive-ui')['NGrid']
|
||||
NH1: typeof import('naive-ui')['NH1']
|
||||
NH3: typeof import('naive-ui')['NH3']
|
||||
NIcon: typeof import('naive-ui')['NIcon']
|
||||
@@ -143,7 +143,6 @@ declare module '@vue/runtime-core' {
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
|
||||
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
|
||||
|
||||
+1
-2
@@ -46,7 +46,6 @@
|
||||
"@tiptap/starter-kit": "2.1.6",
|
||||
"@tiptap/vue-3": "2.0.3",
|
||||
"@types/figlet": "^1.5.8",
|
||||
"@types/hex-array": "^1.0.2",
|
||||
"@types/markdown-it": "^13.0.7",
|
||||
"@vicons/material": "^0.12.0",
|
||||
"@vicons/tabler": "^0.12.0",
|
||||
@@ -68,7 +67,6 @@
|
||||
"figlet": "^1.7.0",
|
||||
"figue": "^1.2.0",
|
||||
"fuse.js": "^6.6.2",
|
||||
"hex-array": "^1.0.0",
|
||||
"highlight.js": "^11.7.0",
|
||||
"iarna-toml-esm": "^3.0.5",
|
||||
"ibantools": "^4.3.3",
|
||||
@@ -117,6 +115,7 @@
|
||||
"@types/bcryptjs": "^2.4.2",
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
"@types/dompurify": "^3.0.5",
|
||||
"@types/har-format": "^1.2.16",
|
||||
"@types/jsdom": "^21.0.0",
|
||||
"@types/lodash": "^4.14.192",
|
||||
"@types/mime-types": "^2.1.1",
|
||||
|
||||
Generated
+7
-15
@@ -32,9 +32,6 @@ dependencies:
|
||||
'@types/figlet':
|
||||
specifier: ^1.5.8
|
||||
version: 1.7.0
|
||||
'@types/hex-array':
|
||||
specifier: ^1.0.2
|
||||
version: 1.0.2
|
||||
'@types/markdown-it':
|
||||
specifier: ^13.0.7
|
||||
version: 13.0.9
|
||||
@@ -98,9 +95,6 @@ dependencies:
|
||||
fuse.js:
|
||||
specifier: ^6.6.2
|
||||
version: 6.6.2
|
||||
hex-array:
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0
|
||||
highlight.js:
|
||||
specifier: ^11.7.0
|
||||
version: 11.11.1
|
||||
@@ -241,6 +235,9 @@ devDependencies:
|
||||
'@types/dompurify':
|
||||
specifier: ^3.0.5
|
||||
version: 3.2.0
|
||||
'@types/har-format':
|
||||
specifier: ^1.2.16
|
||||
version: 1.2.16
|
||||
'@types/jsdom':
|
||||
specifier: ^21.0.0
|
||||
version: 21.1.7
|
||||
@@ -3140,9 +3137,9 @@ packages:
|
||||
resolution: {integrity: sha512-C3YYeRQWp2fmq9OryX+FoDy8nXS6scQ7dPptD8LnFDAUNcKWJjXQKDNJD3HVm+kOUsXhTOkpi69vI4EuAr95bA==}
|
||||
dev: true
|
||||
|
||||
/@types/hex-array@1.0.2:
|
||||
resolution: {integrity: sha512-H1QsLqz6k9QTioutUQUiBiyM4CMmE6A1prXHGotw42j8sN5H/ScC5OxIbcrXnipikrJ5Qn3aozWb9UXBKUscJQ==}
|
||||
dev: false
|
||||
/@types/har-format@1.2.16:
|
||||
resolution: {integrity: sha512-fluxdy7ryD3MV6h8pTfTYpy/xQzCFC7m89nOH9y94cNqJ1mDIDPut7MnRHI3F6qRmh/cT2fUjG1MLdCNb4hE9A==}
|
||||
dev: true
|
||||
|
||||
/@types/jsdom@21.1.7:
|
||||
resolution: {integrity: sha512-yOriVnggzrnQ3a9OKOCxaVuSug3w3/SbOj5i7VwXWZEyUNl3bLF9V3MfxGbZKuwqJOQyRfqXyROBB1CoZLFWzA==}
|
||||
@@ -6012,7 +6009,6 @@ packages:
|
||||
glob-parent: 5.1.2
|
||||
merge2: 1.4.1
|
||||
micromatch: 4.0.5
|
||||
dev: false
|
||||
|
||||
/fast-glob@3.3.3:
|
||||
resolution: {integrity: sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==}
|
||||
@@ -6380,7 +6376,7 @@ packages:
|
||||
dependencies:
|
||||
array-union: 2.1.0
|
||||
dir-glob: 3.0.1
|
||||
fast-glob: 3.3.3
|
||||
fast-glob: 3.3.1
|
||||
ignore: 5.2.4
|
||||
merge2: 1.4.1
|
||||
slash: 3.0.0
|
||||
@@ -6502,10 +6498,6 @@ packages:
|
||||
tslib: 2.8.1
|
||||
dev: false
|
||||
|
||||
/hex-array@1.0.0:
|
||||
resolution: {integrity: sha512-dbjcApZ+RBr2DYCqs2gab5So6q4rM5VBqFg8oeOPc/s8PzrD48pf4w9e7DC4G+Gq4CEkHYQxqn7uYAQZKVWo8w==}
|
||||
dev: false
|
||||
|
||||
/highlight.js@11.11.1:
|
||||
resolution: {integrity: sha512-Xwwo44whKBVCYoliBQwaPvtd/2tYFkRQtXDWj1nackaV2JPXx3L0+Jvd8/qCJ2p+ML0/XVkJ2q+Mr+UVdpJK5w==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import Base64 from 'js-base64';
|
||||
import hexArray from 'hex-array';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { isValidBase64 } from '@/utils/base64';
|
||||
|
||||
const textInput = ref('');
|
||||
const base64Output = computed(() => {
|
||||
try {
|
||||
return Base64.fromUint8Array(hexArray.fromString(textInput.value));
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
const { copy: copyTextBase64 } = useCopy({ source: base64Output, text: 'Base64 Hex Array copied to the clipboard' });
|
||||
|
||||
const uppercase = ref(false);
|
||||
const grouping = ref(0);
|
||||
const rowlength = ref(0);
|
||||
|
||||
const base64Input = ref('');
|
||||
const textOutput = computed(() => {
|
||||
try {
|
||||
return hexArray.toString(Base64.toUint8Array(base64Input.value), {
|
||||
uppercase: uppercase.value,
|
||||
grouping: grouping.value,
|
||||
rowlength: rowlength.value,
|
||||
});
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
},
|
||||
);
|
||||
const { copy: copyText } = useCopy({ source: textOutput, text: 'Hex Array copied to the clipboard' });
|
||||
const b64ValidationRules = [
|
||||
{
|
||||
message: 'Invalid base64 string',
|
||||
validator: (value: string) => isValidBase64(value.trim()),
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card title="Hex Array to Base64">
|
||||
<c-input-text
|
||||
v-model:value="textInput"
|
||||
multiline
|
||||
placeholder="Put your Hex Array here..."
|
||||
rows="5"
|
||||
label="Hex Array to encode"
|
||||
raw-text
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
label="Base64 of Hex Array"
|
||||
:value="base64Output"
|
||||
multiline
|
||||
readonly
|
||||
placeholder="The base64 encoding of your Hex Array will be here"
|
||||
rows="5"
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<div flex justify-center>
|
||||
<c-button @click="copyTextBase64()">
|
||||
Copy base64
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Base64 to Hex Array">
|
||||
<n-space align="baseline" justify="center" mb-1>
|
||||
<n-form-item label="Uppercase" label-placement="left">
|
||||
<n-switch v-model:value="uppercase" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Group by" label-placement="left">
|
||||
<n-input-number v-model:value="grouping" :min="0" style="width: 6em" mr-1 /> digits (0 = no grouping)
|
||||
</n-form-item>
|
||||
<n-form-item label="Split as rows by" label-placement="left">
|
||||
<n-input-number v-model:value="rowlength" :min="0" style="width: 6em" mr-1 /> group of digits (0 = no rows)
|
||||
</n-form-item>
|
||||
</n-space>
|
||||
<c-input-text
|
||||
v-model:value="base64Input"
|
||||
multiline
|
||||
placeholder="Your base64 Hex Array..."
|
||||
rows="5"
|
||||
:validation-rules="b64ValidationRules"
|
||||
label="Base64 Hex Array to decode"
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="textOutput"
|
||||
label="Decoded Hex Array"
|
||||
placeholder="The decoded Hex Array will be here"
|
||||
multiline
|
||||
rows="5"
|
||||
readonly
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<div flex justify-center>
|
||||
<c-button @click="copyText()">
|
||||
Copy decoded Hex Array
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
</template>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { FileDigit } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Base64 Hex array encoder/decoder',
|
||||
path: '/base64-hex-converter',
|
||||
description: 'Simply encode and decode Hex array into a their base64 representation.',
|
||||
keywords: ['base64', 'converter', 'conversion', 'web', 'data', 'format', 'atob', 'btoa', 'hex'],
|
||||
component: () => import('./base64-hex-converter.vue'),
|
||||
icon: FileDigit,
|
||||
createdAt: new Date('2025-02-09'),
|
||||
});
|
||||
@@ -0,0 +1,150 @@
|
||||
<script setup lang="ts">
|
||||
import { downloadFile } from './lib/downloadFile';
|
||||
import { defaultScrubItems, getHarInfo, sanitize } from './lib/har_sanitize';
|
||||
|
||||
type ScrubState = Record<ScrubType, Record<string, boolean>>;
|
||||
type ScrubType =
|
||||
| 'cookies'
|
||||
| 'headers'
|
||||
| 'queryArgs'
|
||||
| 'postParams'
|
||||
| 'mimeTypes';
|
||||
|
||||
const typeMap: Record<ScrubType, string> = {
|
||||
cookies: 'Cookies',
|
||||
mimeTypes: 'Mime Types',
|
||||
headers: 'Headers',
|
||||
postParams: 'Post Body Params',
|
||||
queryArgs: 'Query String Parameters',
|
||||
};
|
||||
|
||||
const defaulScrubState: ScrubState = {
|
||||
cookies: {},
|
||||
headers: {},
|
||||
queryArgs: {},
|
||||
postParams: {},
|
||||
mimeTypes: {},
|
||||
};
|
||||
const scrubItemsToClean = ref<ScrubState>(defaulScrubState);
|
||||
|
||||
function getScrubableItems(input: string): ScrubState {
|
||||
const rawItems = getHarInfo(input);
|
||||
const output = { ...defaulScrubState };
|
||||
Object.entries(rawItems).forEach(([key, items]: [string, string[]]) => {
|
||||
output[key as ScrubType] = items.reduce(
|
||||
(acc, curr) => {
|
||||
if (!curr) {
|
||||
return acc;
|
||||
}
|
||||
acc[curr] = defaultScrubItems.includes(curr);
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, boolean>,
|
||||
);
|
||||
return null;
|
||||
});
|
||||
return output;
|
||||
}
|
||||
|
||||
function sanitizeHar(input: string, scrubItems: ScrubState) {
|
||||
const words = new Set<string>();
|
||||
Object.entries(scrubItems.cookies).forEach(([key, val]) => {
|
||||
if (val) {
|
||||
words.add(key);
|
||||
}
|
||||
});
|
||||
Object.entries(scrubItems.headers).forEach(([key, val]) => {
|
||||
if (val) {
|
||||
words.add(key);
|
||||
}
|
||||
});
|
||||
Object.entries(scrubItems.queryArgs).forEach(([key, val]) => {
|
||||
if (val) {
|
||||
words.add(key);
|
||||
}
|
||||
});
|
||||
Object.entries(scrubItems.postParams).forEach(([key, val]) => {
|
||||
if (val) {
|
||||
words.add(key);
|
||||
}
|
||||
});
|
||||
|
||||
const mimeTypes = new Set<string>();
|
||||
Object.entries(scrubItems.mimeTypes).forEach(([key, val]) => {
|
||||
if (val) {
|
||||
mimeTypes.add(key);
|
||||
}
|
||||
});
|
||||
return sanitize(input, {
|
||||
scrubWords: [...words],
|
||||
scrubMimetypes: [...mimeTypes],
|
||||
});
|
||||
}
|
||||
|
||||
const file = ref<File | null>(null);
|
||||
|
||||
const error = ref('');
|
||||
|
||||
function readAsTextAsync(file: File) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsText(file);
|
||||
reader.onload = () => resolve(reader.result?.toString() ?? '');
|
||||
reader.onerror = error => reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
const harContent = ref('');
|
||||
async function onFileUploaded(uploadedFile: File) {
|
||||
file.value = uploadedFile;
|
||||
harContent.value = await readAsTextAsync(uploadedFile);
|
||||
|
||||
error.value = '';
|
||||
try {
|
||||
scrubItemsToClean.value = getScrubableItems(harContent.value);
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
function processHar() {
|
||||
downloadFile(sanitizeHar(harContent.value, scrubItemsToClean.value), `sanitized-${file.value?.name}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div style="flex: 0 0 100%" mb-3>
|
||||
<div mx-auto max-w-600px>
|
||||
<c-file-upload
|
||||
title="Drag and drop a HAR file here, or click to select a file"
|
||||
accept=".har" @file-upload="onFileUploaded"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<c-alert v-if="error" title="Error">
|
||||
{{ error }}
|
||||
</c-alert>
|
||||
|
||||
<div v-for="(title, key) in typeMap" :key="key" mb-1>
|
||||
<c-card v-if="Object.keys(scrubItemsToClean[key]).length" :title="title">
|
||||
<n-checkbox font-size-5 @update:checked="(allChecked: boolean) => Object.keys(scrubItemsToClean[key]).forEach((name) => scrubItemsToClean[key][name] = allChecked)">
|
||||
All {{ title }}
|
||||
</n-checkbox>
|
||||
<n-space size="large">
|
||||
<n-checkbox v-for="(checked, name) in scrubItemsToClean[key]" :key="name" v-model:checked="scrubItemsToClean[key][name]" style="width: 150px">
|
||||
{{ name }}
|
||||
</n-checkbox>
|
||||
</n-space>
|
||||
</c-card>
|
||||
</div>
|
||||
|
||||
<div v-if="!error" mt-3 flex justify-center>
|
||||
<c-button @click="processHar()">
|
||||
Sanitize and download
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { ClearFormatting } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'HAR Sanitizer',
|
||||
path: '/har-sanitizer',
|
||||
description: 'HAR Files Sanitizer',
|
||||
keywords: ['har', 'sanitizer'],
|
||||
component: () => import('./har-sanitizer.vue'),
|
||||
icon: ClearFormatting,
|
||||
createdAt: new Date('2024-06-17'),
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
export function downloadFile(harOutput: string, name: string) {
|
||||
const blob = new Blob([harOutput], { type: 'application/json' });
|
||||
|
||||
// Create a URL for the Blob
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
// Create an anchor element to trigger the download
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
// Set file name
|
||||
a.download = name;
|
||||
a.style.display = 'none';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Clean up by removing the anchor and revoking the URL
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
/* eslint-disable prefer-regex-literals */
|
||||
import type { Cookie, Har, Header, Param, QueryString } from 'har-format';
|
||||
|
||||
export interface PossibleScrubItems {
|
||||
headers: string[]
|
||||
cookies: string[]
|
||||
queryArgs: string[]
|
||||
postParams: string[]
|
||||
mimeTypes: string[]
|
||||
}
|
||||
|
||||
const defaultMimeTypesList = ['application/javascript', 'text/javascript'];
|
||||
|
||||
const defaultWordList = [
|
||||
'Authorization',
|
||||
'SAMLRequest',
|
||||
'SAMLResponse',
|
||||
'access_token',
|
||||
'appID',
|
||||
'assertion',
|
||||
'auth',
|
||||
'authenticity_token',
|
||||
'challenge',
|
||||
'client_id',
|
||||
'client_secret',
|
||||
'code',
|
||||
'code_challenge',
|
||||
'code_verifier',
|
||||
'email',
|
||||
'facetID',
|
||||
'fcParams',
|
||||
'id_token',
|
||||
'password',
|
||||
'refresh_token',
|
||||
'serverData',
|
||||
'shdf',
|
||||
'state',
|
||||
'token',
|
||||
'usg',
|
||||
'vses2',
|
||||
'x-client-data',
|
||||
];
|
||||
|
||||
export const defaultScrubItems = [...defaultMimeTypesList, ...defaultWordList];
|
||||
|
||||
// The default list of regexes that aren't word dependent
|
||||
// Uses double list so it matches format of word regex
|
||||
const defaultRegex = [
|
||||
[
|
||||
// Redact signature on JWTs
|
||||
{
|
||||
regex: new RegExp(
|
||||
'\\b(ey[A-Za-z0-9-_=]+)\\.(ey[A-Za-z0-9-_=]+)\\.[A-Za-z0-9-_.+/=]+\\b',
|
||||
'g',
|
||||
),
|
||||
replacement: '$1.$2.redacted',
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
function buildRegex(word: string) {
|
||||
return [
|
||||
{
|
||||
// [full word]=[capture]
|
||||
regex: new RegExp(
|
||||
`([\\s";,&?]+${word}=)([\\w+-_/=#|.%&:!*()\`~'"]+?)(&|\\\\",|",|"\\s|"}}|;){1}`,
|
||||
'g',
|
||||
),
|
||||
replacement: `$1[${word} redacted]$3`,
|
||||
},
|
||||
// Set up this way in case "value" isn't directly after "name"
|
||||
// {
|
||||
// "name": "[word]",
|
||||
// "something": "not wanted",
|
||||
// "value": "[capture]"
|
||||
// }
|
||||
{
|
||||
regex: new RegExp(
|
||||
`("name": "${word}",[\\s\\w+:"-\\%!*()\`~'.,#]*?"value": ")((?:\\\\"|[^"])*?)(")`,
|
||||
'g',
|
||||
),
|
||||
replacement: `$1[${word} redacted]$3`,
|
||||
},
|
||||
// "name" comes after "value"
|
||||
// {
|
||||
// "value": "[capture]",
|
||||
// "something": "not wanted",
|
||||
// "name": "[word]"
|
||||
// }
|
||||
{
|
||||
regex: new RegExp(
|
||||
`("value": ")([\\w+-_:&+=#$~/()\\\\.\\,*!|%"\\s;]+)("[,\\s}}]+)([\\s\\w+:"-\\\\%!*\`()~'#.]*"name": "${word}")`,
|
||||
'g',
|
||||
),
|
||||
replacement: `$1[${word} redacted]$3$4`,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function removeContentForMimeTypes(input: string, scrubList: string[]) {
|
||||
const harJSON = JSON.parse(input);
|
||||
|
||||
const entries = harJSON.log.entries;
|
||||
if (!entries) {
|
||||
throw new Error('failed to find entries in HAR file');
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
const response = entry.response;
|
||||
if (response && scrubList.includes(response.content.mimeType)) {
|
||||
response.content.text = `[${response.content.mimeType} redacted]`;
|
||||
}
|
||||
}
|
||||
|
||||
return JSON.stringify(harJSON, null, 2);
|
||||
}
|
||||
|
||||
export function getHarInfo(input: string): PossibleScrubItems {
|
||||
const output = {
|
||||
headers: new Set<string>(),
|
||||
queryArgs: new Set<string>(),
|
||||
cookies: new Set<string>(),
|
||||
postParams: new Set<string>(),
|
||||
mimeTypes: new Set<string>(),
|
||||
};
|
||||
const harJSON: Har = JSON.parse(input);
|
||||
|
||||
const entries = harJSON.log.entries;
|
||||
if (!entries) {
|
||||
throw new Error('failed to find entries in HAR file');
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
const response = entry.response;
|
||||
response.headers.map((header: Header) => output.headers.add(header.name));
|
||||
response.cookies.map((cookie: Cookie) => output.cookies.add(cookie.name));
|
||||
output.mimeTypes.add(response.content.mimeType);
|
||||
|
||||
const request = entry.request;
|
||||
request.headers.map((header: Header) => output.headers.add(header.name));
|
||||
request.queryString.map((arg: QueryString) =>
|
||||
output.queryArgs.add(arg.name),
|
||||
);
|
||||
request.cookies.map((cookie: Cookie) => output.cookies.add(cookie.name));
|
||||
if (request.postData) {
|
||||
request.postData.params?.map((param: Param) =>
|
||||
output.postParams.add(param.name),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
headers: [...output.headers].sort((a, b) => a.localeCompare(b)),
|
||||
queryArgs: [...output.queryArgs].sort((a, b) => a.localeCompare(b)),
|
||||
cookies: [...output.cookies].sort((a, b) => a.localeCompare(b)),
|
||||
postParams: [...output.postParams].sort((a, b) => a.localeCompare(b)),
|
||||
mimeTypes: [...output.mimeTypes].sort((a, b) => a.localeCompare(b)),
|
||||
};
|
||||
}
|
||||
|
||||
function getScrubMimeTypes(
|
||||
options?: SanitizeOptions,
|
||||
possibleScrubItems?: PossibleScrubItems,
|
||||
) {
|
||||
if (options?.allMimeTypes && !!possibleScrubItems) {
|
||||
return possibleScrubItems.mimeTypes;
|
||||
}
|
||||
return options?.scrubMimetypes || defaultMimeTypesList;
|
||||
}
|
||||
|
||||
function getScrubWords(
|
||||
options?: SanitizeOptions,
|
||||
possibleScrubItems?: PossibleScrubItems,
|
||||
) {
|
||||
let scrubWords = options?.scrubWords || [];
|
||||
if (options?.allCookies && !!possibleScrubItems) {
|
||||
scrubWords = scrubWords.concat(possibleScrubItems.cookies);
|
||||
}
|
||||
if (options?.allHeaders && !!possibleScrubItems) {
|
||||
scrubWords = scrubWords.concat(possibleScrubItems.headers);
|
||||
}
|
||||
if (options?.allQueryArgs && !!possibleScrubItems) {
|
||||
scrubWords = scrubWords.concat(possibleScrubItems.queryArgs);
|
||||
}
|
||||
if (options?.allPostParams && !!possibleScrubItems) {
|
||||
scrubWords = scrubWords.concat(possibleScrubItems.postParams);
|
||||
}
|
||||
|
||||
return scrubWords || defaultScrubItems;
|
||||
}
|
||||
|
||||
interface SanitizeOptions {
|
||||
scrubWords?: string[]
|
||||
scrubMimetypes?: string[]
|
||||
allCookies?: boolean
|
||||
allHeaders?: boolean
|
||||
allQueryArgs?: boolean
|
||||
allMimeTypes?: boolean
|
||||
allPostParams?: boolean
|
||||
}
|
||||
|
||||
export function sanitize(input: string, options?: SanitizeOptions) {
|
||||
let possibleScrubItems: PossibleScrubItems | undefined;
|
||||
if (
|
||||
options?.allCookies
|
||||
|| options?.allHeaders
|
||||
|| options?.allMimeTypes
|
||||
|| options?.allQueryArgs
|
||||
|| options?.allPostParams
|
||||
) {
|
||||
// we have to parse the HAR to get the full list of things we could scrub
|
||||
possibleScrubItems = getHarInfo(input);
|
||||
}
|
||||
|
||||
// Remove specific mime responses first
|
||||
input = removeContentForMimeTypes(
|
||||
input,
|
||||
getScrubMimeTypes(options, possibleScrubItems),
|
||||
);
|
||||
|
||||
// trim the list of words we are looking for down to the ones actually in the HAR file
|
||||
const wordList = getScrubWords(options, possibleScrubItems).filter(val =>
|
||||
input.includes(val),
|
||||
);
|
||||
|
||||
// build list of regexes needed to actually scrub the file
|
||||
const wordSpecificScrubList = wordList.map(word => buildRegex(word));
|
||||
const allScrubList = defaultRegex.concat(wordSpecificScrubList);
|
||||
|
||||
for (const scrubList of allScrubList) {
|
||||
for (const scrub of scrubList) {
|
||||
input = input.replace(scrub.regex, scrub.replacement);
|
||||
}
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
export type HashMap = Record<string, string[]>;
|
||||
|
||||
export function toHashString(obj: HashMap): string {
|
||||
const params = new URLSearchParams();
|
||||
Object.entries(obj).forEach(([key, stringArr]) => {
|
||||
stringArr.forEach((value) => {
|
||||
params.append(key, value);
|
||||
});
|
||||
});
|
||||
return `#${params.toString()}`;
|
||||
}
|
||||
|
||||
export function getHashMap(hash: string): HashMap {
|
||||
const existingParams = new URLSearchParams(hash.replace('#', ''));
|
||||
return Object.fromEntries(
|
||||
[...existingParams.keys()].map(key => [key, existingParams.getAll(key)]),
|
||||
);
|
||||
}
|
||||
+10
-3
@@ -2,7 +2,6 @@ import { tool as base64FileConverter } from './base64-file-converter';
|
||||
import { tool as base64StringConverter } from './base64-string-converter';
|
||||
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||
import { tool as emailNormalizer } from './email-normalizer';
|
||||
import { tool as base64HexConverter } from './base64-hex-converter';
|
||||
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
@@ -13,6 +12,7 @@ import { tool as jsonToXml } from './json-to-xml';
|
||||
import { tool as regexTester } from './regex-tester';
|
||||
import { tool as regexMemo } from './regex-memo';
|
||||
import { tool as markdownToHtml } from './markdown-to-html';
|
||||
import { tool as harSanitizer } from './har-sanitizer';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
@@ -102,7 +102,6 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
romanNumeralConverter,
|
||||
base64StringConverter,
|
||||
base64FileConverter,
|
||||
base64HexConverter,
|
||||
colorConverter,
|
||||
caseConverter,
|
||||
textToNatoAlphabet,
|
||||
@@ -166,7 +165,15 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
},
|
||||
{
|
||||
name: 'Network',
|
||||
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
|
||||
components: [
|
||||
ipv4SubnetCalculator,
|
||||
ipv4AddressConverter,
|
||||
ipv4RangeExpander,
|
||||
macAddressLookup,
|
||||
macAddressGenerator,
|
||||
ipv6UlaGenerator,
|
||||
harSanitizer,
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Math',
|
||||
|
||||
Reference in new issue
Block a user