From 722bd18999ae73b9b76fb03a20fff4cb0a8f4619 Mon Sep 17 00:00:00 2001 From: Vojta Drbohlav Date: Mon, 11 Oct 2021 21:50:53 +0200 Subject: [PATCH] normalize config file name for download to make it work on Windows Windows client name is derived from config file name when importing to WireGuard and it only accepts names satisfying /^[a-zA-Z0-9_=+.-]{1,32}$/. For more information look at https://github.com/WireGuard/wireguard-windows/blob/af60ab229954519b8295bb3ef453231f4d3b9087/conf/name.go#L24. --- src/lib/Server.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/Server.js b/src/lib/Server.js index cf6b26e..e204fa5 100644 --- a/src/lib/Server.js +++ b/src/lib/Server.js @@ -99,7 +99,8 @@ module.exports = class Server { const { clientId } = req.params; const client = await WireGuard.getClient({ clientId }); const config = await WireGuard.getClientConfiguration({ clientId }); - res.header('Content-Disposition', `attachment; filename="${client.name}.conf"`); + const configName = client.name.replace(/[^a-zA-Z0-9_=+.-]/g, '-').replace(/(-{2,}|-$)/g, '-').replace(/-$/, '').substring(0, 32); + res.header('Content-Disposition', `attachment; filename="${configName}.conf"`); res.header('Content-Type', 'text/plain'); res.send(config); }))