fix(notifications): encode SMTP credentials in Shoutrrr URLs (#831)

Closes #829
This commit is contained in:
Nico
2026-04-25 09:24:05 +02:00
committed by GitHub
parent 3adc722cca
commit f078e006c1
2 changed files with 18 additions and 3 deletions

View File

@@ -39,6 +39,21 @@ describe("notification shoutrrr URL builders", () => {
).toBe(
"smtp://user%20name:p%40ss%20word@smtp.example.com:465/?from=alerts%2Bteam%40example.com&fromname=Ops+Team&to=ops%40example.com&starttls=no",
);
expect(
buildEmailShoutrrrUrl({
type: "email",
smtpHost: "smtp.example.com",
smtpPort: 465,
username: "user%name+tag",
password: "pa%ss+word",
from: "alerts@example.com",
to: ["ops@example.com"],
useTLS: false,
}),
).toBe(
"smtp://user%25name%2Btag:pa%25ss%2Bword@smtp.example.com:465/?from=alerts%40example.com&to=ops%40example.com&starttls=no",
);
});
test("builds discord URLs and rejects invalid webhook formats", () => {

View File

@@ -7,9 +7,9 @@ export const buildEmailShoutrrrUrl = (config: Extract<NotificationConfig, { type
shoutrrrUrl.port = String(config.smtpPort);
shoutrrrUrl.pathname = "/";
let auth = "";
if (config.username && config.password) {
shoutrrrUrl.username = config.username;
shoutrrrUrl.password = config.password;
auth = `${encodeURIComponent(config.username)}:${encodeURIComponent(config.password)}@`;
}
shoutrrrUrl.searchParams.set("from", config.from);
@@ -19,5 +19,5 @@ export const buildEmailShoutrrrUrl = (config: Extract<NotificationConfig, { type
shoutrrrUrl.searchParams.set("to", config.to.join(","));
shoutrrrUrl.searchParams.set("starttls", config.useTLS ? "yes" : "no");
return shoutrrrUrl.toString();
return shoutrrrUrl.toString().replace("smtp://", `smtp://${auth}`);
};