Skip to content

Commit

Permalink
Add the URL Defanger Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
bdalling committed Jan 22, 2025
1 parent 08d977b commit 4920849
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ declare module '@vue/runtime-core' {
UlidGenerator: typeof import('./src/tools/ulid-generator/ulid-generator.vue')['default']
UrlEncoder: typeof import('./src/tools/url-encoder/url-encoder.vue')['default']
UrlParser: typeof import('./src/tools/url-parser/url-parser.vue')['default']
UrlDefang: typeof import('./src/tools/url-defang/url-defang.vue')['default']
UserAgentParser: typeof import('./src/tools/user-agent-parser/user-agent-parser.vue')['default']
UserAgentResultCards: typeof import('./src/tools/user-agent-parser/user-agent-result-cards.vue')['default']
UuidGenerator: typeof import('./src/tools/uuid-generator/uuid-generator.vue')['default']
Expand Down
4 changes: 4 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ tools:
title: URL parser
description: Parse a URL into its separate constituent parts (protocol, origin, params, port, username-password, ...)

url-defang:
title: URL Defang
description: Defangs a given url to make a potentially malicous domain safe to share for security research or operations purposes.

iban-validator-and-parser:
title: IBAN validator and parser
description: Validate and parse IBAN numbers. Check if an IBAN is valid and get the country, BBAN, if it is a QR-IBAN and the IBAN friendly format.
Expand Down
2 changes: 2 additions & 0 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import { tool as tokenGenerator } from './token-generator';
import type { ToolCategory } from './tools.types';
import { tool as urlEncoder } from './url-encoder';
import { tool as urlParser } from './url-parser';
import { tool as urlDefang } from './url-defang';
import { tool as uuidGenerator } from './uuid-generator';
import { tool as macAddressLookup } from './mac-address-lookup';
import { tool as xmlFormatter } from './xml-formatter';
Expand Down Expand Up @@ -124,6 +125,7 @@ export const toolsByCategory: ToolCategory[] = [
urlEncoder,
htmlEntities,
urlParser,
urlDefang,
deviceInformation,
basicAuthGenerator,
metaTagGenerator,
Expand Down
12 changes: 12 additions & 0 deletions src/tools/url-defang/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Unlink } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate } from '@/plugins/i18n.plugin';

export const tool = defineTool({
name: translate('tools.url-defang.title'),
path: '/url-defang',
description: translate('tools.url-defang.description'),
keywords: ['url', 'defang'],
component: () => import('./url-defang.vue'),
icon: Unlink,
});
59 changes: 59 additions & 0 deletions src/tools/url-defang/url-defang.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<script setup lang="ts">
import InputCopyable from '../../components/InputCopyable.vue';
import { isNotThrowing } from '@/utils/boolean';

Check failure on line 3 in src/tools/url-defang/url-defang.vue

View workflow job for this annotation

GitHub Actions / ci

'isNotThrowing' is defined but never used
import { withDefaultOnError } from '@/utils/defaults';
const urlToParse = ref('https://me:[email protected]:3000/url-parser?key1=value&key2=value2#the-hash');
const urlParsed = computed(() => withDefaultOnError(() => defangUrl(urlToParse.value), undefined));

Check failure on line 8 in src/tools/url-defang/url-defang.vue

View workflow job for this annotation

GitHub Actions / ci

'defangUrl' was used before it was defined
const defangUrl = (url) => {

Check failure on line 10 in src/tools/url-defang/url-defang.vue

View workflow job for this annotation

GitHub Actions / ci

Top-level functions should be declared with function keyword
let urlString = url.toString();
// Remove credentials (username:password)
const credentialsPattern = /\/\/([^@]+@)/;
urlString = urlString.replace(credentialsPattern, '://');
// Replace protocol separator to prevent execution (http:// or https:// -> http[:]//)
urlString = urlString.replace('://', '[:]//');
// Replace the dot before TLD with [.] (e.g., domain.tld -> domain[.]tld)
const domainPattern = /(\.[a-zA-Z]{2,})(?=\b)/g;
urlString = urlString.replace(domainPattern, '[.]$1').replace('.].', '.]');
return urlString;
};

Check failure on line 25 in src/tools/url-defang/url-defang.vue

View workflow job for this annotation

GitHub Actions / ci

Expected 1 line break before '</script>', but 2 line breaks found
</script>

<template>
<c-card>
<c-input-text
v-model:value="urlToParse"
label="URL to Defang:"
placeholder="Your url to defang..."
raw-text
/>

<n-divider />

<InputCopyable
label="Defanged URL"
:value="(urlParsed as string) ?? ''"
readonly
label-position="left"
label-width="110px"
mb-2
placeholder=" "
/>
</c-card>
</template>

<style lang="less" scoped>
.n-input-group-label {
text-align: right;
}
.n-input-group {
margin: 2px 0;
}
</style>

0 comments on commit 4920849

Please sign in to comment.