fix(electron-utils): block trailing-dot internal hostnames (#396)

* fix(electron-utils): block trailing-dot internal hostnames

DNS treats localhost. as localhost; strip trailing dots before the hostname gate.

* fix(electron-utils): prettier format trailing-dot guard

---------

Co-authored-by: Aniruddha Adak <aniruddhaadak80@users.noreply.github.com>
This commit is contained in:
ANIRUDDHA ADAK
2026-09-15 15:47:53 +08:00
committed by GitHub
co-authored by Aniruddha Adak
parent f994dd9c8c
commit f9c65f67a9
2 changed files with 17 additions and 2 deletions
@@ -73,6 +73,15 @@ describe('isSafeRemoteUrl', () => {
await expect(isSafeRemoteUrl(url)).resolves.toBe(false)
})
it.each([
'http://localhost./x.png',
'http://LOCALHOST./x.png',
'http://printer.local./x.png',
'http://metadata.internal./x.png',
])('rejects trailing-dot internal hostname %s without DNS', async (url) => {
await expect(isSafeRemoteUrl(url)).resolves.toBe(false)
})
it('rejects malformed input and non-strings', async () => {
await expect(isSafeRemoteUrl('not a url')).resolves.toBe(false)
await expect(isSafeRemoteUrl(undefined)).resolves.toBe(false)