harden(protocol): bound + charset-constrain the handshake session_id#547
Merged
Conversation
The WebSocket handshake accepted an unbounded, arbitrary session_id from the
peer, then used it as a registry key, logged it, and hashed it into telemetry.
The plugin only ever produces "<slug>@<4hex>" (slug is [a-z0-9-]), so a
pattern of ^[A-Za-z0-9._@-]{1,128}$ rejects only malformed or non-plugin
clients while accepting every real id. A bad id now fails the handshake at the
Pydantic boundary instead of populating the registry.
Addresses review finding ST-4 (#527).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements the “ST-4” hardening from #527 by validating the WebSocket handshake session_id at the Pydantic model boundary, preventing unbounded/arbitrary peer-provided IDs from flowing into the session registry, logs, and telemetry.
Changes:
- Constrain
HandshakeMessage.session_idto^[A-Za-z0-9._@-]{1,128}$via PydanticField(pattern=...). - Add unit tests asserting canonical plugin-style IDs are accepted and malformed/oversized/non-ASCII IDs are rejected.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/godot_ai/protocol/envelope.py |
Adds bounded/charset validation for handshake session_id in the protocol envelope model. |
tests/unit/test_protocol.py |
Adds targeted validation tests covering accepted and rejected session_id inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wave 2 hardening — review finding ST-4 (#527).
The WebSocket handshake accepted an unbounded, arbitrary
session_idfrom the peer, then used it as a registry key, logged it, and hashed it into telemetry. The plugin only ever produces<slug>@<4hex>(slug is[a-z0-9-], seeconnection.gd::_make_session_id), so a^[A-Za-z0-9._@-]{1,128}$pattern rejects only malformed/non-plugin clients while accepting every legitimate id. A bad id now fails at the Pydantic boundary instead of populating the registry.Test
tests/unit/test_protocol.py: canonicalslug@hexaccepted; empty / whitespace / path-separator / over-128 / non-ASCII rejected.Closes #527.
🤖 Generated with Claude Code