-
-
Notifications
You must be signed in to change notification settings - Fork 599
feat: allow updating monitor URL and type via Configure #2752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 5 commits
46579cd
db754cb
38fe814
da4b5c9
81ec448
3776441
94d171c
4da2ebe
4fec374
6e3c8b8
d5e4fe0
ab177d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -367,20 +367,27 @@ const infrastructureMonitorValidation = joi.object({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .string() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .trim() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .custom((value, helpers) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const urlRegex = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /^(https?:\/\/)?(([0-9]{1,3}\.){3}[0-9]{1,3}|[\da-z\.-]+)(\.[a-z\.]{2,6})?(:(\d+))?([\/\w \.-]*)*\/?$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!urlRegex.test(value)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return helpers.error("string.invalidUrl"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!/^https?:\/\//i.test(value)) return helpers.error("string.uri"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const u = new URL(value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasPath = u.pathname && u.pathname !== "/"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasQuery = !!u.search; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasHash = !!u.hash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (hasPath || hasQuery || hasHash) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return helpers.error("string.invalidUrl"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const u = new URL(value); | |
| const hasPath = u.pathname && u.pathname !== "/"; | |
| const hasQuery = !!u.search; | |
| const hasHash = !!u.hash; | |
| if (hasPath || hasQuery || hasHash) { | |
| return helpers.error("string.invalidUrl"); | |
| } | |
| return value; | |
| } catch { | |
| const u = new URL(value); | |
| const hasPath = u.pathname !== "/"; | |
| const hasQuery = !!u.search; | |
| const hasHash = !!u.hash; | |
| const hasCreds = !!(u.username || u.password); | |
| if (hasCreds) { | |
| return helpers.error("string.invalidUrl"); | |
| } | |
| if (u.port) { | |
| const portNum = Number(u.port); | |
| if (!Number.isInteger(portNum) || portNum < 1 || portNum > 65535) { | |
| return helpers.error("string.invalidUrl"); | |
| } | |
| } | |
| if (hasPath || hasQuery || hasHash) { | |
| return helpers.error("string.invalidUrl"); | |
| } | |
| // Normalize to canonical form: scheme://host[:port] | |
| return `${u.protocol}//${u.host}`; | |
| } catch { |
🤖 Prompt for AI Agents
In client/src/Validation/validation.js around lines 372 to 380, the URL
validation does not block URLs containing user credentials or ports outside the
valid range 1–65535, which violates the requirement to allow only hostname and
optional port. Update the validation logic to check if the URL includes username
or password and reject it, and also verify that if a port is specified, it falls
within the valid range; if not, return the validation error "string.invalidUrl".
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Confirm client/server validation parity (paths, creds, ports)
Ensure server-side schemas match these client constraints to prevent UX mismatches (client rejects while server accepts, or vice versa).
🏁 Script executed:
#!/bin/bash
# Verify server-side URL constraints mirror client rules:
# - http/https only
# - no path/query/fragment
# - no credentials
# - port in 1..65535
# Locate joi validation files
fd -i -a 'joi.js'
# Inspect monitor body validations
rg -n -A5 -B5 'createMonitorBodyValidation|editMonitorBodyValidation'
# Inspect URL rules and custom validators
rg -n -A6 -B3 'url.*joi|Joi.*uri|Joi.*custom|credentials|username|password|pathname|search|hash|port'
# As a fallback, scan for any URI validations that might allow paths
rg -n -A3 -B3 'uri\('Length of output: 295827
Align server-side URL validation with client constraints
The server currently uses
.string()
.uri({ scheme: ["http", "https"] })which only enforces the protocol. It still allows paths, query strings, fragments, and credentials—unlike the client’s custom validator that forbids them. This will lead to confusing UX where the client rejects a URL the server accepts (or vice versa).
Please update the schema in server/src/validation/joi.js:
- createMonitorBodyValidation.url (around line 158)
- editMonitorBodyValidation.url (around line 188)
to mirror the client logic by disallowing:
• path (u.pathname !== "/")
• query (u.search)
• fragment (u.hash)
• credentials (u.username/u.password)
and still enforcing a valid port (1–65535).
You can use Joi’s URI options (e.g. allowQuery: false, allowFragments: false, allowCredentials: false) or plug in a custom validator akin to the client’s new URL(value) check.
Let’s keep Canada and the U.S. arguing over hockey, not URL formats! 😉
🤖 Prompt for AI Agents
In server/src/validation/joi.js around lines 158 and 188, update the
createMonitorBodyValidation.url and editMonitorBodyValidation.url schemas to
match the client-side URL validation by disallowing paths, queries, fragments,
and credentials. Use Joi's URI options such as allowQuery: false,
allowFragments: false, allowCredentials: false to enforce these restrictions,
and ensure the port is valid (1-65535). Alternatively, implement a custom
validator similar to the client’s new URL(value) check that verifies pathname is
"/", no search or hash exists, and username and password are empty.
Uh oh!
There was an error while loading. Please reload this page.