MDLeom 2025-04-04 08:40:25 +00:00
parent d5aa5bcf79
commit 80bdbb7e93
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
1 changed files with 33 additions and 10 deletions

View File

@ -15,6 +15,38 @@ const caretPath = (pathname) => {
return `${path}?${search}`
}
const safeLinks = [
'safelinks\\.protection\\.outlook\\.com',
'\\.protection\\.sophos\\.com',
'linkprotect\\.cudasvc\\.com'
]
const deSafelink = (urlStr) => {
let url = new URL(urlStr)
// O365 Safelinks
if (url.hostname.endsWith('safelinks.protection.outlook.com')) {
url = new URL(url.searchParams.get('url'))
}
// #92
if (url.hostname.endsWith('.protection.sophos.com')) {
url = new URL(`http://${url.searchParams.get('d')}`)
}
// Barracuda
if (url.hostname.endsWith('linkprotect.cudasvc.com')) {
url = new URL(url.searchParams.get('a'))
}
// "Just have to go deep enough."
if (url.hostname.match(new RegExp(safeLinks.join('|')))) {
return deSafelink(url.href)
}
return url.href
}
for await (const line of createInterface({ input: process.stdin, terminal: false })) {
// parse hostname from url
if (process.argv[2] === 'hostname') {
@ -37,16 +69,7 @@ for await (const line of createInterface({ input: process.stdin, terminal: false
}
} else {
if (URL.canParse(line)) {
let url = new URL(line)
// O365 Safelinks
if (url.hostname.endsWith('safelinks.protection.outlook.com')) {
url = new URL(url.searchParams.get('url'))
}
// #92
if (url.hostname.endsWith('.protection.sophos.com')) {
url = new URL(`http://${url.searchParams.get('d')}`)
}
const url = new URL(deSafelink(line))
url.host = url.host.replace(/^www\./, '')