From c8a1b023d53faf9d4826752fba8ba9c59ccce39c Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Mon, 9 Dec 2024 13:25:06 +0100 Subject: [PATCH] Trim master password when someone uses strange XML formatting (#82) Fixes #80 --- .../internal/dispatchers/LegacyDispatcher.java | 6 +++++- src/test/legacy/legacy-settings-security-2.xml | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/components/secdispatcher/internal/dispatchers/LegacyDispatcher.java b/src/main/java/org/codehaus/plexus/components/secdispatcher/internal/dispatchers/LegacyDispatcher.java index 942ff22..dc51786 100644 --- a/src/main/java/org/codehaus/plexus/components/secdispatcher/internal/dispatchers/LegacyDispatcher.java +++ b/src/main/java/org/codehaus/plexus/components/secdispatcher/internal/dispatchers/LegacyDispatcher.java @@ -152,9 +152,13 @@ private String getMasterMasterPasswordFromSettingsSecurityXml() { } if (Files.exists(xml)) { try (InputStream is = Files.newInputStream(xml)) { - return (String) XPathFactory.newInstance() + String result = (String) XPathFactory.newInstance() .newXPath() .evaluate("//master", new InputSource(is), XPathConstants.STRING); + if (result != null) { + result = result.trim(); + } + return result; } catch (Exception e) { // just ignore whatever it is } diff --git a/src/test/legacy/legacy-settings-security-2.xml b/src/test/legacy/legacy-settings-security-2.xml index 0f7b33d..4b5539a 100644 --- a/src/test/legacy/legacy-settings-security-2.xml +++ b/src/test/legacy/legacy-settings-security-2.xml @@ -1,4 +1,6 @@ to the moon - {KDvsYOFLlXgH4LU8tvpzAGg5otiosZXvfdQq0yO86LU=} + + {KDvsYOFLlXgH4LU8tvpzAGg5otiosZXvfdQq0yO86LU=} +