Skip to content

Conversation

stephenchengCloud
Copy link
Collaborator

Add user name and detailed reason in http response when console connection limits are exceeded.

Add user name and detailed reason in http response when console
connection limits are exceeded.

Signed-off-by: Stephen Cheng <[email protected]>
@stephenchengCloud
Copy link
Collaborator Author

Tested with XenCenter.
It looks like XenCenter only read the http header, and doesn't read the http body. So I tested with sending "vnc console limit exceeded" message in header.

I captured the message from XenCenter, and the message was sent correctly.
image


let response_forbidden_with_body ?req s body =
let version = Option.map get_return_version req in
response_error_html ?version s "403" "Forbidden" [] body
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want 403, not 503 as before?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a client issue, not a server issue, so a 4xx response is warranted, maybe a 429 (too many requests) would be a better fit here?

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/429

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we expect more specific error responses - does it make sense to factor this into a function that takes the error code and message as arguments?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is more like a service side issue. It's server that is applying the restriction.
How about 503 + a specific error message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both 429 and 503 are reasonable to me.
Yeah, it's more of a serser side issue, because the server actively reject the connection.
I'll change this to 503.

Copy link
Collaborator Author

@stephenchengCloud stephenchengCloud Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we expect more specific error responses - does it make sense to factor this into a function that takes the error code and message as arguments?

Yeah, the specific error responses are contained in the body. See https://github.com/xapi-project/xen-api/pull/6710/files#diff-b467704b510207bfdab55411ab1ff91aae3f19c3e0ab0409f142fd1646595a3cR236
But yes, we can make this fucion more generic taking error code and messages as arguments. Will modify it.

let user = Db.Session.get_auth_user_name ~__context ~self:session_id in
let body =
Printf.sprintf
"<html><body><h1>Connection Limit Exceeded</h1><p>User '%s': Only 1 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this useful? The caller would know itself right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could create invalid HTML if user has characters with special meaning in HTML that would require escaping.

!https://miro.medium.com/v2/resize:fit:720/format:webp/1*P4nj9fJjSeJ9-c0rwSZqlg.png

Copy link
Collaborator Author

@stephenchengCloud stephenchengCloud Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this useful? The caller would know itself right?

Indeed it's meaningless. Instead, we can send in the response the user name who is using the connection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that may be a security issue...


let response_forbidden_with_body ?req s body =
let version = Option.map get_return_version req in
response_error_html ?version s "403" "Forbidden" [] body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we expect more specific error responses - does it make sense to factor this into a function that takes the error code and message as arguments?

let user = Db.Session.get_auth_user_name ~__context ~self:session_id in
let body =
Printf.sprintf
"<html><body><h1>Connection Limit Exceeded</h1><p>User '%s': Only 1 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could create invalid HTML if user has characters with special meaning in HTML that would require escaping.

!https://miro.medium.com/v2/resize:fit:720/format:webp/1*P4nj9fJjSeJ9-c0rwSZqlg.png

fix
Signed-off-by: Stephen Cheng <[email protected]>
@stephenchengCloud
Copy link
Collaborator Author

stephenchengCloud commented Oct 16, 2025

Fixed the comments above and tested.
The main changes are:

  1. To contain the active users in the response message, changed the active_connections to record the existing users and use the unique session id to identify them in case multiple connections have the same user name.
  2. Made response_custom_error a generic functon taking error code and messages as inputs
  3. Added escape_char to escape html special characters.

Tested:
(XenCenter doesn't read the http body, so only see the header in the result)
image

@robhoes
Copy link
Member

robhoes commented Oct 16, 2025

To contain the active users in the response message, changed the active_connections to record the existing users and use the unique session id to identify them in case multiple connections have the same user name.

If we do this, we need to consider whether the console user has the right permissions to get data about other users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants