Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URL Defanger Tool #1464

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading