Skip to content

Conversation

@dmgav
Copy link
Contributor

@dmgav dmgav commented Dec 9, 2025

Implementation of websocket security. The clients must authenticate with the server when connecting to the websocket. If authentication fails, then the connection is immediately closed. Clients can authenticate with the server using tokens and API keys. The authentication scheme is identical to the scheme used for other API endpoints.

The websockets implemented in #74 are not secured. The security is added in this PR.

Summary of Changes for Release Notes

Added

  • Security for websockets.

How Has This Been Tested?

Unit tests were added.

@dmgav dmgav changed the title ENH: security for websockets Security for WebSockets Dec 9, 2025
auth_header = websocket.headers.get("Authorization", "")
access_token, api_key = None, None
if auth_header.startswith("Bearer "):
access_token = auth_header[len("Bearer") :].strip()
Copy link
Member

Choose a reason for hiding this comment

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

For what it's worth, we chose not to support these in Tiled because there is no mechanism for the server to request that they be refreshed, since it cannot send HTTP response codes.

Instead, the client mints a short-lived API key and revokes it after the connection is formed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sense. It should be possible to implement a refresh scheme when a token is validated by sending a plain HTTP request in case connection to a websocket fails and then refreshed if requested by the server, but it does not look like a standard approach.

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.

2 participants