diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-11-20 11:52:26 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-11-23 10:08:54 +0100 |
| commit | 49354a7bacea4741e33155a05e2dd9808a6899e6 (patch) | |
| tree | cd5fefae231f5eca79d9909645002ebec9cc174f /gui/src | |
| parent | 9a2fa96aa3d40c809d63a779243923ba88b3512a (diff) | |
| download | mullvadvpn-49354a7bacea4741e33155a05e2dd9808a6899e6.tar.xz mullvadvpn-49354a7bacea4741e33155a05e2dd9808a6899e6.zip | |
Prevent duplicate custom DNS addresses
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/renderer/components/CustomDnsSettings.tsx | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/gui/src/renderer/components/CustomDnsSettings.tsx b/gui/src/renderer/components/CustomDnsSettings.tsx index 9db4637d44..a6f409ea5c 100644 --- a/gui/src/renderer/components/CustomDnsSettings.tsx +++ b/gui/src/renderer/components/CustomDnsSettings.tsx @@ -94,31 +94,35 @@ export default function CustomDnsSettings() { const onAdd = useCallback( async (address: string) => { - const add = async () => { - await setDnsOptions({ - ...dns, - state: dns.state === 'custom' || inputVisible ? 'custom' : 'default', - customOptions: { - addresses: [...dns.customOptions.addresses, address], - }, - }); + if (dns.customOptions.addresses.includes(address)) { + setInvalid(); + } else { + const add = async () => { + await setDnsOptions({ + ...dns, + state: dns.state === 'custom' || inputVisible ? 'custom' : 'default', + customOptions: { + addresses: [...dns.customOptions.addresses, address], + }, + }); - hideInput(); - }; + hideInput(); + }; - try { - const ipAddress = IpAddress.fromString(address); - if (ipAddress.isLocal()) { - await add(); - } else { - willShowConfirmationDialog.current = true; - setConfirmAction(() => async () => { - willShowConfirmationDialog.current = false; + try { + const ipAddress = IpAddress.fromString(address); + if (ipAddress.isLocal()) { await add(); - }); + } else { + willShowConfirmationDialog.current = true; + setConfirmAction(() => async () => { + willShowConfirmationDialog.current = false; + await add(); + }); + } + } catch { + setInvalid(); } - } catch { - setInvalid(); } }, [inputVisible, dns, setDnsOptions], @@ -126,6 +130,10 @@ export default function CustomDnsSettings() { const onEdit = useCallback( (oldAddress: string, newAddress: string) => { + if (oldAddress !== newAddress && dns.customOptions.addresses.includes(newAddress)) { + throw new Error('Duplicate address'); + } + const edit = async () => { const addresses = dns.customOptions.addresses.map((address) => oldAddress === address ? newAddress : address, |
