Skip to content

Commit b823f0f

Browse files
committed
Relax monitor URL validation for Docker and local hostnames (fixes #2605)
1 parent 066df2c commit b823f0f

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

client/src/Validation/validation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const monitorValidation = joi.object({
130130
.custom((value, helpers) => {
131131
const noProtocol = value.replace(/^(https?:\/\/)/, "");
132132

133-
if (/^[a-zA-Z0-9-]+(:\d{1,5})?$/.test(noProtocol)) {
133+
if (/^[a-zA-Z0-9.-]+(:\d{1,5})?$/.test(noProtocol)) {
134134
return value;
135135
}
136136

server/validation/joi.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,52 @@ const createMonitorBodyValidation = joi.object({
168168
name: joi.string().required(),
169169
description: joi.string().required(),
170170
type: joi.string().required(),
171-
url: joi.string().required(),
171+
url: joi
172+
.string()
173+
.required()
174+
.custom((value, helpers) => {
175+
const noProtocol = value.replace(/^(https?:\/\/)/, "");
176+
177+
if (/^[a-zA-Z0-9.-]+(:\d{1,5})?$/.test(noProtocol)) {
178+
return value;
179+
}
180+
181+
// Existing complex URL validation as fallback
182+
var urlRegex = new RegExp(
183+
"^" +
184+
"(?:(?:https?|ftp):\\/\\/)?" +
185+
"(?:" +
186+
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
187+
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
188+
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
189+
"|" +
190+
"(?:" +
191+
"(?:" +
192+
"[a-z0-9\\u00a1-\\uffff]" +
193+
"[a-z0-9\\u00a1-\\uffff_-]{0,62}" +
194+
")?" +
195+
"[a-z0-9\\u00a1-\\uffff]\\." +
196+
")+" +
197+
"(?:[a-z\\u00a1-\\uffff]{2,}\\.?)" +
198+
")" +
199+
"(?::\\d{2,5})?" +
200+
"(?:[/?#]\\S*)?" +
201+
"$",
202+
"i"
203+
);
204+
205+
if (urlRegex.test(value)) {
206+
return value;
207+
}
208+
209+
return helpers.error("string.invalidUrl");
210+
})
211+
.messages({
212+
"string.empty": "This field is required.",
213+
"string.uri": "The URL you provided is not valid.",
214+
"string.invalidUrl":
215+
"Please enter a valid URL, hostname, or container name (with optional port).",
216+
}),
172217
ignoreTlsErrors: joi.boolean().default(false),
173218
port: joi.number(),
174219
isActive: joi.boolean(),

0 commit comments

Comments
 (0)