Skip to content

Commit

Permalink
don't trust upnp on who's the internet gateway #685
Browse files Browse the repository at this point in the history
  • Loading branch information
rejetto committed Jul 20, 2024
1 parent c24f642 commit 05c5cf0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/nat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ export const getPublicIps = debounceAsync(async () => {
}, { retain: 10 * MINUTE })

export const getNatInfo = debounceAsync(async () => {
const gatewayIpPromise = findGateway().catch(() => undefined)
const res = await haveTimeout(10_000, upnpClient.getGateway()).catch(() => null)
const status = await getServerStatus()
const mappings = res && await haveTimeout(5_000, upnpClient.getMappings()).catch(() => null)
console.debug('mappings found', mappings?.map(x => x.description))
const gatewayIp = res && try_(() => new URL(res.gateway.description).hostname, () => console.debug('unexpected upnp gw', res.gateway?.description))
|| await findGateway().catch(() => undefined)
const localIps = await getIps(false)
const gatewayIp = await gatewayIpPromise
const localIp = res?.address || gatewayIp ? _.maxBy(localIps, x => inCommon(x, gatewayIp!)) : localIps[0]
const internalPort = status?.https?.listening && status.https.port || status?.http?.listening && status.http.port || undefined
const mapped = _.find(mappings, x => x.private.host === localIp && x.private.port === internalPort)
Expand Down

0 comments on commit 05c5cf0

Please sign in to comment.