feat: parse barracuda link protection
https://campus.barracuda.com/product/emailgatewaydefense/doc/96023012/understanding-link-protection/
This commit is contained in:
parent
d5aa5bcf79
commit
80bdbb7e93
|
@ -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\./, '')
|
||||
|
||||
|
|
Loading…
Reference in New Issue